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

Function setprogdir

third-party/lua-5.5.0/src/loadlib.c:153–165  ·  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

151** of LUA_EXEC_DIR with the executable's path.
152*/
153static void setprogdir (lua_State *L) {
154 char buff[MAX_PATH + 1];
155 char *lb;
156 DWORD nsize = sizeof(buff)/sizeof(char);
157 DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */
158 if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
159 luaL_error(L, "unable to get ModuleFileName");
160 else {
161 *lb = '\0'; /* cut name on the last '\\' to get the path */
162 luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);
163 lua_remove(L, -2); /* remove original string */
164 }
165}
166
167
168

Callers 1

setpathFunction · 0.70

Calls 3

luaL_errorFunction · 0.70
luaL_gsubFunction · 0.70
lua_removeFunction · 0.50

Tested by

no test coverage detected