[syslinux:master] lua: enable dynamic module loading
syslinux-bot for Ferenc Wágner
wferi at niif.hu
Sun Mar 2 13:48:21 PST 2014
Commit-ID: 351ce48b5a009eb9f3a3a6a21051351a2f0b381b
Gitweb: http://www.syslinux.org/commit/351ce48b5a009eb9f3a3a6a21051351a2f0b381b
Author: Ferenc Wágner <wferi at niif.hu>
AuthorDate: Sun, 13 Oct 2013 21:52:53 +0200
Committer: Ferenc Wágner <wferi at niif.hu>
CommitDate: Sat, 1 Mar 2014 17:40:34 +0100
lua: enable dynamic module loading
---
com32/lua/src/loadlib.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
com32/lua/src/luaconf.h | 3 +++
2 files changed, 48 insertions(+)
diff --git a/com32/lua/src/loadlib.c b/com32/lua/src/loadlib.c
index a995927..3962889 100644
--- a/com32/lua/src/loadlib.c
+++ b/com32/lua/src/loadlib.c
@@ -212,6 +212,51 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
/* }====================================================== */
+#elif defined(SYSLINUX)
+/*
+** {=========================================================================
+** This is an implementation of loadlib for the Syslinux COM32 module system.
+** ==========================================================================
+*/
+
+#include <sys/module.h>
+
+static void ll_unloadlib (void *lib) {
+ module_unload ((struct elf_module *)lib);
+}
+
+
+static void *ll_load (lua_State *L, const char *path, int seeglb) {
+ int err;
+ struct elf_module *lib = module_alloc (path);
+ if (lib == NULL) {
+ lua_pushstring (L, "module not found");
+ return NULL;
+ }
+ (void)seeglb; /* gcc, ignore it */
+ err = module_load (lib);
+ if (err) {
+ printf ("module load error: %d\n", err);
+ lua_pushstring (L, "failed to load module");
+ return NULL;
+ }
+ return (void *)lib;
+}
+
+
+static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
+ Elf_Sym *p = module_find_symbol (sym, (struct elf_module *)lib);
+ if (p == NULL) {
+ lua_pushstring (L, "symbol not found in module");
+ return NULL;
+ }
+ return (lua_CFunction)module_get_absolute(p->st_value, (struct elf_module *)lib);
+}
+
+/* }====================================================== */
+
+
+
#else
/*
** {======================================================
diff --git a/com32/lua/src/luaconf.h b/com32/lua/src/luaconf.h
index fa6546b..7fd4eaa 100644
--- a/com32/lua/src/luaconf.h
+++ b/com32/lua/src/luaconf.h
@@ -97,6 +97,9 @@
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
+#elif defined(SYSLINUX)
+#define LUA_PATH_DEFAULT "./?.lua"
+#define LUA_CPATH_DEFAULT "./?.c32"
#else /* }{ */
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
More information about the Syslinux-commits
mailing list