mooa

Lua + lubev + sandboxing
git clone https://code.literati.org/mooa.git
Log | Files | Refs | README | LICENSE

commit 5c03ec5af838f306b6a4eeba1e89eed8f6f3ace2
parent c5db0f2aa0f97b1118876bd46582b9ad68b7bf54
Author: Sean Lynch <seanl@literati.org>
Date:   Tue, 23 Feb 2016 22:54:05 -0800

Save loaded packages for emulating require

Diffstat:
Mmooa.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mooa.c b/mooa.c @@ -86,7 +86,7 @@ static void mooa_state_makesafe(lua_State *L) { } lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS); - lua_pop(L, 1); + lua_setfield(L, LUA_REGISTRYINDEX, "mooa_orig_globals"); } @@ -128,9 +128,12 @@ static int mooa_panic(lua_State *L) { static void mooa_require(lua_State *L, const char *module) { + lua_getfield(L, LUA_REGISTRYINDEX, "mooa_packages"); lua_getglobal(L, "require"); lua_pushstring(L, module); - lua_call(L, 1, 0); + lua_call(L, 1, 1); + /* For our emulated require */ + lua_setfield(L, -1, module); } @@ -146,6 +149,7 @@ static lua_State *mooa_state_new(void) { mooa_task_init_state(L); lua_newtable(L); + /* Store loaded packages for our emulated require. */ lua_setfield(L, LUA_REGISTRYINDEX, "mooa_packages"); luaL_requiref(L, "base", luaopen_base, 0);