diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-04-03 16:01:23 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-04-03 16:01:23 -0300 |
| commit | 3507c3380f5251a49c63f87c81c027b2664795c7 (patch) | |
| tree | 9930819afb2c1d5809086f5b362fd2deea444649 | |
| parent | 88a50ffa715483e7187c0d7d6caaf708ebacf756 (diff) | |
| download | lua-3507c3380f5251a49c63f87c81c027b2664795c7.tar.gz lua-3507c3380f5251a49c63f87c81c027b2664795c7.tar.bz2 lua-3507c3380f5251a49c63f87c81c027b2664795c7.zip | |
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.
| -rw-r--r-- | loadlib.c | 9 |
1 files changed, 4 insertions, 5 deletions
| @@ -621,12 +621,12 @@ static void findloader (lua_State *L, const char *name) { | |||
| 621 | != LUA_TTABLE)) | 621 | != LUA_TTABLE)) |
| 622 | luaL_error(L, "'package.searchers' must be a table"); | 622 | luaL_error(L, "'package.searchers' must be a table"); |
| 623 | luaL_buffinit(L, &msg); | 623 | luaL_buffinit(L, &msg); |
| 624 | luaL_addstring(&msg, "\n\t"); /* error-message prefix for first message */ | ||
| 624 | /* iterate over available searchers to find a loader */ | 625 | /* iterate over available searchers to find a loader */ |
| 625 | for (i = 1; ; i++) { | 626 | for (i = 1; ; i++) { |
| 626 | luaL_addstring(&msg, "\n\t"); /* error-message prefix */ | ||
| 627 | if (l_unlikely(lua_rawgeti(L, 3, i) == LUA_TNIL)) { /* no more searchers? */ | 627 | if (l_unlikely(lua_rawgeti(L, 3, i) == LUA_TNIL)) { /* no more searchers? */ |
| 628 | lua_pop(L, 1); /* remove nil */ | 628 | lua_pop(L, 1); /* remove nil */ |
| 629 | luaL_buffsub(&msg, 2); /* remove prefix */ | 629 | luaL_buffsub(&msg, 2); /* remove last prefix */ |
| 630 | luaL_pushresult(&msg); /* create error message */ | 630 | luaL_pushresult(&msg); /* create error message */ |
| 631 | luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1)); | 631 | luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1)); |
| 632 | } | 632 | } |
| @@ -637,11 +637,10 @@ static void findloader (lua_State *L, const char *name) { | |||
| 637 | else if (lua_isstring(L, -2)) { /* searcher returned error message? */ | 637 | else if (lua_isstring(L, -2)) { /* searcher returned error message? */ |
| 638 | lua_pop(L, 1); /* remove extra return */ | 638 | lua_pop(L, 1); /* remove extra return */ |
| 639 | luaL_addvalue(&msg); /* concatenate error message */ | 639 | luaL_addvalue(&msg); /* concatenate error message */ |
| 640 | luaL_addstring(&msg, "\n\t"); /* prefix for next message */ | ||
| 640 | } | 641 | } |
| 641 | else { /* no error message */ | 642 | else /* no error message */ |
| 642 | lua_pop(L, 2); /* remove both returns */ | 643 | lua_pop(L, 2); /* remove both returns */ |
| 643 | luaL_buffsub(&msg, 2); /* remove prefix */ | ||
| 644 | } | ||
| 645 | } | 644 | } |
| 646 | } | 645 | } |
| 647 | 646 | ||
