diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-11-21 13:49:47 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-11-21 13:49:47 +1100 |
| commit | d70ec9bf447f7a46e347c3bc5ad58fd88aff46a2 (patch) | |
| tree | ab75c1663934d7408fad36d134a0cfd4f4cb089b /src/lua/bridge.cpp | |
| parent | f34b6405884c4073158c3f36158c6351fa135a0f (diff) | |
| download | tangara-fw-d70ec9bf447f7a46e347c3bc5ad58fd88aff46a2.tar.gz | |
Add lua functions to get database content
Diffstat (limited to 'src/lua/bridge.cpp')
| -rw-r--r-- | src/lua/bridge.cpp | 37 |
1 files changed, 9 insertions, 28 deletions
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 <sys/_stdint.h> #include <memory> #include <string> +#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 { |
