Add LUA patches

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2022-11-25 18:49:59 +01:00
parent a0ce163886
commit 717181335b
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
6 changed files with 86 additions and 13 deletions

4
patch/lua.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/sh
set -e
patch -p1 < patch/lua/0001-add-pihole-library.patch

View File

@ -0,0 +1,80 @@
diff --git a/src/lua/linit.c b/src/lua/linit.c
index 69808f84..83b89555 100644
--- a/src/lua/linit.c
+++ b/src/lua/linit.c
@@ -50,6 +50,7 @@ static const luaL_Reg loadedlibs[] = {
{LUA_MATHLIBNAME, luaopen_math},
{LUA_UTF8LIBNAME, luaopen_utf8},
{LUA_DBLIBNAME, luaopen_debug},
+ {LUA_PIHOLELIBNAME, luaopen_pihole},
{NULL, NULL}
};
diff --git a/src/lua/lua.c b/src/lua/lua.c
index 454ce12f..a363925c 100644
--- a/src/lua/lua.c
+++ b/src/lua/lua.c
@@ -20,6 +20,8 @@
#include "lauxlib.h"
#include "lualib.h"
+#include "ftl_lua.h"
+
#if !defined(LUA_PROGNAME)
#define LUA_PROGNAME "lua"
@@ -190,7 +192,7 @@ static int dostring (lua_State *L, const char *s, const char *name) {
** Calls 'require(name)' and stores the result in a global variable
** with the given name.
*/
-static int dolibrary (lua_State *L, const char *name) {
+int dolibrary (lua_State *L, const char *name) {
int status;
lua_getglobal(L, "require");
lua_pushstring(L, name);
@@ -597,6 +599,10 @@ static int pmain (lua_State *L) {
if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
return 0; /* error running LUA_INIT */
}
+
+ // Load and enable libraries bundled with Pi-hole
+ ftl_lua_init(L);
+
if (!runargs(L, argv, script)) /* execute arguments -e and -l */
return 0; /* something failed */
if (script < argc && /* execute main script (if there is one) */
@@ -616,7 +622,7 @@ static int pmain (lua_State *L) {
}
-int main (int argc, char **argv) {
+int lua_main (int argc, char **argv) {
int status, result;
lua_State *L = luaL_newstate(); /* create state */
if (L == NULL) {
diff --git a/src/lua/luac.c b/src/lua/luac.c
index 56ddc414..d7d219e4 100644
--- a/src/lua/luac.c
+++ b/src/lua/luac.c
@@ -194,7 +194,7 @@ static int pmain(lua_State* L)
return 0;
}
-int main(int argc, char* argv[])
+int luac_main(int argc, char* argv[])
{
lua_State* L;
int i=doargs(argc,argv);
diff --git a/src/lua/lualib.h b/src/lua/lualib.h
index eb08b530..e6dfbf6c 100644
--- a/src/lua/lualib.h
+++ b/src/lua/lualib.h
@@ -44,6 +44,8 @@ LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
+#define LUA_PIHOLELIBNAME "pihole"
+LUAMOD_API int (luaopen_pihole) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);

View File

@ -1,5 +1,5 @@
#!/bin/sh
set -e
patch src/database/shell.c patches/sqlite3/0001-print-FTL-version-in-interactive-shell.patch
patch src/database/sqlite3.c patches/sqlite3/0002-make-sqlite3ErrName-public.patch
patch -p1 < patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch
patch -p1 < patch/sqlite3/0002-make-sqlite3ErrName-public.patch

View File

@ -50,9 +50,7 @@ static const luaL_Reg loadedlibs[] = {
{LUA_MATHLIBNAME, luaopen_math},
{LUA_UTF8LIBNAME, luaopen_utf8},
{LUA_DBLIBNAME, luaopen_debug},
/************** Pi-hole modification ***************/
{LUA_PIHOLELIBNAME, luaopen_pihole},
/***************************************************/
{NULL, NULL}
};

View File

@ -20,9 +20,7 @@
#include "lauxlib.h"
#include "lualib.h"
/************** Pi-hole modification ***************/
#include "ftl_lua.h"
/***************************************************/
#if !defined(LUA_PROGNAME)
@ -194,9 +192,7 @@ static int dostring (lua_State *L, const char *s, const char *name) {
** Calls 'require(name)' and stores the result in a global variable
** with the given name.
*/
/************** Pi-hole modification ***************/
int dolibrary (lua_State *L, const char *name) {
/***************************************************/
int status;
lua_getglobal(L, "require");
lua_pushstring(L, name);
@ -604,11 +600,8 @@ static int pmain (lua_State *L) {
return 0; /* error running LUA_INIT */
}
/************** Pi-hole modification ***************/
// Load and enable libraries bundled with Pi-hole
ftl_lua_init(L);
/***************************************************/
if (!runargs(L, argv, script)) /* execute arguments -e and -l */
return 0; /* something failed */

View File

@ -44,10 +44,8 @@ LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/************** Pi-hole modification ***************/
#define LUA_PIHOLELIBNAME "pihole"
LUAMOD_API int (luaopen_pihole) (lua_State *L);
/***************************************************/
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);