]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
lua: Create scaffolding for a module
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 11:02:38 +0000 (11:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 22 Feb 2024 11:02:38 +0000 (11:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/lua/location.c [new file with mode: 0644]
src/lua/location.h [new file with mode: 0644]
tests/lua/main.lua [new file with mode: 0755]

index fb881ea8b496ca89138be7341db30f9e3d73ec3b..fff9722fac8dd7805b644bdb01b01f13f8e4d922 100644 (file)
@@ -3,6 +3,7 @@ CLEANFILES =
 INSTALL_DIRS =
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 AM_MAKEFLAGS = --no-print-directory
+check_SCRIPTS =
 
 SUBDIRS = . po
 BINDINGS =
@@ -227,6 +228,46 @@ src_python__location_la_LIBADD = \
        src/libloc.la \
        $(PYTHON_LIBS)
 
+# ------------------------------------------------------------------------------
+
+if ENABLE_LUA
+lua_LTLIBRARIES = \
+       src/lua/location.la
+
+luadir = $(LUA_INSTALL_CMOD)
+
+src_lua_location_la_SOURCES = \
+       src/lua/location.c \
+       src/lua/location.h
+
+src_lua_location_la_CFLAGS = \
+       $(AM_CFLAGS) \
+       $(LUA_CFLAGS)
+
+src_lua_location_la_LDFLAGS = \
+       $(AM_LDFLAGS) \
+       $(LUA_LDFLAGS) \
+       -shared \
+       -module \
+       -avoid-version
+
+src_lua_location_la_LIBADD = \
+       src/libloc.la \
+       $(LUA_LIBS)
+endif
+
+EXTRA_DIST += \
+       src/lua/location.c \
+       src/lua/location.h
+
+LUA_TESTS = \
+       tests/lua/main.lua
+
+EXTRA_DIST += \
+       $(LUA_TESTS)
+
+# ------------------------------------------------------------------------------
+
 # Compile & install bindings
 all-local: $(foreach binding,$(BINDINGS),build-$(binding))
 check-local: $(foreach binding,$(BINDINGS),check-$(binding))
@@ -346,11 +387,13 @@ TESTS_LDADD = \
        src/libloc-internal.la
 
 TESTS_ENVIRONMENT = \
+       LUA_PATH="$(abs_builddir)/src/lua/.libs/?.so;;" \
        PYTHONPATH=$(abs_srcdir)/src/python:$(abs_builddir)/src/python/.libs \
        TEST_DATA_DIR="$(abs_top_srcdir)/data"
 
 TESTS = \
        $(check_PROGRAMS) \
+       $(check_SCRIPTS) \
        $(dist_check_SCRIPTS)
 
 CLEANFILES += \
@@ -367,6 +410,11 @@ dist_check_SCRIPTS = \
        tests/python/test-database.py \
        tests/python/test-export.py
 
+if ENABLE_LUA
+check_SCRIPTS += \
+       $(LUA_TESTS)
+endif
+
 check_PROGRAMS = \
        src/test-libloc \
        src/test-stringpool \
diff --git a/src/lua/location.c b/src/lua/location.c
new file mode 100644 (file)
index 0000000..2b23f92
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+       libloc - A library to determine the location of someone on the Internet
+
+       Copyright (C) 2024 IPFire Development Team <info@ipfire.org>
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+*/
+
+#include <lua.h>
+
+#include "location.h"
+
+int luaopen_location(lua_State* L) {
+       return 0;
+}
diff --git a/src/lua/location.h b/src/lua/location.h
new file mode 100644 (file)
index 0000000..539c5a2
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+       libloc - A library to determine the location of someone on the Internet
+
+       Copyright (C) 2024 IPFire Development Team <info@ipfire.org>
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+*/
+
+#include <lua.h>
+
+int luaopen_location(lua_State* L);
diff --git a/tests/lua/main.lua b/tests/lua/main.lua
new file mode 100755 (executable)
index 0000000..d09e217
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/lua
+--[[###########################################################################
+#                                                                             #
+# libloc - A library to determine the location of someone on the Internet     #
+#                                                                             #
+# Copyright (C) 2024 IPFire Development Team <info@ipfire.org>                #
+#                                                                             #
+# This library is free software; you can redistribute it and/or               #
+# modify it under the terms of the GNU Lesser General Public                  #
+# License as published by the Free Software Foundation; either                #
+# version 2.1 of the License, or (at your option) any later version.          #
+#                                                                             #
+# This library is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           #
+# Lesser General Public License for more details.                             #
+#                                                                             #
+############################################################################--]]
+
+luaunit = require("luaunit")
+
+function test_load()
+       -- Try loading the module
+       location = require("location")
+end
+
+os.exit(luaunit.LuaUnit.run())