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