From d70ec9bf447f7a46e347c3bc5ad58fd88aff46a2 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 21 Nov 2023 13:49:47 +1100 Subject: Add lua functions to get database content --- src/lua/bridge.cpp | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'src/lua/bridge.cpp') diff --git a/src/lua/bridge.cpp b/src/lua/bridge.cpp index a45f2b27..070dee98 100644 --- a/src/lua/bridge.cpp +++ b/src/lua/bridge.cpp @@ -5,13 +5,19 @@ */ #include "bridge.hpp" +#include #include #include +#include "database.hpp" #include "esp_log.h" +#include "index.hpp" #include "lauxlib.h" +#include "lua.h" #include "lua.hpp" +#include "lua_database.hpp" +#include "lua_queue.hpp" #include "lvgl.h" #include "event_queue.hpp" @@ -22,6 +28,7 @@ namespace lua { [[maybe_unused]] static constexpr char kTag[] = "lua_bridge"; + static constexpr char kBridgeKey[] = "bridge"; static auto open_settings_fn(lua_State* state) -> int { @@ -54,32 +61,6 @@ static auto lua_legacy_ui(lua_State* state) -> int { return 1; } -static auto get_indexes(lua_State* state) -> int { - Bridge* instance = Bridge::Get(state); - - lua_newtable(state); - - auto db = instance->services().database().lock(); - if (!db) { - return 1; - } - - for (const auto& i : db->GetIndexes()) { - lua_pushstring(state, i.name.c_str()); - lua_rawseti(state, -2, i.id); - } - - return 1; -} - -static const struct luaL_Reg kDatabaseFuncs[] = {{"get_indexes", get_indexes}, - {NULL, NULL}}; - -static auto lua_database(lua_State* state) -> int { - luaL_newlib(state, kDatabaseFuncs); - return 1; -} - auto Bridge::Get(lua_State* state) -> Bridge* { lua_pushstring(state, kBridgeKey); lua_gettable(state, LUA_REGISTRYINDEX); @@ -95,8 +76,8 @@ Bridge::Bridge(system_fsm::ServiceLocator& services, lua_State& s) luaL_requiref(&s, "legacy_ui", lua_legacy_ui, true); lua_pop(&s, 1); - luaL_requiref(&s, "database", lua_database, true); - lua_pop(&s, 1); + RegisterDatabaseModule(&s); + RegisterQueueModule(&s); } static auto new_property_module(lua_State* state) -> int { -- cgit v1.2.3