]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
lua: Initialize location context
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 11:27:16 +0000 (11:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 11:28:02 +0000 (11:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/lua/location.c
src/lua/location.h

index e8441a489a7f0648c0c4eca564cce9a2228d1f86..a61a9aedd1e7fb70316d2bfe5d8c9778c7040cfd 100644 (file)
        Lesser General Public License for more details.
 */
 
+#include <errno.h>
+#include <string.h>
+
 #include <lua.h>
 #include <lauxlib.h>
 #include <lualib.h>
 
+#include <libloc/libloc.h>
+
 #include "location.h"
 
+struct loc_ctx* ctx = NULL;
+
 static int version(lua_State* L) {
        lua_pushstring(L, PACKAGE_VERSION);
        return 1;
@@ -31,6 +38,15 @@ static const struct luaL_Reg location_functions[] = {
 };
 
 int luaopen_location(lua_State* L) {
+       int r;
+
+       // Initialize the context
+       r = loc_new(&ctx);
+       if (r)
+               return luaL_error(L,
+                       "Could not initialize location context: %s\n", strerror(errno));
+
+       // Register functions
        luaL_newlib(L, location_functions);
 
        return 1;
index 539c5a27312ef75114928c1572d2fa45c9eab57d..1f64f5c496608eb578ae54d64d41f0bd09b65cc9 100644 (file)
@@ -16,4 +16,8 @@
 
 #include <lua.h>
 
+#include <libloc/libloc.h>
+
+extern struct loc_ctx* ctx;
+
 int luaopen_location(lua_State* L);