diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-06-22 11:41:48 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-06-22 11:41:48 -0300 |
| commit | ab6a94952215b1f66436d8eeebded1dad9fa5409 (patch) | |
| tree | ba66254537defc76602ce351d962b899ddfe1b29 /lua.c | |
| parent | 86e8039a72646cd9192fd08a6f1771c90b872ff6 (diff) | |
| parent | ea39042e13645f63713425c05cc9ee4cfdcf0a40 (diff) | |
| download | lua-ab6a94952215b1f66436d8eeebded1dad9fa5409.tar.gz lua-ab6a94952215b1f66436d8eeebded1dad9fa5409.tar.bz2 lua-ab6a94952215b1f66436d8eeebded1dad9fa5409.zip | |
Merge branch 'master' into nextversion
Diffstat (limited to 'lua.c')
| -rw-r--r-- | lua.c | 14 |
1 files changed, 11 insertions, 3 deletions
| @@ -210,12 +210,17 @@ static int dostring (lua_State *L, const char *s, const char *name) { | |||
| 210 | 210 | ||
| 211 | /* | 211 | /* |
| 212 | ** Receives 'globname[=modname]' and runs 'globname = require(modname)'. | 212 | ** Receives 'globname[=modname]' and runs 'globname = require(modname)'. |
| 213 | ** If there is no explicit modname and globname contains a '-', cut | ||
| 214 | ** the sufix after '-' (the "version") to make the global name. | ||
| 213 | */ | 215 | */ |
| 214 | static int dolibrary (lua_State *L, char *globname) { | 216 | static int dolibrary (lua_State *L, char *globname) { |
| 215 | int status; | 217 | int status; |
| 218 | char *suffix = NULL; | ||
| 216 | char *modname = strchr(globname, '='); | 219 | char *modname = strchr(globname, '='); |
| 217 | if (modname == NULL) /* no explicit name? */ | 220 | if (modname == NULL) { /* no explicit name? */ |
| 218 | modname = globname; /* module name is equal to global name */ | 221 | modname = globname; /* module name is equal to global name */ |
| 222 | suffix = strchr(modname, *LUA_IGMARK); /* look for a suffix mark */ | ||
| 223 | } | ||
| 219 | else { | 224 | else { |
| 220 | *modname = '\0'; /* global name ends here */ | 225 | *modname = '\0'; /* global name ends here */ |
| 221 | modname++; /* module name starts after the '=' */ | 226 | modname++; /* module name starts after the '=' */ |
| @@ -223,8 +228,11 @@ static int dolibrary (lua_State *L, char *globname) { | |||
| 223 | lua_getglobal(L, "require"); | 228 | lua_getglobal(L, "require"); |
| 224 | lua_pushstring(L, modname); | 229 | lua_pushstring(L, modname); |
| 225 | status = docall(L, 1, 1); /* call 'require(modname)' */ | 230 | status = docall(L, 1, 1); /* call 'require(modname)' */ |
| 226 | if (status == LUA_OK) | 231 | if (status == LUA_OK) { |
| 232 | if (suffix != NULL) /* is there a suffix mark? */ | ||
| 233 | *suffix = '\0'; /* remove sufix from global name */ | ||
| 227 | lua_setglobal(L, globname); /* globname = require(modname) */ | 234 | lua_setglobal(L, globname); /* globname = require(modname) */ |
| 235 | } | ||
| 228 | return report(L, status); | 236 | return report(L, status); |
| 229 | } | 237 | } |
| 230 | 238 | ||
| @@ -670,7 +678,7 @@ int main (int argc, char **argv) { | |||
| 670 | l_message(argv[0], "cannot create state: not enough memory"); | 678 | l_message(argv[0], "cannot create state: not enough memory"); |
| 671 | return EXIT_FAILURE; | 679 | return EXIT_FAILURE; |
| 672 | } | 680 | } |
| 673 | lua_gc(L, LUA_GCSTOP); /* stop GC while buidling state */ | 681 | lua_gc(L, LUA_GCSTOP); /* stop GC while building state */ |
| 674 | lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */ | 682 | lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */ |
| 675 | lua_pushinteger(L, argc); /* 1st argument */ | 683 | lua_pushinteger(L, argc); /* 1st argument */ |
| 676 | lua_pushlightuserdata(L, argv); /* 2nd argument */ | 684 | lua_pushlightuserdata(L, argv); /* 2nd argument */ |
