summaryrefslogtreecommitdiff
path: root/src/lib/elua
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
parentad999df598680c43c492d5db776a6eeb50e45ec3 (diff)
elua lib: manage bound modules within Elua_State
Diffstat (limited to 'src/lib/elua')
-rw-r--r--src/lib/elua/Elua.h1
-rw-r--r--src/lib/elua/elua.c31
-rw-r--r--src/lib/elua/elua_private.h1
3 files changed, 32 insertions, 1 deletions
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index 0b452cf210..b72ada52c7 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -87,6 +87,7 @@ EAPI int elua_io_loadfile(const Elua_State *es, const char *fname);
87EAPI void elua_io_register(const Elua_State *es); 87EAPI void elua_io_register(const Elua_State *es);
88 88
89EAPI int elua_io_popen(lua_State *L); 89EAPI int elua_io_popen(lua_State *L);
90EAPI int elua_module_init(lua_State *L);
90 91
91#endif 92#endif
92 93
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}
diff --git a/src/lib/elua/elua_private.h b/src/lib/elua/elua_private.h
index 5c634880e8..722d3f2b20 100644
--- a/src/lib/elua/elua_private.h
+++ b/src/lib/elua/elua_private.h
@@ -33,6 +33,7 @@ struct _Elua_State
33 Eina_Stringshare *coredir; 33 Eina_Stringshare *coredir;
34 Eina_Stringshare *moddir; 34 Eina_Stringshare *moddir;
35 Eina_Stringshare *appsdir; 35 Eina_Stringshare *appsdir;
36 Eina_List *cmods;
36}; 37};
37 38
38extern int _elua_log_dom; 39extern int _elua_log_dom;