lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 3507c3380f5251a49c63f87c81c027b2664795c7
parent 88a50ffa715483e7187c0d7d6caaf708ebacf756
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Wed,  3 Apr 2024 16:00:56 -0300

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.

Diffstat:
Mloadlib.c | 9++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git 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 */ - } } }