Singe now properly pre-loads embedded Lua C libraries.

This commit is contained in:
Scott Duensing 2020-04-09 21:06:05 -05:00
parent 405881f2d7
commit aff5341801
2 changed files with 19 additions and 7 deletions

View file

@ -23,6 +23,8 @@
dofile("Singe/Framework.singe")
lfs = require("lfs")
function compareTitles(a, b)
return a.TITLE < b.TITLE

View file

@ -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
}