diff options
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.25 2005/03/30 19:50:29 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.26 2005/04/13 17:24:20 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 | ** |
@@ -191,7 +191,7 @@ static void *ll_load (lua_State *L, const char *path) { | |||
191 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | 191 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { |
192 | NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); | 192 | NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); |
193 | if (nss == NULL) { | 193 | if (nss == NULL) { |
194 | lua_pushfstring(L, "symbol `%s' not found", sym); | 194 | lua_pushfstring(L, "symbol " LUA_SM " not found", sym); |
195 | return NULL; | 195 | return NULL; |
196 | } | 196 | } |
197 | return (lua_CFunction)NSAddressOfSymbol(nss); | 197 | return (lua_CFunction)NSAddressOfSymbol(nss); |
@@ -213,9 +213,9 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | |||
213 | 213 | ||
214 | 214 | ||
215 | #if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux) | 215 | #if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux) |
216 | #define DLMSG "`loadlib' not enabled; check your Lua installation" | 216 | #define DLMSG "'loadlib' not enabled; check your Lua installation" |
217 | #else | 217 | #else |
218 | #define DLMSG "`loadlib' not supported" | 218 | #define DLMSG "'loadlib' not supported" |
219 | #endif | 219 | #endif |
220 | 220 | ||
221 | static void ll_unloadlib (void *lib) { | 221 | static void ll_unloadlib (void *lib) { |
@@ -327,11 +327,12 @@ static int loader_Lua (lua_State *L) { | |||
327 | path = lua_tostring(L, -1); | 327 | path = lua_tostring(L, -1); |
328 | } | 328 | } |
329 | if (path == NULL) | 329 | if (path == NULL) |
330 | luaL_error(L, "`package.path' must be a string"); | 330 | luaL_error(L, LUA_SM " must be a string", "package.path"); |
331 | fname = luaL_searchpath(L, fname, path); | 331 | fname = luaL_searchpath(L, fname, path); |
332 | if (fname == NULL) return 0; /* library not found in this path */ | 332 | if (fname == NULL) return 0; /* library not found in this path */ |
333 | if (luaL_loadfile(L, fname) != 0) | 333 | if (luaL_loadfile(L, fname) != 0) |
334 | luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1)); | 334 | luaL_error(L, "error loading package " LUA_SM " (%s)", |
335 | name, lua_tostring(L, -1)); | ||
335 | return 1; /* library loaded successfully */ | 336 | return 1; /* library loaded successfully */ |
336 | } | 337 | } |
337 | 338 | ||
@@ -344,13 +345,14 @@ static int loader_C (lua_State *L) { | |||
344 | lua_getfield(L, LUA_ENVIRONINDEX, "cpath"); | 345 | lua_getfield(L, LUA_ENVIRONINDEX, "cpath"); |
345 | path = lua_tostring(L, -1); | 346 | path = lua_tostring(L, -1); |
346 | if (path == NULL) | 347 | if (path == NULL) |
347 | luaL_error(L, "`package.cpath' must be a string"); | 348 | luaL_error(L, LUA_SM " must be a string", "package.cpath"); |
348 | fname = luaL_searchpath(L, fname, path); | 349 | fname = luaL_searchpath(L, fname, path); |
349 | if (fname == NULL) return 0; /* library not found in this path */ | 350 | if (fname == NULL) return 0; /* library not found in this path */ |
350 | funcname = luaL_gsub(L, name, ".", LUA_OFSEP); | 351 | funcname = luaL_gsub(L, name, ".", LUA_OFSEP); |
351 | funcname = lua_pushfstring(L, "%s%s", POF, funcname); | 352 | funcname = lua_pushfstring(L, "%s%s", POF, funcname); |
352 | if (ll_loadfunc(L, fname, funcname) != 1) | 353 | if (ll_loadfunc(L, fname, funcname) != 1) |
353 | luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -2)); | 354 | luaL_error(L, "error loading package " LUA_SM " (%s)", |
355 | name, lua_tostring(L, -2)); | ||
354 | return 1; /* library loaded successfully */ | 356 | return 1; /* library loaded successfully */ |
355 | } | 357 | } |
356 | 358 | ||
@@ -358,7 +360,7 @@ static int loader_C (lua_State *L) { | |||
358 | static int loader_preload (lua_State *L) { | 360 | static int loader_preload (lua_State *L) { |
359 | lua_getfield(L, LUA_ENVIRONINDEX, "preload"); | 361 | lua_getfield(L, LUA_ENVIRONINDEX, "preload"); |
360 | if (!lua_istable(L, -1)) | 362 | if (!lua_istable(L, -1)) |
361 | luaL_error(L, "`package.preload' must be a table"); | 363 | luaL_error(L, LUA_SM " must be a table", "package.preload"); |
362 | lua_getfield(L, -1, luaL_checkstring(L, 1)); | 364 | lua_getfield(L, -1, luaL_checkstring(L, 1)); |
363 | return 1; | 365 | return 1; |
364 | } | 366 | } |
@@ -378,11 +380,11 @@ static int ll_require (lua_State *L) { | |||
378 | /* iterate over available loaders */ | 380 | /* iterate over available loaders */ |
379 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); | 381 | lua_getfield(L, LUA_ENVIRONINDEX, "loaders"); |
380 | if (!lua_istable(L, -1)) | 382 | if (!lua_istable(L, -1)) |
381 | luaL_error(L, "`package.loaders' must be a table"); | 383 | luaL_error(L, LUA_SM " must be a table", "package.loaders"); |
382 | for (i=1;; i++) { | 384 | for (i=1;; i++) { |
383 | lua_rawgeti(L, -1, i); /* get a loader */ | 385 | lua_rawgeti(L, -1, i); /* get a loader */ |
384 | if (lua_isnil(L, -1)) | 386 | if (lua_isnil(L, -1)) |
385 | return luaL_error(L, "package `%s' not found", name); | 387 | return luaL_error(L, "package " LUA_SM " not found", name); |
386 | lua_pushstring(L, name); | 388 | lua_pushstring(L, name); |
387 | lua_call(L, 1, 1); /* call it */ | 389 | lua_call(L, 1, 1); /* call it */ |
388 | if (lua_isnil(L, -1)) lua_pop(L, 1); | 390 | if (lua_isnil(L, -1)) lua_pop(L, 1); |
@@ -421,7 +423,7 @@ static int ll_module (lua_State *L) { | |||
421 | luaL_setfield(L, LUA_GLOBALSINDEX, modname); | 423 | luaL_setfield(L, LUA_GLOBALSINDEX, modname); |
422 | } | 424 | } |
423 | else if (!lua_istable(L, -1)) | 425 | else if (!lua_istable(L, -1)) |
424 | return luaL_error(L, "name conflict for module `%s'", modname); | 426 | return luaL_error(L, "name conflict for module " LUA_SM, modname); |
425 | /* check whether table already has a _NAME field */ | 427 | /* check whether table already has a _NAME field */ |
426 | lua_getfield(L, -1, "_NAME"); | 428 | lua_getfield(L, -1, "_NAME"); |
427 | if (!lua_isnil(L, -1)) /* is table an initialized module? */ | 429 | if (!lua_isnil(L, -1)) /* is table an initialized module? */ |