From: Michael Tremer Date: Thu, 22 Feb 2024 11:21:01 +0000 (+0000) Subject: lua: Add version() function X-Git-Tag: 0.9.18~167 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03b9c3a42c3b155100b8b9b870cb9d83ef8839f8;p=location%2Flibloc.git lua: Add version() function Signed-off-by: Michael Tremer --- diff --git a/src/lua/location.c b/src/lua/location.c index 2b23f92..e8441a4 100644 --- a/src/lua/location.c +++ b/src/lua/location.c @@ -15,9 +15,23 @@ */ #include +#include +#include #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; } diff --git a/tests/lua/main.lua b/tests/lua/main.lua index d09e217..901dd42 100755 --- a/tests/lua/main.lua +++ b/tests/lua/main.lua @@ -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())