diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-10-24 10:49:44 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-10-24 10:49:44 -0300 |
| commit | ba9cd0d25a022cf61c0b747d8e26f9ba81201112 (patch) | |
| tree | a07ae4d2d273ab438d3c7db9b61f157af5fc17cd | |
| parent | b93f3b00bb76cddbf600eb399849fb0c01d197fd (diff) | |
| download | lua-ba9cd0d25a022cf61c0b747d8e26f9ba81201112.tar.gz lua-ba9cd0d25a022cf61c0b747d8e26f9ba81201112.tar.bz2 lua-ba9cd0d25a022cf61c0b747d8e26f9ba81201112.zip | |
Change in the prefix of messages from searchers
The initial "\n\t" to properly indent a searcher message is being added
by 'findloader' when building the error message, instead of being
included in the original message by each searcher itself.
| -rw-r--r-- | loadlib.c | 14 | ||||
| -rw-r--r-- | testes/attrib.lua | 23 |
2 files changed, 32 insertions, 5 deletions
| @@ -458,13 +458,13 @@ static const char *getnextfilename (char **path, char *end) { | |||
| 458 | /* | 458 | /* |
| 459 | ** Given a path such as ";blabla.so;blublu.so", pushes the string | 459 | ** Given a path such as ";blabla.so;blublu.so", pushes the string |
| 460 | ** | 460 | ** |
| 461 | ** no file 'blabla.so' | 461 | ** no file 'blabla.so' |
| 462 | ** no file 'blublu.so' | 462 | ** no file 'blublu.so' |
| 463 | */ | 463 | */ |
| 464 | static void pusherrornotfound (lua_State *L, const char *path) { | 464 | static void pusherrornotfound (lua_State *L, const char *path) { |
| 465 | luaL_Buffer b; | 465 | luaL_Buffer b; |
| 466 | luaL_buffinit(L, &b); | 466 | luaL_buffinit(L, &b); |
| 467 | luaL_addstring(&b, "\n\tno file '"); | 467 | luaL_addstring(&b, "no file '"); |
| 468 | luaL_addgsub(&b, path, LUA_PATH_SEP, "'\n\tno file '"); | 468 | luaL_addgsub(&b, path, LUA_PATH_SEP, "'\n\tno file '"); |
| 469 | luaL_addstring(&b, "'"); | 469 | luaL_addstring(&b, "'"); |
| 470 | luaL_pushresult(&b); | 470 | luaL_pushresult(&b); |
| @@ -591,7 +591,7 @@ static int searcher_Croot (lua_State *L) { | |||
| 591 | if (stat != ERRFUNC) | 591 | if (stat != ERRFUNC) |
| 592 | return checkload(L, 0, filename); /* real error */ | 592 | return checkload(L, 0, filename); /* real error */ |
| 593 | else { /* open function not found */ | 593 | else { /* open function not found */ |
| 594 | lua_pushfstring(L, "\n\tno module '%s' in file '%s'", name, filename); | 594 | lua_pushfstring(L, "no module '%s' in file '%s'", name, filename); |
| 595 | return 1; | 595 | return 1; |
| 596 | } | 596 | } |
| 597 | } | 597 | } |
| @@ -604,7 +604,7 @@ static int searcher_preload (lua_State *L) { | |||
| 604 | const char *name = luaL_checkstring(L, 1); | 604 | const char *name = luaL_checkstring(L, 1); |
| 605 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); | 605 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); |
| 606 | if (lua_getfield(L, -1, name) == LUA_TNIL) { /* not found? */ | 606 | if (lua_getfield(L, -1, name) == LUA_TNIL) { /* not found? */ |
| 607 | lua_pushfstring(L, "\n\tno field package.preload['%s']", name); | 607 | lua_pushfstring(L, "no field package.preload['%s']", name); |
| 608 | return 1; | 608 | return 1; |
| 609 | } | 609 | } |
| 610 | else { | 610 | else { |
| @@ -623,8 +623,10 @@ static void findloader (lua_State *L, const char *name) { | |||
| 623 | luaL_buffinit(L, &msg); | 623 | luaL_buffinit(L, &msg); |
| 624 | /* iterate over available searchers to find a loader */ | 624 | /* iterate over available searchers to find a loader */ |
| 625 | for (i = 1; ; i++) { | 625 | for (i = 1; ; i++) { |
| 626 | luaL_addstring(&msg, "\n\t"); /* error-message prefix */ | ||
| 626 | if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */ | 627 | if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */ |
| 627 | lua_pop(L, 1); /* remove nil */ | 628 | lua_pop(L, 1); /* remove nil */ |
| 629 | luaL_buffsub(&msg, 2); /* remove prefix */ | ||
| 628 | luaL_pushresult(&msg); /* create error message */ | 630 | luaL_pushresult(&msg); /* create error message */ |
| 629 | 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)); |
| 630 | } | 632 | } |
| @@ -636,8 +638,10 @@ static void findloader (lua_State *L, const char *name) { | |||
| 636 | lua_pop(L, 1); /* remove extra return */ | 638 | lua_pop(L, 1); /* remove extra return */ |
| 637 | luaL_addvalue(&msg); /* concatenate error message */ | 639 | luaL_addvalue(&msg); /* concatenate error message */ |
| 638 | } | 640 | } |
| 639 | else | 641 | else { /* no error message */ |
| 640 | lua_pop(L, 2); /* remove both returns */ | 642 | lua_pop(L, 2); /* remove both returns */ |
| 643 | luaL_buffsub(&msg, 2); /* remove prefix */ | ||
| 644 | } | ||
| 641 | } | 645 | } |
| 642 | } | 646 | } |
| 643 | 647 | ||
diff --git a/testes/attrib.lua b/testes/attrib.lua index b1a4a199..76a447c8 100644 --- a/testes/attrib.lua +++ b/testes/attrib.lua | |||
| @@ -47,6 +47,29 @@ do | |||
| 47 | package.path = oldpath | 47 | package.path = oldpath |
| 48 | end | 48 | end |
| 49 | 49 | ||
| 50 | |||
| 51 | do print"testing 'require' message" | ||
| 52 | local oldpath = package.path | ||
| 53 | local oldcpath = package.cpath | ||
| 54 | |||
| 55 | package.path = "?.lua;?/?" | ||
| 56 | package.cpath = "?.so;?/init" | ||
| 57 | |||
| 58 | local st, msg = pcall(require, 'XXX') | ||
| 59 | |||
| 60 | local expected = [[module 'XXX' not found: | ||
| 61 | no field package.preload['XXX'] | ||
| 62 | no file 'XXX.lua' | ||
| 63 | no file 'XXX/XXX' | ||
| 64 | no file 'XXX.so' | ||
| 65 | no file 'XXX/init']] | ||
| 66 | |||
| 67 | assert(msg == expected) | ||
| 68 | |||
| 69 | package.path = oldpath | ||
| 70 | package.cpath = oldcpath | ||
| 71 | end | ||
| 72 | |||
| 50 | print('+') | 73 | print('+') |
| 51 | 74 | ||
| 52 | 75 | ||
