projects/guix·blob java-team · refs

62 lines · 1.8 KiB

1Define two helper functions that are used in other Lua patches.
2
3The functions construct default values for LUA_PATH and LUA_CPATH (using '?'s
4as wildcards) from GUIX_LUA_PATH and GUIX_LUA_CPATH, respectively.
5
6--- /dev/null
7+++ b/src/guixpaths.c
8@@ -0,0 +1,54 @@
9+const char* guix_path (lua_State* L) {
10+ luaL_Buffer buf;
11+ luaL_buffinit(L, &buf);
12+
13+ const char* next;
14+ const char* source = getenv("GUIX_LUA_PATH");
15+ if (source != NULL) {
16+ while ((next = strstr(source, ";")) != NULL) {
17+ luaL_addlstring(&buf, source, next - source); /* push prefix */
18+ luaL_addstring(&buf, "/?.lua;");
19+ luaL_addlstring(&buf, source, next - source); /* push prefix */
20+ luaL_addstring(&buf, "/?/init.lua;");
21+ source = next + 1; /* continue after the semicolon */
22+ }
23+ if (*source != '\0') {
24+ luaL_addstring(&buf, source);
25+ luaL_addstring(&buf, "/?.lua;");
26+ luaL_addstring(&buf, source);
27+ luaL_addstring(&buf, "/?/init.lua;");
28+ }
29+ }
30+
31+ /* Then add the local directory last */
32+ luaL_addstring(&buf, "./?.lua;" "./?/init.lua");
33+ luaL_pushresult(&buf);
34+ return lua_tostring(L, -1);
35+}
36+
37+
38+const char* guix_cpath (lua_State* L) {
39+ luaL_Buffer buf;
40+ luaL_buffinit(L, &buf);
41+
42+ const char* next;
43+ const char* source = getenv("GUIX_LUA_CPATH");
44+ if (source != NULL) {
45+ while ((next = strstr(source, ";")) != NULL) {
46+ luaL_addlstring(&buf, source, next - source); /* push prefix */
47+ luaL_addstring(&buf, "/?.so;");
48+ source = next + 1; /* continue after the semicolon */
49+ }
50+ if (*source != '\0') {
51+ luaL_addstring(&buf, source);
52+ luaL_addstring(&buf, "/?.so;");
53+ }
54+ }
55+
56+ /* Then add the local directory last */
57+ luaL_addstring(&buf, "./?.so");
58+
59+ luaL_pushresult(&buf);
60+ return lua_tostring(L, -1);
61+}
62+