** Receives 'globname[=modname]' and runs 'globname = require(modname)'. ** If there is no explicit modname and globname contains a '-', cut ** the suffix after '-' (the "version") to make the global name. */
| 215 | ** the suffix after '-' (the "version") to make the global name. |
| 216 | */ |
| 217 | static int dolibrary (lua_State *L, char *globname) { |
| 218 | int status; |
| 219 | char *suffix = NULL; |
| 220 | char *modname = strchr(globname, '='); |
| 221 | if (modname == NULL) { /* no explicit name? */ |
| 222 | modname = globname; /* module name is equal to global name */ |
| 223 | suffix = strchr(modname, *LUA_IGMARK); /* look for a suffix mark */ |
| 224 | } |
| 225 | else { |
| 226 | *modname = '\0'; /* global name ends here */ |
| 227 | modname++; /* module name starts after the '=' */ |
| 228 | } |
| 229 | lua_getglobal(L, "require"); |
| 230 | lua_pushstring(L, modname); |
| 231 | status = docall(L, 1, 1); /* call 'require(modname)' */ |
| 232 | if (status == LUA_OK) { |
| 233 | if (suffix != NULL) /* is there a suffix mark? */ |
| 234 | *suffix = '\0'; /* remove suffix from global name */ |
| 235 | lua_setglobal(L, globname); /* globname = require(modname) */ |
| 236 | } |
| 237 | return report(L, status); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | /* |
no test coverage detected