~seanlynch/mooa

5c03ec5af838f306b6a4eeba1e89eed8f6f3ace2 — Sean Lynch 8 years ago c5db0f2 master
Save loaded packages for emulating require
1 files changed, 6 insertions(+), 2 deletions(-)

M mooa.c
M mooa.c => mooa.c +6 -2
@@ 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);