Hi,
Even though LuajitTeX has lfs as a built-in library, trying to load it via `require` doesn't work.
(LuaTeX with Lua 5.2/5.3 doesn't have this problem)
This is because the field package.loaded["lfs"] is not set during initialization.
To fix this, change Luas_open to set the module (returned by the module loader) to the package.loaded table, which is available as _LOADED on the registry table.
Also, zlib suffers from a similar problem, both on LuaTeX and LuajitTeX.
Here is a proposed patch to fix these problems:
diff --git a/source/texk/web2c/luatexdir/lua/luastuff.c b/source/texk/web2c/luatexdir/lua/luastuff.c
index 0d9342223..a0590c400 100644
--- a/source/texk/web2c/luatexdir/lua/luastuff.c
+++ b/source/texk/web2c/luatexdir/lua/luastuff.c
@@ -36,9 +36,14 @@ int lua_active = 0;
#define Luas_load(Luas,getS,ls,lua_id) \
lua_load(Luas,getS,ls,lua_id);
#define Luas_open(name,luaopen_lib) \
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); \
lua_pushcfunction(L, luaopen_lib); \
lua_pushstring(L, name); \
- lua_call(L, 1, 0);
+ lua_call(L, 1, 1); \
+ lua_pushvalue(L, -1); /* copy of module */ \
+ lua_setfield(L, -3, name); /* _LOADED[name] = module */ \
+ lua_setglobal(L, name); /* _G[name] = module */ \
+ lua_pop(L, 1); /* pop _LOADED table */
#else
#define Luas_load(Luas,getS,ls,lua_id) \
lua_load(Luas,getS,ls,lua_id,NULL);
@@ -347,8 +352,7 @@ void luainterpreter(void)
luatex_socketlua_open(L);
}
/*tex |zlib|'s slightly odd calling convention */
- luaopen_zlib(L);
- lua_setglobal(L, "zlib");
+ Luas_open("zlib", luaopen_zlib);
luaopen_gzip(L);
/*tex our own libraries register themselves */
luaopen_fio(L);
--
Mizuki