summaryrefslogtreecommitdiff
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/CMakeLists.txt6
-rw-r--r--src/lua/bridge.cpp2
-rw-r--r--src/lua/include/lua_version.hpp15
-rw-r--r--src/lua/lua_version.cpp51
4 files changed, 72 insertions, 2 deletions
diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt
index 5c67a57e..7174757a 100644
--- a/src/lua/CMakeLists.txt
+++ b/src/lua/CMakeLists.txt
@@ -3,8 +3,10 @@
# SPDX-License-Identifier: GPL-3.0-only
idf_component_register(
- SRCS "lua_thread.cpp" "bridge.cpp" "property.cpp" "lua_database.cpp" "lua_queue.cpp"
+ SRCS "lua_thread.cpp" "bridge.cpp" "property.cpp" "lua_database.cpp"
+ "lua_queue.cpp" "lua_version.cpp"
INCLUDE_DIRS "include"
REQUIRES "drivers" "lvgl" "tinyfsm" "events" "system_fsm" "database"
- "esp_timer" "battery" "esp-idf-lua" "luavgl" "lua-linenoise" "lua-term")
+ "esp_timer" "battery" "esp-idf-lua" "luavgl" "lua-linenoise" "lua-term"
+ "esp_app_format")
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
diff --git a/src/lua/bridge.cpp b/src/lua/bridge.cpp
index 1063cfbf..e7344e0e 100644
--- a/src/lua/bridge.cpp
+++ b/src/lua/bridge.cpp
@@ -18,6 +18,7 @@
#include "lua.hpp"
#include "lua_database.hpp"
#include "lua_queue.hpp"
+#include "lua_version.hpp"
#include "lvgl.h"
#include "event_queue.hpp"
@@ -74,6 +75,7 @@ Bridge::Bridge(system_fsm::ServiceLocator& services, lua_State& s)
RegisterDatabaseModule(&s);
RegisterQueueModule(&s);
+ RegisterVersionModule(&s);
}
static auto new_property_module(lua_State* state) -> int {
diff --git a/src/lua/include/lua_version.hpp b/src/lua/include/lua_version.hpp
new file mode 100644
index 00000000..4ba4be94
--- /dev/null
+++ b/src/lua/include/lua_version.hpp
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include "lua.hpp"
+
+namespace lua {
+
+auto RegisterVersionModule(lua_State*) -> void;
+
+} // namespace lua
diff --git a/src/lua/lua_version.cpp b/src/lua/lua_version.cpp
new file mode 100644
index 00000000..ac72d3ae
--- /dev/null
+++ b/src/lua/lua_version.cpp
@@ -0,0 +1,51 @@
+
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#include "lua_version.hpp"
+
+#include <string>
+
+#include "bridge.hpp"
+#include "lua.hpp"
+
+#include "esp_app_desc.h"
+#include "esp_log.h"
+#include "lauxlib.h"
+#include "lua.h"
+#include "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 const struct luaL_Reg kVersionFuncs[] = {{"esp", esp},
+ {"samd", 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