projects/guix·blob javascript-team · refs

42 lines · 1.6 KiB

1Change Lua to use GUIX_LUA_PATH and GUIX_LUA_CPATH to construct the default
2LUA_PATH and LUA_CPATH, instead of using hard-coded paths that Guix doesn't
3populate.
4
5These paths don't use Lua's usual '?' path wildcard, and thus are compatible
6with Guix's search-paths mechanism.
7
8This patch uses functions defined in lua-5.x-search-path-helpers.patch.
9
10--- a/src/loadlib.c
11+++ b/src/loadlib.c
12@@ -687,6 +687,9 @@
13 }
14
15
16+#include "./guixpaths.c"
17+
18+
19 LUAMOD_API int luaopen_package (lua_State *L) {
20 /* create table CLIBS to keep track of loaded C libraries */
21 luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
22@@ -702,10 +757,18 @@
23 lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */
24 #endif
25 lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
26+
27+ /* Calculate default LUA_PATH and LUA_CPATH values from their
28+ corresponding GUIX_ environment variables */
29+ const char* default_path = guix_path(L); // push default_path
30+ const char* default_cpath = guix_cpath(L); // push default_cpath
31+ lua_pushvalue(L, -3); // copy the old head of the stack back to the top
32 /* set field 'path' */
33- setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT);
34+ setpath(L, "path", LUA_PATHVERSION, LUA_PATH, default_path);
35 /* set field 'cpath' */
36- setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT);
37+ setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, default_cpath);
38+ lua_pop(L, 3); // pop our three working values back off the stack
39+
40 /* store config information */
41 lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
42 LUA_EXEC_DIR "\n" LUA_IGMARK "\n");