Переглянути джерело

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.
Roberto Ierusalimschy 1 рік тому
батько
коміт
3507c3380f
1 змінених файлів з 4 додано та 5 видалено
  1. 4 5
      loadlib.c

+ 4 - 5
loadlib.c

@@ -621,12 +621,12 @@ static void findloader (lua_State *L, const char *name) {
                  != 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 @@ static void findloader (lua_State *L, const char *name) {
     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 */
-    }
   }
 }