From 3507c3380f5251a49c63f87c81c027b2664795c7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 3 Apr 2024 16:01:23 -0300 Subject: 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. --- loadlib.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'loadlib.c') diff --git a/loadlib.c b/loadlib.c index 4f8024c6..7b4bb16a 100644 --- a/loadlib.c +++ b/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 */ - } } } -- cgit v1.2.3-55-g6feb