diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 13:46:38 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 13:46:38 -0300 |
commit | 09f3c2372f5dbeaec9f50614a26c1b5761726a88 (patch) | |
tree | 83469dd02dba1c59ead0eb0cba3a35bd39ec899d /lua.c | |
parent | c197885cb00b85251c35cffdc4057efaee2d7a88 (diff) | |
download | lua-09f3c2372f5dbeaec9f50614a26c1b5761726a88.tar.gz lua-09f3c2372f5dbeaec9f50614a26c1b5761726a88.tar.bz2 lua-09f3c2372f5dbeaec9f50614a26c1b5761726a88.zip |
Option '-l' discards version sufix from file name
Like 'require', the command-line option '-l' discards an optional
version suffix (everything after an hyphen) from a file name when
creating the module name.
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 12 |
1 files changed, 10 insertions, 2 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 | ||