aboutsummaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lua.c b/lua.c
index 0ff88454..3af5ce6a 100644
--- a/lua.c
+++ b/lua.c
@@ -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*/
214static int dolibrary (lua_State *L, char *globname) { 216static 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