diff options
-rw-r--r-- | loadlib.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.10 2004/11/18 19:53:49 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.11 2004/11/19 15:52:12 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 | * |
@@ -40,6 +40,7 @@ | |||
40 | 40 | ||
41 | #define ERR_OPEN 1 | 41 | #define ERR_OPEN 1 |
42 | #define ERR_FUNCTION 2 | 42 | #define ERR_FUNCTION 2 |
43 | #define ERR_ABSENT 3 | ||
43 | 44 | ||
44 | 45 | ||
45 | static void registerlib (lua_State *L, const void *lib); | 46 | static void registerlib (lua_State *L, const void *lib); |
@@ -176,13 +177,11 @@ static int loadlib (lua_State *L, const char *path, const char *init) { | |||
176 | 177 | ||
177 | #define freelib(lib) ((void)lib) | 178 | #define freelib(lib) ((void)lib) |
178 | 179 | ||
179 | static int loadlib(lua_State *L) | 180 | static int loadlib(lua_State *L, const char *path, const char *init) |
180 | { | 181 | { |
181 | registerlib(L, NULL); /* to avoid warnings */ | 182 | (void)path; (void)init; (void)®isterlib; /* to avoid warnings */ |
182 | lua_pushnil(L); | ||
183 | lua_pushliteral(L,"`loadlib' not supported"); | 183 | lua_pushliteral(L,"`loadlib' not supported"); |
184 | lua_pushliteral(L,"absent"); | 184 | return ERR_ABSENT; |
185 | return 3; | ||
186 | } | 185 | } |
187 | 186 | ||
188 | #endif | 187 | #endif |
@@ -215,7 +214,8 @@ static int gctm (lua_State *L) | |||
215 | } | 214 | } |
216 | 215 | ||
217 | 216 | ||
218 | static int loadlib1 (lua_State *L) { | 217 | static int ll_loadlib (lua_State *L) { |
218 | static const char *const errcodes[] = {NULL, "open", "init", "absent"}; | ||
219 | const char *path=luaL_checkstring(L,1); | 219 | const char *path=luaL_checkstring(L,1); |
220 | const char *init=luaL_checkstring(L,2); | 220 | const char *init=luaL_checkstring(L,2); |
221 | int res = loadlib(L,path,init); | 221 | int res = loadlib(L,path,init); |
@@ -224,7 +224,7 @@ static int loadlib1 (lua_State *L) { | |||
224 | else { /* error */ | 224 | else { /* error */ |
225 | lua_pushnil(L); | 225 | lua_pushnil(L); |
226 | lua_insert(L,-2); /* insert nil before error message */ | 226 | lua_insert(L,-2); /* insert nil before error message */ |
227 | lua_pushstring(L, (res==ERR_OPEN)?"open":"init"); | 227 | lua_pushstring(L, errcodes[res]); |
228 | return 3; | 228 | return 3; |
229 | } | 229 | } |
230 | } | 230 | } |
@@ -267,7 +267,7 @@ static const char *loadC (lua_State *L, const char *fname, const char *name) { | |||
267 | luaL_error(L, "global _CPATH must be a string"); | 267 | luaL_error(L, "global _CPATH must be a string"); |
268 | fname = luaL_searchpath(L, fname, path); | 268 | fname = luaL_searchpath(L, fname, path); |
269 | if (fname == NULL) return path; /* library not found in this path */ | 269 | if (fname == NULL) return path; /* library not found in this path */ |
270 | funcname = luaL_gsub(L, name, ".", ""); | 270 | funcname = luaL_gsub(L, name, ".", LUA_OFSEP); |
271 | funcname = lua_pushfstring(L, "%s%s", LUA_POF, funcname); | 271 | funcname = lua_pushfstring(L, "%s%s", LUA_POF, funcname); |
272 | if (loadlib(L, fname, funcname) != 0) | 272 | if (loadlib(L, fname, funcname) != 0) |
273 | luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); | 273 | luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); |
@@ -366,7 +366,7 @@ static int ll_module (lua_State *L) { | |||
366 | 366 | ||
367 | 367 | ||
368 | static const luaL_reg ll_funcs[] = { | 368 | static const luaL_reg ll_funcs[] = { |
369 | {"loadlib", loadlib1}, | 369 | {"loadlib", ll_loadlib}, |
370 | {"require", ll_require}, | 370 | {"require", ll_require}, |
371 | {"module", ll_module}, | 371 | {"module", ll_module}, |
372 | {NULL, NULL} | 372 | {NULL, NULL} |