diff options
| -rw-r--r-- | loadlib.c | 8 |
1 files changed, 4 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.42 2005/08/26 17:36:32 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.43 2005/08/31 23:17:29 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -93,18 +93,18 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | |||
| 93 | */ | 93 | */ |
| 94 | 94 | ||
| 95 | #include <windows.h> | 95 | #include <windows.h> |
| 96 | #include "Shlwapi.h" | ||
| 97 | 96 | ||
| 98 | 97 | ||
| 99 | #undef setprogdir | 98 | #undef setprogdir |
| 100 | 99 | ||
| 101 | void setprogdir (lua_State *L) { | 100 | void setprogdir (lua_State *L) { |
| 102 | char buff[MAX_PATH + 1]; | 101 | char buff[MAX_PATH + 1]; |
| 102 | char *lb; | ||
| 103 | DWORD nsize = sizeof(buff)/sizeof(char); | 103 | DWORD nsize = sizeof(buff)/sizeof(char); |
| 104 | DWORD n = GetModuleFileName(NULL, buff, nsize); | 104 | DWORD n = GetModuleFileName(NULL, buff, nsize); |
| 105 | if (n == 0 || n == nsize) | 105 | if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) |
| 106 | luaL_error(L, "unable to get ModuleFileName"); | 106 | luaL_error(L, "unable to get ModuleFileName"); |
| 107 | PathRemoveFileSpec(buff); | 107 | *lb = '\0'; |
| 108 | luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); | 108 | luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); |
| 109 | lua_remove(L, -2); /* remove original string */ | 109 | lua_remove(L, -2); /* remove original string */ |
| 110 | } | 110 | } |
