]> git.ipfire.org Git - location/libloc.git/commitdiff
lua: Add version() function
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 11:21:01 +0000 (11:21 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 11:21:01 +0000 (11:21 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/lua/location.c
tests/lua/main.lua

index 2b23f926b5aabf209ea0eea5cd7aa6c4c6a5c0ec..e8441a489a7f0648c0c4eca564cce9a2228d1f86 100644 (file)
 */
 
 #include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
 
 #include "location.h"
 
+static int version(lua_State* L) {
+       lua_pushstring(L, PACKAGE_VERSION);
+       return 1;
+}
+
+static const struct luaL_Reg location_functions[] = {
+       { "version", version },
+       { NULL, NULL },
+};
+
 int luaopen_location(lua_State* L) {
-       return 0;
+       luaL_newlib(L, location_functions);
+
+       return 1;
 }
index d09e2175c7c8aefb5d341ac4a337ccf01b5be476..901dd42b7a8b0da94a33786a1627254de7fea088 100755 (executable)
@@ -22,6 +22,9 @@ luaunit = require("luaunit")
 function test_load()
        -- Try loading the module
        location = require("location")
+
+       -- Print the version
+       print(location.version())
 end
 
 os.exit(luaunit.LuaUnit.run())