From aff534180195e508cf99c509c2398dd127e0a6ef Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Thu, 9 Apr 2020 21:06:05 -0500 Subject: [PATCH] Singe now properly pre-loads embedded Lua C libraries. --- singe/Menu.singe | 2 ++ singe/singe.c | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/singe/Menu.singe b/singe/Menu.singe index 27a30efb4..da0333eda 100644 --- a/singe/Menu.singe +++ b/singe/Menu.singe @@ -23,6 +23,8 @@ dofile("Singe/Framework.singe") +lfs = require("lfs") + function compareTitles(a, b) return a.TITLE < b.TITLE diff --git a/singe/singe.c b/singe/singe.c index 95500bd72..b9bed14e2 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -34,9 +34,9 @@ #include "thirdparty/manymouse/manymouse.h" #include "thirdparty/luafilesystem/src/lfs.h" #include "thirdparty/luasocket/src/luasocket.h" +#include "thirdparty/luasocket/src/mime.h" #ifndef _WIN32 -#include "thirdparty/luasocket/src/unixdgram.h" -#include "thirdparty/luasocket/src/unixstream.h" +#include "thirdparty/luasocket/src/unix.h" // There is no serial.h, so fake it. LUASOCKET_API int luaopen_socket_serial(lua_State *L); #endif @@ -340,6 +340,7 @@ void callLua(const char *func, const char *sig, ...); void channelFinished(int channel); void luaDie(lua_State *L, char *method, char *fmt, ...); int32_t luaError(lua_State *L); +void luaPreload(lua_State *L, const char *name, lua_CFunction func); void luaTrace(lua_State *L, char *method, char *fmt, ...); void processKey(bool down, int keysym, int32_t scancode); void putPixel(int32_t x, int32_t y); @@ -3213,6 +3214,14 @@ void luaStackDump(lua_State *L) { #endif +void luaPreload(lua_State *L, const char *name, lua_CFunction func) { + luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); + lua_pushcfunction(L, func); + lua_setfield(L, -2, name); + lua_pop(L, 1); // remove PRELOAD table +} + + void luaTrace(lua_State *L, char *method, char *fmt, ...) { va_list args; lua_Debug ar; @@ -4142,12 +4151,13 @@ void startControllers(void) { void startLuaContext(lua_State *L) { luaL_openlibs(L); lua_atpanic(L, luaError); - luaopen_lfs(L); - luaopen_socket_core(L); + + luaPreload(L, "lfs", luaopen_lfs); + luaPreload(L, "socket.core", luaopen_socket_core); + luaPreload(L, "mime.core", luaopen_mime_core); #ifndef _WIN32 - unixdgram_open(L); - unixstream_open(L); - luaopen_socket_serial(L); + luaPreload(L, "socket.unix", luaopen_socket_unix); + luaPreload(L, "socket.serial", luaopen_socket_serial); #endif }