summaryrefslogtreecommitdiff
path: root/src/lib/elua/elua.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-04-09 16:12:15 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:19 +0100
commit329fae97b0a1190b4a5c9349fb9a9aebbeb4f6c7 (patch)
tree8ee9e6053eb4a4d1a31ab6c48fb2ef11ff3206de /src/lib/elua/elua.c
parentad999df598680c43c492d5db776a6eeb50e45ec3 (diff)
elua lib: manage bound modules within Elua_State
Diffstat (limited to 'src/lib/elua/elua.c')
-rw-r--r--src/lib/elua/elua.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index f14dc2997c..3ab2448427 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -81,7 +81,18 @@ EAPI void
81elua_state_free(Elua_State *es) 81elua_state_free(Elua_State *es)
82{ 82{
83 if (!es) return; 83 if (!es) return;
84 if (es->luastate) lua_close(es->luastate); 84 if (es->luastate)
85 {
86 void *data;
87 EINA_LIST_FREE(es->cmods, data)
88 {
89 lua_rawgeti(es->luastate, LUA_REGISTRYINDEX, (size_t)data);
90 lua_call(es->luastate, 0, 0);
91 }
92 lua_close(es->luastate);
93 }
94 else if (es->cmods)
95 eina_list_free(es->cmods);
85 eina_stringshare_del(es->coredir); 96 eina_stringshare_del(es->coredir);
86 eina_stringshare_del(es->moddir); 97 eina_stringshare_del(es->moddir);
87 eina_stringshare_del(es->appsdir); 98 eina_stringshare_del(es->appsdir);
@@ -211,3 +222,21 @@ elua_state_setup_i18n(const Elua_State *es)
211 lua_setfield(es->luastate, -2, "dngettext"); 222 lua_setfield(es->luastate, -2, "dngettext");
212#endif 223#endif
213} 224}
225
226EAPI int
227elua_module_init(lua_State *L)
228{
229 Elua_State *es = elua_state_from_lua_get(L);
230 if (!lua_isnoneornil(L, 1))
231 {
232 lua_pushvalue(L, 1);
233 lua_call(L, 0, 0);
234 }
235 if (!lua_isnoneornil(L, 2))
236 {
237 lua_pushvalue(L, 2);
238 es->cmods = eina_list_append(es->cmods,
239 (void*)(size_t)luaL_ref(L, LUA_REGISTRYINDEX));
240 }
241 return 0;
242}