Skip to content

Commit

Permalink
Add bundled script loading into luaL_openlibs to make them available …
Browse files Browse the repository at this point in the history
…globally (also in the webserver)

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Sep 23, 2024
1 parent dce844b commit 0ff00e1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/lua/ftl_lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ int run_luac(const int argc, char **argv);
int lua_main (int argc, char **argv);
int luac_main (int argc, char **argv);

extern int dolibrary (lua_State *L, char *name);

void print_embedded_scripts(void);
void ftl_lua_init(lua_State *L);

Expand Down
6 changes: 6 additions & 0 deletions src/lua/linit.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#define linit_c
#define LUA_LIB

/** Pi-hole modification **/
#include "ftl_lua.h"
/**************************/

/*
** If you embed Lua in your program and need to open the standard
** libraries, call luaL_openlibs in your program. If you need a
Expand Down Expand Up @@ -64,5 +68,7 @@ LUALIB_API void luaL_openlibs (lua_State *L) {
luaL_requiref(L, lib->name, lib->func, 1);
lua_pop(L, 1); /* remove lib */
}
// Load and enable libraries bundled with Pi-hole
ftl_lua_init(L);
}

13 changes: 1 addition & 12 deletions src/lua/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include "lauxlib.h"
#include "lualib.h"

/** Pi-hole modification **/
#include "ftl_lua.h"
/**************************/


#if !defined(LUA_PROGNAME)
#define LUA_PROGNAME "lua"
Expand Down Expand Up @@ -218,9 +214,7 @@ static int dostring (lua_State *L, const char *s, const char *name) {
** If there is no explicit modname and globname contains a '-', cut
** the suffix after '-' (the "version") to make the global name.
*/
/************** Pi-hole modification ***************/
int dolibrary (lua_State *L, char *globname) {
/***************************************************/
static int dolibrary (lua_State *L, char *globname) {
int status;
char *suffix = NULL;
char *modname = strchr(globname, '=');
Expand Down Expand Up @@ -655,11 +649,6 @@ 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, optlim)) /* execute arguments -e and -l */
return 0; /* something failed */
if (script > 0) { /* execute main script (if there is one) */
Expand Down
2 changes: 1 addition & 1 deletion src/webserver/civetweb/mod_lua.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2824,7 +2824,7 @@ lua_error_handler(lua_State *L)
lua_call(L, 2, 0); /* call mg.write(traceback + \n) */
lua_pop(L, 2); /* pop mg and traceback */
} else {
lua_pop(L, 3); /* pop mg, traceback and error message */
lua_pop(L, 3); /* pop mg, traceback and write */
}

} else {
Expand Down

0 comments on commit 0ff00e1

Please sign in to comment.