This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch efl
in repository laugh.
View the commit online.
commit f194c941ac37922fc5a841e0f9d583c6a02e45ad
Author: melerva <[email protected]>
AuthorDate: Sun Sep 21 12:51:47 2025 -0400
Finally sorted out the xxd -i thing
---
meson.build | 11 +++++--
src/main.c | 6 ----
src/modules/laugh_ui.c | 8 +++--
src/modules/mod_packagegc.c | 77 +++++--------------------------------------
src/modules/mod_packagegc.lua | 70 +++++++++++++++++++++++++++++++++++++++
test/init.lua | 4 +--
6 files changed, 95 insertions(+), 81 deletions(-)
diff --git a/meson.build b/meson.build
index 5cd1c32..a0053d7 100644
--- a/meson.build
+++ b/meson.build
@@ -35,16 +35,21 @@ laugh_sources = [
'src/modules/laugh_ui.c',
'src/packages.c',
'src/require.c',
- custom_target('laugh_luaui.h',
- output: 'laugh_luaui.h',
+ custom_target('laugh_ui.lua.h',
+ output: 'laugh_ui.lua.h',
input: 'src/modules/laugh_ui.lua',
- command: [prog_xxd, '-i', '-n', 'luaui_source', '@INPUT@', '@OUTPUT@'],
+ command: [prog_xxd, '-i', '-n', 'laugh_ui_str', '@INPUT@', '@OUTPUT@'],
),
]
if get_option('mod_packagegc')
conf.set('LAUGH_MOD_PACKAGEGC', true)
laugh_sources += 'src/modules/mod_packagegc.c'
+ laugh_sources += custom_target('mod_packagegc.lua.h',
+ output: 'mod_packagegc.lua.h',
+ input: 'src/modules/mod_packagegc.lua',
+ command: [prog_xxd, '-i', '-n', 'mod_packagegc_str', '@INPUT@', '@OUTPUT@'],
+ )
endif
configure_file(output: 'config.h', configuration: conf)
diff --git a/src/main.c b/src/main.c
index 3945b6b..785c029 100644
--- a/src/main.c
+++ b/src/main.c
@@ -160,12 +160,6 @@ int main(const int argc, char *const argv[]) {
lua_pushcfunction(L, msgh);
}
- /* require laugh module */
- lua_getglobal(L, "require");
- lua_pushstring(L, "laugh");
- lua_call(L, 1, 1);
- lua_setglobal(L, "laugh");
-
/* load main file */
lua_pushcfunction(L, laugh_loadfile);
lua_pushstring(L, "init.lua");
diff --git a/src/modules/laugh_ui.c b/src/modules/laugh_ui.c
index 929b1e0..b92491e 100644
--- a/src/modules/laugh_ui.c
+++ b/src/modules/laugh_ui.c
@@ -4,8 +4,12 @@
#include <lauxlib.h>
int luaopen_laugh_ui(lua_State *const L) {
-#include "laugh_luaui.h"
- luaL_loadstring(L, luaui_source);
+#define unsigned static const // it's more portable than piping through sed
+#define int size_t
+#include "laugh_ui.lua.h"
+#undef int
+#undef unsigned
+ luaL_loadbuffer(L, laugh_ui_str, laugh_ui_str_len, "laugh.ui");
lua_call(L, 0, 1);
return 1;
}
diff --git a/src/modules/mod_packagegc.c b/src/modules/mod_packagegc.c
index a495c39..5f402c1 100644
--- a/src/modules/mod_packagegc.c
+++ b/src/modules/mod_packagegc.c
@@ -1,74 +1,15 @@
+#include "config.h"
+
#include <lauxlib.h>
#include <lua.h>
-#include <lualib.h>
-#include <stdbool.h>
int luaopen_mod_packagegc(lua_State *const L) {
- // [1] = preloader
- // [2] = physfs (inserted in src/require.c)
- // [3] = lua
- // [4] = native
- // [5] = all-in-one
- luaL_loadstring(
- L,
- "do\n"
- " local pl4 = package.searchers[4]\n"
- "\n"
- " package.searchers[4] = function(modname)\n"
- " local r, n = pl4(modname)\n"
- "\n"
- " if (r == nil) or (type(r) == 'string') then\n"
- " return r\n"
- " else\n"
- " local f = function(v)\n"
- " local m = r(v)\n"
- " package.nogc[modname] = m\n"
- " return m\n"
- " end\n"
- "\n"
- " return f, v\n"
- " end\n"
- " end\n"
- "end\n"
-
- "do\n"
- " local pl5 = package.searchers[5]\n"
- "\n"
- " package.searchers[5] = function(modname)\n"
- " local r, n = pl5(modname)\n"
- "\n"
- " if (r == nil) or (type(r) == 'string') then\n"
- " return r\n"
- " else\n"
- " local f = function(v)\n"
- " local m = r(v)\n"
- " package.nogc[modname] = m\n"
- " return m\n"
- " end\n"
- "\n"
- " return f, v\n"
- " end\n"
- " end\n"
- "end\n"
-
- /* If a package is loaded at this point,
- * it is probably built-in. */
- "for n,v in pairs(package.loaded) do\n"
- " package.nogc[n] = v\n"
- "end\n"
- );
- lua_call(L, 0, 0);
-
- /* make `package.loaded` weak */
- lua_getglobal(L, "package");
- lua_getfield(L, -1, "loaded");
- lua_createtable(L, 0, 1);
- lua_pushstring(L, "v");
- lua_setfield(L, -2, "__mode");
- lua_setmetatable(L, -2);
- lua_pop(L, 2);
-
- /* this is a "feral" module, return true */
- lua_pushboolean(L, true);
+#define unsigned static const // it's more portable than piping through sed
+#define int size_t
+#include "mod_packagegc.lua.h"
+#undef int
+#undef unsigned
+ luaL_loadbuffer(L, mod_packagegc_str, mod_packagegc_str_len, "mod_packagegc");
+ lua_call(L, 0, 1);
return 1;
}
diff --git a/src/modules/mod_packagegc.lua b/src/modules/mod_packagegc.lua
new file mode 100644
index 0000000..18dd2cf
--- /dev/null
+++ b/src/modules/mod_packagegc.lua
@@ -0,0 +1,70 @@
+-- make the table if it doesn't exist
+local package = require('package')
+if not package.nogc then
+ package.nogc = {}
+end
+
+--[[ package.searchers should be:
+ [1] = preloader
+ [2] = physfs (inserted in src/require.c)
+ [3] = lua
+ [4] = native
+ [5] = all-in-one
+]]
+
+do -- replace native package searcher with one that adds to package.nogc
+ local pl4 = package.searchers[4]
+
+ package.searchers[4] = function(modname)
+ local r, n = pl4(modname)
+
+ if (r == nil) or (type(r) == 'string') then
+ return r
+ else
+ local f = function(v)
+ local m = r(v)
+ package.nogc[modname] = m
+ return m
+ end
+
+ return f, v
+ end
+ end
+end
+
+do -- replace all-in-one loader with one that adds to package.nogc
+ local pl5 = package.searchers[5]
+
+ package.searchers[5] = function(modname)
+ local r, n = pl5(modname)
+
+ if (r == nil) or (type(r) == 'string') then
+ return r
+ else
+ local f = function(v)
+ local m = r(v)
+ package.nogc[modname] = m
+ return m
+ end
+
+ return f, v
+ end
+ end
+end
+
+-- If a package is loaded at this point, it is probably built-in.
+for n,v in pairs(package.loaded) do
+ package.nogc[n] = v
+end
+
+do -- make package.loaded have a metatable, set it to weakly linked
+ local mt = getmetatable(package.loaded)
+ if not mt then
+ mt = {['__mode'] = 'v'}
+ setmetatable(package.loaded, mt)
+ else
+ mt['__mode'] = 'v'
+ end
+end
+
+return true -- signal this module altered the global lua state
diff --git a/test/init.lua b/test/init.lua
index 03e8680..0317846 100644
--- a/test/init.lua
+++ b/test/init.lua
@@ -1,10 +1,10 @@
+local laugh = require("laugh")
+
print("hello world")
print(laugh.version.major, laugh.version.minor, laugh.version.patch)
print("well, i guess this part works")
print("now let's open a file")
-local laugh = require("laugh")
-
do
local fptr = assert(laugh.open("/file.txt", "rb"))
print("okay the file opened")
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.