MCPcopy Create free account
hub / github.com/Tencent/xLua / setpath

Function setpath

WebGLPlugins/loadlib.c:290–313  ·  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#if defined(WINAPI_FAMILY_PARTITION)
295 const char *path = NULL;
296#else
297 const char *path = getenv(nver); /* use versioned name */
298 if (path == NULL) /* no environment variable? */
299 path = getenv(envname); /* try unversioned name */
300#endif
301 if (path == NULL || noenv(L)) /* no environment variable? */
302 lua_pushstring(L, dft); /* use default */
303 else {
304 /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
305 path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
306 LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
307 luaL_gsub(L, path, AUXMARK, dft);
308 lua_remove(L, -2); /* remove result from 1st 'gsub' */
309 }
310 setprogdir(L);
311 lua_setfield(L, -3, fieldname); /* package[fieldname] = path value */
312 lua_pop(L, 1); /* pop versioned variable name */
313}
314
315/* }================================================================== */
316

Callers 1

luaopen_packageFunction · 0.85

Calls 7

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

Tested by

no test coverage detected