| 595 | |
| 596 | |
| 597 | static int ll_require (lua_State *L) { |
| 598 | const char *name = luaL_checkstring(L, 1); |
| 599 | lua_settop(L, 1); /* LOADED table will be at index 2 */ |
| 600 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); |
| 601 | lua_getfield(L, 2, name); /* LOADED[name] */ |
| 602 | if (lua_toboolean(L, -1)) /* is it there? */ |
| 603 | return 1; /* package is already loaded */ |
| 604 | /* else must load package */ |
| 605 | lua_pop(L, 1); /* remove 'getfield' result */ |
| 606 | findloader(L, name); |
| 607 | lua_pushstring(L, name); /* pass name as argument to module loader */ |
| 608 | lua_insert(L, -2); /* name is 1st argument (before search data) */ |
| 609 | lua_call(L, 2, 1); /* run loader to load module */ |
| 610 | if (!lua_isnil(L, -1)) /* non-nil return? */ |
| 611 | lua_setfield(L, 2, name); /* LOADED[name] = returned value */ |
| 612 | if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */ |
| 613 | lua_pushboolean(L, 1); /* use true as result */ |
| 614 | lua_pushvalue(L, -1); /* extra copy to be returned */ |
| 615 | lua_setfield(L, 2, name); /* LOADED[name] = true */ |
| 616 | } |
| 617 | return 1; |
| 618 | } |
| 619 | |
| 620 | /* }====================================================== */ |
| 621 |
nothing calls this directly
no test coverage detected