MCPcopy Create free account
hub / github.com/DFHack/dfhack / setpath

Function setpath

depends/lua/src/loadlib.c:290–309  ·  view source on GitHub ↗

** Set a path */

Source from the content-addressed store, hash-verified

288** Set a path
289*/
290static void setpath (lua_State *L, const char *fieldname,
291 const char *envname,
292 const char *dft) {
293 const char *nver = lua_pushfstring(L, "%s%s", envname, LUA_VERSUFFIX);
294 const char *path = getenv(nver); /* use versioned name */
295 if (path == NULL) /* no environment variable? */
296 path = getenv(envname); /* try unversioned name */
297 if (path == NULL || noenv(L)) /* no environment variable? */
298 lua_pushstring(L, dft); /* use default */
299 else {
300 /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
301 path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
302 LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
303 luaL_gsub(L, path, AUXMARK, dft);
304 lua_remove(L, -2); /* remove result from 1st 'gsub' */
305 }
306 setprogdir(L);
307 lua_setfield(L, -3, fieldname); /* package[fieldname] = path value */
308 lua_pop(L, 1); /* pop versioned variable name */
309}
310
311/* }================================================================== */
312

Callers 1

luaopen_packageFunction · 0.85

Calls 6

lua_pushfstringFunction · 0.85
noenvFunction · 0.85
lua_pushstringFunction · 0.85
luaL_gsubFunction · 0.85
setprogdirFunction · 0.85
lua_setfieldFunction · 0.85

Tested by

no test coverage detected