Change in the prefix of messages from searchers
The initial "\n\t" to properly indent a searcher message is being added
by 'findloader' when building the error message, instead of being
included in the original message by each searcher itself.
diff --git a/loadlib.c b/loadlib.c
index 689767f..56167f6 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -458,13 +458,13 @@
/*
** Given a path such as ";blabla.so;blublu.so", pushes the string
**
-** no file 'blabla.so'
+** no file 'blabla.so'
** no file 'blublu.so'
*/
static void pusherrornotfound (lua_State *L, const char *path) {
luaL_Buffer b;
luaL_buffinit(L, &b);
- luaL_addstring(&b, "\n\tno file '");
+ luaL_addstring(&b, "no file '");
luaL_addgsub(&b, path, LUA_PATH_SEP, "'\n\tno file '");
luaL_addstring(&b, "'");
luaL_pushresult(&b);
@@ -591,7 +591,7 @@
if (stat != ERRFUNC)
return checkload(L, 0, filename); /* real error */
else { /* open function not found */
- lua_pushfstring(L, "\n\tno module '%s' in file '%s'", name, filename);
+ lua_pushfstring(L, "no module '%s' in file '%s'", name, filename);
return 1;
}
}
@@ -604,7 +604,7 @@
const char *name = luaL_checkstring(L, 1);
lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
if (lua_getfield(L, -1, name) == LUA_TNIL) { /* not found? */
- lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
+ lua_pushfstring(L, "no field package.preload['%s']", name);
return 1;
}
else {
@@ -623,8 +623,10 @@
luaL_buffinit(L, &msg);
/* iterate over available searchers to find a loader */
for (i = 1; ; i++) {
+ luaL_addstring(&msg, "\n\t"); /* error-message prefix */
if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */
lua_pop(L, 1); /* remove nil */
+ luaL_buffsub(&msg, 2); /* remove prefix */
luaL_pushresult(&msg); /* create error message */
luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
}
@@ -636,8 +638,10 @@
lua_pop(L, 1); /* remove extra return */
luaL_addvalue(&msg); /* concatenate error message */
}
- else
+ else { /* no error message */
lua_pop(L, 2); /* remove both returns */
+ luaL_buffsub(&msg, 2); /* remove prefix */
+ }
}
}
diff --git a/testes/attrib.lua b/testes/attrib.lua
index b1a4a19..76a447c 100644
--- a/testes/attrib.lua
+++ b/testes/attrib.lua
@@ -47,6 +47,29 @@
package.path = oldpath
end
+
+do print"testing 'require' message"
+ local oldpath = package.path
+ local oldcpath = package.cpath
+
+ package.path = "?.lua;?/?"
+ package.cpath = "?.so;?/init"
+
+ local st, msg = pcall(require, 'XXX')
+
+ local expected = [[module 'XXX' not found:
+ no field package.preload['XXX']
+ no file 'XXX.lua'
+ no file 'XXX/XXX'
+ no file 'XXX.so'
+ no file 'XXX/init']]
+
+ assert(msg == expected)
+
+ package.path = oldpath
+ package.cpath = oldcpath
+end
+
print('+')