projects/guix·blob javascript-team · refs

50 lines · 2.1 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@@ -280,7 +280,9 @@
13 if (path == NULL) /* no versioned environment variable? */
14 path = getenv(envname); /* try unversioned name */
15 if (path == NULL || noenv(L)) /* no environment variable? */
16- lua_pushexternalstring(L, dft, strlen(dft), NULL, NULL); /* use default */
17+ /* Copy our constructed default string onto the Lua stack.
18+ * Otherwise the location might be reused for another string and case us problems! */
19+ lua_pushstring(L, dft); /* use default */
20 else if ((dftmark = strstr(path, LUA_PATH_SEP LUA_PATH_SEP)) == NULL)
21 lua_pushstring(L, path); /* nothing to change */
22 else { /* path contains a ";;": insert default path in its place */
23@@ -721,14 +729,25 @@
24 }
25
26
27+#include "./guixpaths.c"
28+
29+
30 LUAMOD_API int luaopen_package (lua_State *L) {
31 luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS); /* create CLIBS table */
32 lua_pop(L, 1); /* will not use it now */
33 luaL_newlib(L, pk_funcs); /* create 'package' table */
34 createsearcherstable(L);
35+
36 /* set paths */
37+ /* Calculate default LUA_PATH and LUA_CPATH values from their
38+ corresponding GUIX_ environment variables */
39+ const char* default_path = guix_path(L); // push default_path
40+ const char* default_cpath = guix_cpath(L); // push default_cpath
41+ lua_pushvalue(L, -3); // copy the old head of the stack back to the top
42- setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT);
43- setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);
44+ setpath(L, "path", LUA_PATH_VAR, default_path);
45+ setpath(L, "cpath", LUA_CPATH_VAR, default_cpath);
46+ lua_pop(L, 3); // pop our three working values back off the stack
47+
48 /* store config information */
49 lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
50 LUA_EXEC_DIR "\n" LUA_IGMARK "\n");