1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-04-06 21:20:33 +02:00
Files
guix/gnu/packages/patches/lua-5.x-search-path-helpers.patch
Carlo Zancanaro 906b1e13aa gnu: lua: Introduce GUIX_LUA_{,C}PATH to set default Lua search paths.
Fixes <https://issues.guix.gnu.org/issue/25425>.

* gnu/packages/patches/luajit-search-paths.patch: New file.
* gnu/packages/patches/lua-5.1-search-paths.patch: New file.
* gnu/packages/patches/lua-5.2-search-paths.patch: New file.
* gnu/packages/patches/lua-5.3-search-paths.patch: New file.
* gnu/packages/patches/lua-5.4-search-paths.patch: New file.
* gnu/packages/patches/lua-5.x-search-path-helpers: New file.
* gnu/local.mk (dist_patch_DATA): Register them.
* gnu/packages/lua.scm
(lua-search-paths): New procedure.
(lua) [source]: Apply patches.
[native-search-paths]: Define using lua-search-paths.
(lua-5.4) [source]: Apply patches.
[native-search-paths]: Define using lua-search-paths.
(lua-5.2) [source]: Apply patches.
[native-search-paths]: Define using lua-search-paths.
(lua-5.1) [source]: Apply patches.
[native-search-paths]: Define using lua-search-paths.
(luajit) [source]: Apply patches.
[native-search-paths]: Define GUIX_LUA_PATH and GUIX_LUA_CPATH.

Change-Id: I8adc08076e615b3dacc10007eae7c1e9b7d527c0
Signed-off-by: Andreas Enge <andreas@enge.fr>
2026-02-18 21:02:26 +01:00

63 lines
1.8 KiB
Diff

Define two helper functions that are used in other Lua patches.
The functions construct default values for LUA_PATH and LUA_CPATH (using '?'s
as wildcards) from GUIX_LUA_PATH and GUIX_LUA_CPATH, respectively.
--- /dev/null
+++ b/src/guixpaths.c
@@ -0,0 +1,54 @@
+const char* guix_path (lua_State* L) {
+ luaL_Buffer buf;
+ luaL_buffinit(L, &buf);
+
+ const char* next;
+ const char* source = getenv("GUIX_LUA_PATH");
+ if (source != NULL) {
+ while ((next = strstr(source, ";")) != NULL) {
+ luaL_addlstring(&buf, source, next - source); /* push prefix */
+ luaL_addstring(&buf, "/?.lua;");
+ luaL_addlstring(&buf, source, next - source); /* push prefix */
+ luaL_addstring(&buf, "/?/init.lua;");
+ source = next + 1; /* continue after the semicolon */
+ }
+ if (*source != '\0') {
+ luaL_addstring(&buf, source);
+ luaL_addstring(&buf, "/?.lua;");
+ luaL_addstring(&buf, source);
+ luaL_addstring(&buf, "/?/init.lua;");
+ }
+ }
+
+ /* Then add the local directory last */
+ luaL_addstring(&buf, "./?.lua;" "./?/init.lua");
+ luaL_pushresult(&buf);
+ return lua_tostring(L, -1);
+}
+
+
+const char* guix_cpath (lua_State* L) {
+ luaL_Buffer buf;
+ luaL_buffinit(L, &buf);
+
+ const char* next;
+ const char* source = getenv("GUIX_LUA_CPATH");
+ if (source != NULL) {
+ while ((next = strstr(source, ";")) != NULL) {
+ luaL_addlstring(&buf, source, next - source); /* push prefix */
+ luaL_addstring(&buf, "/?.so;");
+ source = next + 1; /* continue after the semicolon */
+ }
+ if (*source != '\0') {
+ luaL_addstring(&buf, source);
+ luaL_addstring(&buf, "/?.so;");
+ }
+ }
+
+ /* Then add the local directory last */
+ luaL_addstring(&buf, "./?.so");
+
+ luaL_pushresult(&buf);
+ return lua_tostring(L, -1);
+}
+