** Replace in the path (on the top of the stack) any occurrence ** of LUA_EXEC_DIR with the executable's path. */
| 166 | ** of LUA_EXEC_DIR with the executable's path. |
| 167 | */ |
| 168 | static void setprogdir (lua_State *L) { |
| 169 | char buff[MAX_PATH + 1]; |
| 170 | char *lb; |
| 171 | DWORD nsize = sizeof(buff)/sizeof(char); |
| 172 | DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */ |
| 173 | if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) |
| 174 | luaL_error(L, "unable to get ModuleFileName"); |
| 175 | else { |
| 176 | *lb = '\0'; /* cut name on the last '\\' to get the path */ |
| 177 | luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff); |
| 178 | lua_remove(L, -2); /* remove original string */ |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | |
| 183 |
no test coverage detected