MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / setpath

Function setpath

third-party/lua-5.5.0/src/loadlib.c:274–304  ·  view source on GitHub ↗

** Set a path. (If using the default path, assume it is a string ** literal in C and create it as an external string.) */

Source from the content-addressed store, hash-verified

272** literal in C and create it as an external string.)
273*/
274static void setpath (lua_State *L, const char *fieldname,
275 const char *envname,
276 const char *dft) {
277 const char *dftmark;
278 const char *nver = lua_pushfstring(L, "%s%s", envname, LUA_VERSUFFIX);
279 const char *path = getenv(nver); /* try versioned name */
280 if (path == NULL) /* no versioned environment variable? */
281 path = getenv(envname); /* try unversioned name */
282 if (path == NULL || noenv(L)) /* no environment variable? */
283 lua_pushexternalstring(L, dft, strlen(dft), NULL, NULL); /* use default */
284 else if ((dftmark = strstr(path, LUA_PATH_SEP LUA_PATH_SEP)) == NULL)
285 lua_pushstring(L, path); /* nothing to change */
286 else { /* path contains a ";;": insert default path in its place */
287 size_t len = strlen(path);
288 luaL_Buffer b;
289 luaL_buffinit(L, &b);
290 if (path < dftmark) { /* is there a prefix before ';;'? */
291 luaL_addlstring(&b, path, ct_diff2sz(dftmark - path)); /* add it */
292 luaL_addchar(&b, *LUA_PATH_SEP);
293 }
294 luaL_addstring(&b, dft); /* add default */
295 if (dftmark < path + len - 2) { /* is there a suffix after ';;'? */
296 luaL_addchar(&b, *LUA_PATH_SEP);
297 luaL_addlstring(&b, dftmark + 2, ct_diff2sz((path + len - 2) - dftmark));
298 }
299 luaL_pushresult(&b);
300 }
301 setprogdir(L);
302 lua_setfield(L, -3, fieldname); /* package[fieldname] = path value */
303 lua_pop(L, 1); /* pop versioned variable name ('nver') */
304}
305
306/* }================================================================== */
307

Callers 1

luaopen_packageFunction · 0.70

Calls 10

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

Tested by

no test coverage detected