From f51350bbf745d9551894794ac3ff8d5100575cd7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 22 Feb 2024 11:27:16 +0000 Subject: [PATCH] lua: Initialize location context Signed-off-by: Michael Tremer --- src/lua/location.c | 16 ++++++++++++++++ src/lua/location.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/lua/location.c b/src/lua/location.c index e8441a4..a61a9ae 100644 --- a/src/lua/location.c +++ b/src/lua/location.c @@ -14,12 +14,19 @@ Lesser General Public License for more details. */ +#include +#include + #include #include #include +#include + #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; diff --git a/src/lua/location.h b/src/lua/location.h index 539c5a2..1f64f5c 100644 --- a/src/lua/location.h +++ b/src/lua/location.h @@ -16,4 +16,8 @@ #include +#include + +extern struct loc_ctx* ctx; + int luaopen_location(lua_State* L); -- 2.39.2