MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / setprogdir

Function setprogdir

3rd/lua-5.4.3/src/loadlib.c:177–189  ·  view source on GitHub ↗

** Replace in the path (on the top of the stack) any occurrence ** of LUA_EXEC_DIR with the executable's path. */

Source from the content-addressed store, hash-verified

175** of LUA_EXEC_DIR with the executable's path.
176*/
177static void setprogdir (lua_State *L) {
178 char buff[MAX_PATH + 1];
179 char *lb;
180 DWORD nsize = sizeof(buff)/sizeof(char);
181 DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */
182 if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
183 luaL_error(L, "unable to get ModuleFileName");
184 else {
185 *lb = '\0'; /* cut name on the last '\\' to get the path */
186 luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);
187 lua_remove(L, -2); /* remove original string */
188 }
189}
190
191
192

Callers 1

setpathFunction · 0.85

Calls 2

luaL_errorFunction · 0.85
luaL_gsubFunction · 0.85

Tested by

no test coverage detected