Small simplification in 'findloader'
Instead of allways adding a prefix for the next message, and then
removing it if there is no message, add the prefix after each message.
diff --git a/loadlib.c b/loadlib.c
index 4f8024c..7b4bb16 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -621,12 +621,12 @@
!= LUA_TTABLE))
luaL_error(L, "'package.searchers' must be a table");
luaL_buffinit(L, &msg);
+ luaL_addstring(&msg, "\n\t"); /* error-message prefix for first message */
/* iterate over available searchers to find a loader */
for (i = 1; ; i++) {
- luaL_addstring(&msg, "\n\t"); /* error-message prefix */
if (l_unlikely(lua_rawgeti(L, 3, i) == LUA_TNIL)) { /* no more searchers? */
lua_pop(L, 1); /* remove nil */
- luaL_buffsub(&msg, 2); /* remove prefix */
+ luaL_buffsub(&msg, 2); /* remove last prefix */
luaL_pushresult(&msg); /* create error message */
luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
}
@@ -637,11 +637,10 @@
else if (lua_isstring(L, -2)) { /* searcher returned error message? */
lua_pop(L, 1); /* remove extra return */
luaL_addvalue(&msg); /* concatenate error message */
+ luaL_addstring(&msg, "\n\t"); /* prefix for next message */
}
- else { /* no error message */
+ else /* no error message */
lua_pop(L, 2); /* remove both returns */
- luaL_buffsub(&msg, 2); /* remove prefix */
- }
}
}