aboutsummaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'loadlib.c')
-rw-r--r--loadlib.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/loadlib.c b/loadlib.c
index c9368be7..1bd3b3d9 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.102 2011/11/09 15:18:04 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.103 2011/11/09 19:11: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**
@@ -344,7 +344,8 @@ static const char *searchpath (lua_State *L, const char *name,
344 const char *path, 344 const char *path,
345 const char *sep, 345 const char *sep,
346 const char *dirsep) { 346 const char *dirsep) {
347 int nerr = 0; /* number of entries in possible error message */ 347 luaL_Buffer msg; /* to build error message */
348 luaL_buffinit(L, &msg);
348 if (*sep != '\0') /* non-empty separator? */ 349 if (*sep != '\0') /* non-empty separator? */
349 name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */ 350 name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
350 while ((path = pushnexttemplate(L, path)) != NULL) { 351 while ((path = pushnexttemplate(L, path)) != NULL) {
@@ -353,12 +354,11 @@ static const char *searchpath (lua_State *L, const char *name,
353 lua_remove(L, -2); /* remove path template */ 354 lua_remove(L, -2); /* remove path template */
354 if (readable(filename)) /* does file exist and is readable? */ 355 if (readable(filename)) /* does file exist and is readable? */
355 return filename; /* return that file name */ 356 return filename; /* return that file name */
356 luaL_checkstack(L, 1, "too many templates in path");
357 lua_pushfstring(L, "\n\tno file " LUA_QS, filename); 357 lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
358 lua_remove(L, -2); /* remove file name */ 358 lua_remove(L, -2); /* remove file name */
359 nerr++; 359 luaL_addvalue(&msg); /* concatenate error msg. entry */
360 } 360 }
361 lua_concat(L, nerr); /* create error message */ 361 luaL_pushresult(&msg); /* create error message */
362 return NULL; /* not found */ 362 return NULL; /* not found */
363} 363}
364 364
@@ -471,7 +471,8 @@ static int searcher_preload (lua_State *L) {
471 471
472static void findloader (lua_State *L, const char *name) { 472static void findloader (lua_State *L, const char *name) {
473 int i; 473 int i;
474 int nerr = 0; /* number of error messages on the stack */ 474 luaL_Buffer msg; /* to build error message */
475 luaL_buffinit(L, &msg);
475 lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */ 476 lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */
476 if (!lua_istable(L, 3)) 477 if (!lua_istable(L, 3))
477 luaL_error(L, LUA_QL("package.searchers") " must be a table"); 478 luaL_error(L, LUA_QL("package.searchers") " must be a table");
@@ -480,7 +481,7 @@ static void findloader (lua_State *L, const char *name) {
480 lua_rawgeti(L, 3, i); /* get a seacher */ 481 lua_rawgeti(L, 3, i); /* get a seacher */
481 if (lua_isnil(L, -1)) { /* no more searchers? */ 482 if (lua_isnil(L, -1)) { /* no more searchers? */
482 lua_pop(L, 1); /* remove nil */ 483 lua_pop(L, 1); /* remove nil */
483 lua_concat(L, nerr); /* concatenate all messages */ 484 luaL_pushresult(&msg); /* create error message */
484 luaL_error(L, "module " LUA_QS " not found:%s", 485 luaL_error(L, "module " LUA_QS " not found:%s",
485 name, lua_tostring(L, -1)); 486 name, lua_tostring(L, -1));
486 } 487 }
@@ -490,8 +491,7 @@ static void findloader (lua_State *L, const char *name) {
490 return; /* module loader found */ 491 return; /* module loader found */
491 else if (lua_isstring(L, -2)) { /* searcher returned error message? */ 492 else if (lua_isstring(L, -2)) { /* searcher returned error message? */
492 lua_pop(L, 1); /* remove extra return */ 493 lua_pop(L, 1); /* remove extra return */
493 nerr++; /* accumulate error message */ 494 luaL_addvalue(&msg); /* concatenate error message */
494 luaL_checkstack(L, 1, "too many searchers");
495 } 495 }
496 else 496 else
497 lua_pop(L, 2); /* remove both returns */ 497 lua_pop(L, 2); /* remove both returns */