Replaced module injection with proper module searcher for Lua.
This commit is contained in:
parent
095835ec8c
commit
206d537c3e
6 changed files with 135 additions and 71 deletions
|
@ -47,7 +47,6 @@ set(SINGE_SOURCE
|
||||||
src/frameFile.c
|
src/frameFile.c
|
||||||
src/videoPlayer.h
|
src/videoPlayer.h
|
||||||
src/util.c
|
src/util.c
|
||||||
src/embedded.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
-- Default Mappings
|
-- Default Mappings
|
||||||
|
|
||||||
DEAD_ZONE = 8000
|
DEAD_ZONE = 15000
|
||||||
|
|
||||||
INPUT_UP = { SCANCODE.UP, SCANCODE.KP_8, GAMEPAD_0.AXIS_LEFT_Y_U, GAMEPAD_0.AXIS_RIGHT_Y_U, GAMEPAD_0.DPAD_UP }
|
INPUT_UP = { SCANCODE.UP, SCANCODE.KP_8, GAMEPAD_0.AXIS_LEFT_Y_U, GAMEPAD_0.AXIS_RIGHT_Y_U, GAMEPAD_0.DPAD_UP }
|
||||||
INPUT_LEFT = { SCANCODE.LEFT, SCANCODE.KP_4, GAMEPAD_0.AXIS_LEFT_X_L, GAMEPAD_0.AXIS_RIGHT_X_L, GAMEPAD_0.DPAD_LEFT }
|
INPUT_LEFT = { SCANCODE.LEFT, SCANCODE.KP_4, GAMEPAD_0.AXIS_LEFT_X_L, GAMEPAD_0.AXIS_RIGHT_X_L, GAMEPAD_0.DPAD_LEFT }
|
||||||
|
|
19
build-all.sh
19
build-all.sh
|
@ -295,6 +295,25 @@ if [[ 0 == 1 ]]; then
|
||||||
createEmbeddedBinary ${G_TARGET}/menuBackground.mkv ${G_GENERATED}/menuBackground_mkv.h MENUBACKGROUND_MKV_H
|
createEmbeddedBinary ${G_TARGET}/menuBackground.mkv ${G_GENERATED}/menuBackground_mkv.h MENUBACKGROUND_MKV_H
|
||||||
rm ${G_TARGET}/temp1.mkv ${G_TARGET}/temp2.mkv ${G_TARGET}/menuBackground.mkv
|
rm ${G_TARGET}/temp1.mkv ${G_TARGET}/temp2.mkv ${G_TARGET}/menuBackground.mkv
|
||||||
|
|
||||||
|
# === LuaSocket ===
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/ftp.lua ${G_GENERATED}/ftp_lua.h FTP_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/headers.lua ${G_GENERATED}/headers_lua.h HEADERS_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/http.lua ${G_GENERATED}/http_lua.h HTTP_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/ltn12.lua ${G_GENERATED}/ltn12_lua.h LTN12_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/mbox.lua ${G_GENERATED}/mbox_lua.h MBOX_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/mime.lua ${G_GENERATED}/mime_lua.h MIME_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/smtp.lua ${G_GENERATED}/smtp_lua.h SMTP_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/socket.lua ${G_GENERATED}/socket_lua.h SOCKET_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/tp.lua ${G_GENERATED}/tp_lua.h TP_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasocket/src/url.lua ${G_GENERATED}/url_lua.h URL_LUA_H
|
||||||
|
|
||||||
|
# === LuaSec ===
|
||||||
|
createEmbeddedBinary thirdparty/luasec/src/https.lua ${G_GENERATED}/https_lua.h HTTPS_LUA_H
|
||||||
|
createEmbeddedBinary thirdparty/luasec/src/ssl.lua ${G_GENERATED}/ssl_lua.h SSL_LUA_H
|
||||||
|
|
||||||
|
# === LuaRS232 ===
|
||||||
|
createEmbeddedBinary thirdparty/librs232/bindings/lua/rs232.lua ${G_GENERATED}/rs232_lua.h RS232_LUA_H
|
||||||
|
|
||||||
:<<UNUSED
|
:<<UNUSED
|
||||||
# === Singe Manual ===
|
# === Singe Manual ===
|
||||||
#libreoffice --headless "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" --convert-to pdf:writer_pdf_Export Manual.odt
|
#libreoffice --headless "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" --convert-to pdf:writer_pdf_Export Manual.odt
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Singe 2
|
|
||||||
* Copyright (C) 2006-2024 Scott Duensing <scott@kangaroopunch.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#define EMBED_HERE
|
|
||||||
|
|
||||||
#undef EMBEDDED_H
|
|
||||||
#include "embedded.h"
|
|
||||||
|
|
||||||
#undef EMBED_HERE
|
|
|
@ -38,5 +38,24 @@
|
||||||
#include "generated/menuBackground_mkv.h"
|
#include "generated/menuBackground_mkv.h"
|
||||||
//#include "generated/Manual_pdf.h"
|
//#include "generated/Manual_pdf.h"
|
||||||
|
|
||||||
|
// LuaSocket
|
||||||
|
#include "generated/ftp_lua.h"
|
||||||
|
#include "generated/headers_lua.h"
|
||||||
|
#include "generated/http_lua.h"
|
||||||
|
#include "generated/ltn12_lua.h"
|
||||||
|
#include "generated/mbox_lua.h"
|
||||||
|
#include "generated/mime_lua.h"
|
||||||
|
#include "generated/smtp_lua.h"
|
||||||
|
#include "generated/socket_lua.h"
|
||||||
|
#include "generated/tp_lua.h"
|
||||||
|
#include "generated/url_lua.h"
|
||||||
|
|
||||||
|
// LuaSec
|
||||||
|
#include "generated/https_lua.h"
|
||||||
|
#include "generated/ssl_lua.h"
|
||||||
|
|
||||||
|
// LuaRS232
|
||||||
|
#include "generated/rs232_lua.h"
|
||||||
|
|
||||||
|
|
||||||
#endif // EMBEDDED_H
|
#endif // EMBEDDED_H
|
||||||
|
|
137
src/singe.c
137
src/singe.c
|
@ -52,6 +52,11 @@ LSEC_API int luaopen_ssl_config(lua_State *L);
|
||||||
#include "frameFile.h"
|
#include "frameFile.h"
|
||||||
#include "videoPlayer.h"
|
#include "videoPlayer.h"
|
||||||
#include "singe.h"
|
#include "singe.h"
|
||||||
|
|
||||||
|
// We have to do the embedding here so the Lua module
|
||||||
|
// definitions can find their lenght properly. They
|
||||||
|
// can't be external to this source file.
|
||||||
|
#define EMBED_HERE
|
||||||
#include "embedded.h"
|
#include "embedded.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,6 +72,16 @@ LSEC_API int luaopen_ssl_config(lua_State *L);
|
||||||
#define AXIS_KEY_DOWN 0
|
#define AXIS_KEY_DOWN 0
|
||||||
#define AXIS_KEY_UP 1
|
#define AXIS_KEY_UP 1
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
union {
|
||||||
|
char *source;
|
||||||
|
lua_CFunction openf;
|
||||||
|
};
|
||||||
|
size_t length;
|
||||||
|
} luaModuleT;
|
||||||
|
|
||||||
typedef struct MouseS {
|
typedef struct MouseS {
|
||||||
int32_t x;
|
int32_t x;
|
||||||
int32_t y;
|
int32_t y;
|
||||||
|
@ -236,6 +251,44 @@ typedef struct GlobalS {
|
||||||
GlobalT _global;
|
GlobalT _global;
|
||||||
|
|
||||||
|
|
||||||
|
#define MODL(name, array) { name, { (char *)array }, sizeof(array) }
|
||||||
|
#define MODC(name, openf) { name, { (char *)openf }, 0 }
|
||||||
|
|
||||||
|
|
||||||
|
// Lua Modules
|
||||||
|
static const luaModuleT luaModules[] = {
|
||||||
|
// LuaFileSystem
|
||||||
|
MODC("lfs", luaopen_lfs),
|
||||||
|
// LuaSocket
|
||||||
|
MODC("mime.core", luaopen_mime_core),
|
||||||
|
MODC("socket.core", luaopen_socket_core),
|
||||||
|
MODL("ltn12", ltn12_lua),
|
||||||
|
MODL("mbox", mbox_lua),
|
||||||
|
MODL("mime", mime_lua),
|
||||||
|
MODL("socket", socket_lua),
|
||||||
|
MODL("socket.ftp", ftp_lua),
|
||||||
|
MODL("socket.headers", headers_lua),
|
||||||
|
MODL("socket.http", http_lua),
|
||||||
|
MODL("socket.smtp", smtp_lua),
|
||||||
|
MODL("socket.tp", tp_lua),
|
||||||
|
MODL("socket.url", url_lua),
|
||||||
|
#ifndef _WIN32
|
||||||
|
MODC("socket.unix", luaopen_socket_unix),
|
||||||
|
MODC("socket.serial", luaopen_socket_serial),
|
||||||
|
#endif
|
||||||
|
// LuaSec
|
||||||
|
MODC("ssl.core", luaopen_ssl_core),
|
||||||
|
MODC("ssl.context", luaopen_ssl_context),
|
||||||
|
MODC("ssl.x509", luaopen_ssl_x509),
|
||||||
|
MODC("ssl.config", luaopen_ssl_config),
|
||||||
|
MODL("ssl.https", https_lua),
|
||||||
|
MODL("ssl", ssl_lua),
|
||||||
|
// LuaRS232
|
||||||
|
MODC("rs232.core", luaopen_luars232),
|
||||||
|
MODL("rs232", rs232_lua),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int32_t apiColorBackground(lua_State *L);
|
int32_t apiColorBackground(lua_State *L);
|
||||||
int32_t apiColorForeground(lua_State *L);
|
int32_t apiColorForeground(lua_State *L);
|
||||||
|
|
||||||
|
@ -352,7 +405,7 @@ void channelFinished(int channel);
|
||||||
void line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, SDL_Color *c);
|
void line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, SDL_Color *c);
|
||||||
void luaDie(lua_State *L, char *method, char *fmt, ...);
|
void luaDie(lua_State *L, char *method, char *fmt, ...);
|
||||||
int32_t luaError(lua_State *L);
|
int32_t luaError(lua_State *L);
|
||||||
void luaPreload(lua_State *L, const char *name, lua_CFunction func);
|
int luaSearcher(lua_State *L);
|
||||||
void luaTrace(lua_State *L, char *method, char *fmt, ...);
|
void luaTrace(lua_State *L, char *method, char *fmt, ...);
|
||||||
void processKey(bool down, int keysym, int32_t scancode);
|
void processKey(bool down, int keysym, int32_t scancode);
|
||||||
void progTrace(char *fmt, ...);
|
void progTrace(char *fmt, ...);
|
||||||
|
@ -3341,11 +3394,35 @@ void luaStackDump(lua_State *L) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void luaPreload(lua_State *L, const char *name, lua_CFunction func) {
|
int luaSearcher(lua_State *L) {
|
||||||
luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
|
// https://leiradel.github.io/2020/03/01/Embedding-Lua-Modules.html
|
||||||
lua_pushcfunction(L, func);
|
char *modname = (char *)lua_tostring(L, 1);
|
||||||
lua_setfield(L, -2, name);
|
size_t i;
|
||||||
lua_pop(L, 1); // remove PRELOAD table
|
int res;
|
||||||
|
|
||||||
|
// Iterates over all modules we know.
|
||||||
|
for (i = 0; i < sizeof(luaModules) / sizeof(luaModules[0]); i++) {
|
||||||
|
if (strcmp(modname, luaModules[i].name) == 0) {
|
||||||
|
// Found the module.
|
||||||
|
if (luaModules[i].length != 0) {
|
||||||
|
// It's a Lua module, return the chunk that defines the module.
|
||||||
|
res = luaL_loadbufferx(L, luaModules[i].source, luaModules[i].length, modname, "t");
|
||||||
|
if (res != LUA_OK) {
|
||||||
|
// Compilation error.
|
||||||
|
return lua_error(L);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// It's a native module, return the native function that defines the module.
|
||||||
|
lua_pushcfunction(L, luaModules[i].openf);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Oops...
|
||||||
|
lua_pushfstring(L, "Unknown Lua module: \"%s\"", modname);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4389,46 +4466,24 @@ void startControllers(void) {
|
||||||
|
|
||||||
|
|
||||||
void startLuaContext(lua_State *L) {
|
void startLuaContext(lua_State *L) {
|
||||||
|
size_t length;
|
||||||
|
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
lua_atpanic(L, luaError);
|
lua_atpanic(L, luaError);
|
||||||
|
|
||||||
luaPreload(L, "lfs", luaopen_lfs);
|
// Get the package global table.
|
||||||
luaPreload(L, "socket.core", luaopen_socket_core);
|
lua_getglobal(L, "package");
|
||||||
luaPreload(L, "mime.core", luaopen_mime_core);
|
// Get the list of searchers in the package table.
|
||||||
luaPreload(L, "rs232", luaopen_luars232);
|
lua_getfield(L, -1, "searchers");
|
||||||
#ifndef _WIN32
|
// Get the number of existing searchers in the table.
|
||||||
luaPreload(L, "socket.unix", luaopen_socket_unix);
|
length = lua_rawlen(L, -1);
|
||||||
luaPreload(L, "socket.serial", luaopen_socket_serial);
|
// Add our own searcher to the list.
|
||||||
#endif
|
lua_pushcfunction(L, luaSearcher);
|
||||||
luaPreload(L, "ssl.core", luaopen_ssl_core);
|
lua_rawseti(L, -2, length + 1);
|
||||||
luaPreload(L, "ssl.context", luaopen_ssl_context);
|
// Remove the seachers and the package tables from the stack.
|
||||||
luaPreload(L, "ssl.x509", luaopen_ssl_x509);
|
lua_pop(L, 2);
|
||||||
luaPreload(L, "ssl.config", luaopen_ssl_config);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
***TODO*** Load these Lua modules:
|
|
||||||
|
|
||||||
Lua Socket:
|
|
||||||
socket.lua
|
|
||||||
ltn12.lua
|
|
||||||
tp.lua
|
|
||||||
url.lua
|
|
||||||
ftp.lua
|
|
||||||
mime.lua
|
|
||||||
headers.lua
|
|
||||||
http.lua
|
|
||||||
|
|
||||||
mbox.lua
|
|
||||||
smtp.lua
|
|
||||||
|
|
||||||
luasec:
|
|
||||||
https.lua
|
|
||||||
ssl.lua
|
|
||||||
|
|
||||||
librs232:
|
|
||||||
rs232.lua
|
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
http = require("socket.http")
|
http = require("socket.http")
|
||||||
http.request{
|
http.request{
|
||||||
|
|
Loading…
Add table
Reference in a new issue