MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / setpath

Function setpath

extlibs/lua/src/loadlib.c:290–320  ·  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 *dftmark;
294 const char *nver = lua_pushfstring(L, "%s%s", envname, LUA_VERSUFFIX);
295 const char *path = getenv(nver); /* try versioned name */
296 if (path == NULL) /* no versioned environment variable? */
297 path = getenv(envname); /* try unversioned name */
298 if (path == NULL || noenv(L)) /* no environment variable? */
299 lua_pushstring(L, dft); /* use default */
300 else if ((dftmark = strstr(path, LUA_PATH_SEP LUA_PATH_SEP)) == NULL)
301 lua_pushstring(L, path); /* nothing to change */
302 else { /* path contains a ";;": insert default path in its place */
303 size_t len = strlen(path);
304 luaL_Buffer b;
305 luaL_buffinit(L, &b);
306 if (path < dftmark) { /* is there a prefix before ';;'? */
307 luaL_addlstring(&b, path, dftmark - path); /* add it */
308 luaL_addchar(&b, *LUA_PATH_SEP);
309 }
310 luaL_addstring(&b, dft); /* add default */
311 if (dftmark < path + len - 2) { /* is there a suffix after ';;'? */
312 luaL_addchar(&b, *LUA_PATH_SEP);
313 luaL_addlstring(&b, dftmark + 2, (path + len - 2) - dftmark);
314 }
315 luaL_pushresult(&b);
316 }
317 setprogdir(L);
318 lua_setfield(L, -3, fieldname); /* package[fieldname] = path value */
319 lua_pop(L, 1); /* pop versioned variable name ('nver') */
320}
321
322/* }================================================================== */
323

Callers 1

luaopen_packageFunction · 0.85

Calls 9

lua_pushfstringFunction · 0.85
noenvFunction · 0.85
lua_pushstringFunction · 0.85
luaL_addstringFunction · 0.85
setprogdirFunction · 0.85
lua_setfieldFunction · 0.85
luaL_buffinitFunction · 0.70
luaL_addlstringFunction · 0.70
luaL_pushresultFunction · 0.70

Tested by

no test coverage detected