diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-05-03 04:48:17 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-05-03 04:48:17 +0000 |
| commit | 3ceb8025ee4330c177101ed30ec17dfb0002f41e (patch) | |
| tree | 58350210f15df7d00d967cac6f30eeceeb031a3c /src/tangara/lua/lua_version.cpp | |
| parent | 964da15a0b84f8e5f00e8abac2f7dfda0bf60488 (diff) | |
| parent | 9fafd797a5504f458b5fcae4a1d28a68da936315 (diff) | |
| download | tangara-fw-3ceb8025ee4330c177101ed30ec17dfb0002f41e.tar.gz | |
Merge pull request 'Break dependency cycles with our components by merging co-dependent components together' (#68) from jqln/component-merge into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/68
Diffstat (limited to 'src/tangara/lua/lua_version.cpp')
| -rw-r--r-- | src/tangara/lua/lua_version.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/tangara/lua/lua_version.cpp b/src/tangara/lua/lua_version.cpp new file mode 100644 index 00000000..b85a30a5 --- /dev/null +++ b/src/tangara/lua/lua_version.cpp @@ -0,0 +1,68 @@ + +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "lua/lua_version.hpp" + +#include <string> + +#include "lua.hpp" +#include "lua/bridge.hpp" + +#include "esp_app_desc.h" +#include "esp_log.h" +#include "lauxlib.h" +#include "lua.h" +#include "lua/lua_thread.hpp" + +namespace lua { + +static auto esp(lua_State* L) -> int { + auto desc = esp_app_get_description(); + lua_pushstring(L, desc->version); + return 1; +} + +static auto samd(lua_State* L) -> int { + Bridge* instance = Bridge::Get(L); + auto& samd = instance->services().samd(); + auto version = samd.Version(); + lua_pushlstring(L, version.data(), version.size()); + return 1; +} + +static auto update_samd(lua_State* L) -> int { + Bridge* instance = Bridge::Get(L); + auto& samd = instance->services().samd(); + samd.ResetToFlashSamd(); + return 0; +} + +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}, + {"update_samd", update_samd}, + {NULL, NULL}}; + +static auto lua_version(lua_State* L) -> int { + luaL_newlib(L, kVersionFuncs); + return 1; +} + +auto RegisterVersionModule(lua_State* L) -> void { + luaL_requiref(L, "version", lua_version, true); + lua_pop(L, 1); +} + +} // namespace lua |
