diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-01-15 12:31:20 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-01-15 12:31:20 +1100 |
| commit | 7cdcd44e0ca10ebdc796638190ed1d9b45d99ef0 (patch) | |
| tree | 637b43848d17c9dbdc1688cb4733eb235f223e37 /src/lua | |
| parent | 0e04eb918ec976017276306181282769d8896c83 (diff) | |
| download | tangara-fw-7cdcd44e0ca10ebdc796638190ed1d9b45d99ef0.tar.gz | |
Begin migration of remaining screens to Lua
Diffstat (limited to 'src/lua')
| -rw-r--r-- | src/lua/bridge.cpp | 25 | ||||
| -rw-r--r-- | src/lua/include/bridge.hpp | 2 | ||||
| -rw-r--r-- | src/lua/lua_database.cpp | 34 | ||||
| -rw-r--r-- | src/lua/lua_version.cpp | 9 |
4 files changed, 45 insertions, 25 deletions
diff --git a/src/lua/bridge.cpp b/src/lua/bridge.cpp index e7344e0e..82721d4e 100644 --- a/src/lua/bridge.cpp +++ b/src/lua/bridge.cpp @@ -37,21 +37,6 @@ namespace lua { static constexpr char kBridgeKey[] = "bridge"; -static auto open_settings_fn(lua_State* state) -> int { - events::Ui().Dispatch(ui::internal::ShowSettingsPage{ - .page = ui::internal::ShowSettingsPage::Page::kRoot}); - return 0; -} - -static const struct luaL_Reg kLegacyUiFuncs[] = { - {"open_settings", open_settings_fn}, - {NULL, NULL}}; - -static auto lua_legacy_ui(lua_State* state) -> int { - luaL_newlib(state, kLegacyUiFuncs); - return 1; -} - auto Bridge::Get(lua_State* state) -> Bridge* { lua_pushstring(state, kBridgeKey); lua_gettable(state, LUA_REGISTRYINDEX); @@ -64,9 +49,6 @@ Bridge::Bridge(system_fsm::ServiceLocator& services, lua_State& s) lua_pushlightuserdata(&s, this); lua_settable(&s, LUA_REGISTRYINDEX); - luaL_requiref(&s, "legacy_ui", lua_legacy_ui, true); - lua_pop(&s, 1); - luaL_requiref(&s, "linenoise", luaopen_linenoise, true); lua_pop(&s, 1); @@ -94,8 +76,7 @@ inline constexpr bool always_false_v = false; auto Bridge::AddPropertyModule( const std::string& name, - std::vector<std::pair<std::string, - std::variant<LuaFunction, std::shared_ptr<Property>>>> + std::vector<std::pair<std::string, std::variant<LuaFunction, Property*>>> props) -> void { // Create the module (or retrieve it if one with this name already exists) luaL_requiref(&state_, name.c_str(), new_property_module, true); @@ -107,8 +88,8 @@ auto Bridge::AddPropertyModule( using T = std::decay_t<decltype(arg)>; if constexpr (std::is_same_v<T, LuaFunction>) { bindings_.Register(&state_, arg); - } else if constexpr (std::is_same_v<T, std::shared_ptr<Property>>) { - bindings_.Register(&state_, arg.get()); + } else if constexpr (std::is_same_v<T, Property*>) { + bindings_.Register(&state_, arg); } else { static_assert(always_false_v<T>, "missing case"); } diff --git a/src/lua/include/bridge.hpp b/src/lua/include/bridge.hpp index 91153d67..62fbc340 100644 --- a/src/lua/include/bridge.hpp +++ b/src/lua/include/bridge.hpp @@ -26,7 +26,7 @@ class Bridge { const std::string&, std::vector< std::pair<std::string, - std::variant<LuaFunction, std::shared_ptr<Property>>>>) + std::variant<LuaFunction, Property*>>>) -> void; system_fsm::ServiceLocator& services() { return services_; } diff --git a/src/lua/lua_database.cpp b/src/lua/lua_database.cpp index 82b22343..ac7d711b 100644 --- a/src/lua/lua_database.cpp +++ b/src/lua/lua_database.cpp @@ -73,8 +73,38 @@ static auto indexes(lua_State* state) -> int { return 1; } -static const struct luaL_Reg kDatabaseFuncs[] = {{"indexes", indexes}, - {NULL, NULL}}; +static auto version(lua_State* L) -> int { + Bridge* instance = Bridge::Get(L); + auto db = instance->services().database().lock(); + if (!db) { + return 0; + } + auto res = db->schemaVersion(); + lua_pushlstring(L, res.data(), res.size()); + return 1; +} + +static auto size(lua_State* L) -> int { + Bridge* instance = Bridge::Get(L); + auto db = instance->services().database().lock(); + if (!db) { + return 0; + } + lua_pushinteger(L, db->sizeOnDiskBytes()); + return 1; +} + +static auto recreate(lua_State* L) -> int { + return 0; +} + +static auto update(lua_State* L) -> int { + return 0; +} + +static const struct luaL_Reg kDatabaseFuncs[] = { + {"indexes", indexes}, {"version", version}, {"size", size}, + {"recreate", recreate}, {"update", update}, {NULL, NULL}}; /* * Struct to be used as userdata for the Lua representation of database records. diff --git a/src/lua/lua_version.cpp b/src/lua/lua_version.cpp index ac72d3ae..c1098a1b 100644 --- a/src/lua/lua_version.cpp +++ b/src/lua/lua_version.cpp @@ -34,8 +34,17 @@ static auto samd(lua_State* L) -> int { return 1; } +static auto collator(lua_State* L) -> int { + Bridge* instance = Bridge::Get(L); + auto& collator = instance->services().collator(); + auto version = collator.Describe().value_or("None"); + lua_pushlstring(L, version.data(), version.size()); + return 1; +} + static const struct luaL_Reg kVersionFuncs[] = {{"esp", esp}, {"samd", samd}, + {"collator", collator}, {NULL, NULL}}; static auto lua_version(lua_State* L) -> int { |
