summaryrefslogtreecommitdiff
path: root/src/lib/elua
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-04-10 12:02:08 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:19 +0100
commit6be9b662fbad73d76690daea3631e0d37c0ae896 (patch)
treec4a0bd077a1a29e9a6cef4f42ee210217c627a3f /src/lib/elua
parent87a8e51cd3457fc8a0cc89add65bc281e0f122db (diff)
elua lib: add APIs for include path management
Diffstat (limited to 'src/lib/elua')
-rw-r--r--src/lib/elua/Elua.h3
-rw-r--r--src/lib/elua/elua.c45
-rw-r--r--src/lib/elua/elua_private.h2
3 files changed, 49 insertions, 1 deletions
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index a05b82433c..f70af321d0 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -78,6 +78,8 @@ EAPI Eina_Stringshare *elua_state_core_dir_get(const Elua_State *es);
78EAPI Eina_Stringshare *elua_state_mod_dir_get(const Elua_State *es); 78EAPI Eina_Stringshare *elua_state_mod_dir_get(const Elua_State *es);
79EAPI Eina_Stringshare *elua_state_apps_dir_get(const Elua_State *es); 79EAPI Eina_Stringshare *elua_state_apps_dir_get(const Elua_State *es);
80 80
81EAPI void elua_state_include_path_add(Elua_State *es, const char *path);
82
81EAPI lua_State *elua_state_lua_state_get(const Elua_State *es); 83EAPI lua_State *elua_state_lua_state_get(const Elua_State *es);
82 84
83EAPI int elua_report_error(const Elua_State *es, const char *pname, int status); 85EAPI int elua_report_error(const Elua_State *es, const char *pname, int status);
@@ -89,6 +91,7 @@ EAPI void elua_io_register(const Elua_State *es);
89 91
90EAPI int elua_io_popen(lua_State *L); 92EAPI int elua_io_popen(lua_State *L);
91EAPI int elua_module_init(lua_State *L); 93EAPI int elua_module_init(lua_State *L);
94EAPI int elua_module_system_init(lua_State *L);
92 95
93#endif 96#endif
94 97
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index ae5da0e012..9019fef565 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -80,10 +80,10 @@ elua_state_new(void)
80EAPI void 80EAPI void
81elua_state_free(Elua_State *es) 81elua_state_free(Elua_State *es)
82{ 82{
83 void *data;
83 if (!es) return; 84 if (!es) return;
84 if (es->luastate) 85 if (es->luastate)
85 { 86 {
86 void *data;
87 EINA_LIST_FREE(es->cmods, data) 87 EINA_LIST_FREE(es->cmods, data)
88 { 88 {
89 lua_rawgeti(es->luastate, LUA_REGISTRYINDEX, (size_t)data); 89 lua_rawgeti(es->luastate, LUA_REGISTRYINDEX, (size_t)data);
@@ -93,6 +93,8 @@ elua_state_free(Elua_State *es)
93 } 93 }
94 else if (es->cmods) 94 else if (es->cmods)
95 eina_list_free(es->cmods); 95 eina_list_free(es->cmods);
96 EINA_LIST_FREE(es->lincs, data)
97 eina_stringshare_del(data);
96 eina_stringshare_del(es->coredir); 98 eina_stringshare_del(es->coredir);
97 eina_stringshare_del(es->moddir); 99 eina_stringshare_del(es->moddir);
98 eina_stringshare_del(es->appsdir); 100 eina_stringshare_del(es->appsdir);
@@ -168,6 +170,15 @@ elua_state_apps_dir_get(const Elua_State *es)
168 return es->moddir; 170 return es->moddir;
169} 171}
170 172
173EAPI void
174elua_state_include_path_add(Elua_State *es, const char *path)
175{
176 EINA_SAFETY_ON_NULL_RETURN(es);
177 EINA_SAFETY_ON_NULL_RETURN(path);
178 EINA_SAFETY_ON_FALSE_RETURN(path[0]);
179 es->lincs = eina_list_append(es->lincs, eina_stringshare_add(path));
180}
181
171EAPI lua_State * 182EAPI lua_State *
172elua_state_lua_state_get(const Elua_State *es) 183elua_state_lua_state_get(const Elua_State *es)
173{ 184{
@@ -278,3 +289,35 @@ elua_module_init(lua_State *L)
278 } 289 }
279 return 0; 290 return 0;
280} 291}
292
293EAPI int
294elua_module_system_init(lua_State *L)
295{
296 Elua_State *es = elua_state_from_lua_get(L);
297 const char *corepath = es->coredir;
298 const char *modpath = es->moddir;
299 const char *appspath = es->appsdir;
300 Eina_Stringshare *data = NULL;
301 int n = 3;
302 if (!corepath || !modpath || !appspath)
303 return 0;
304 lua_pushvalue(L, 1);
305 es->requireref = luaL_ref(L, LUA_REGISTRYINDEX);
306 lua_pushvalue(L, 2);
307 es->apploadref = luaL_ref(L, LUA_REGISTRYINDEX);
308 lua_pushfstring(L, "%s/?.lua;", corepath);
309 EINA_LIST_FREE(es->lincs, data)
310 {
311 lua_pushfstring(L, "%s/?.lua;", data);
312 eina_stringshare_del(data);
313 ++n;
314 }
315 lua_pushfstring(L, "%s/?.eo.lua;", modpath);
316 lua_pushfstring(L, "%s/?.lua;", modpath);
317 lua_pushvalue(L, 3);
318 lua_concat(L, n + 1);
319 lua_pushfstring(L, "%s/?.lua;", appspath);
320 lua_pushvalue(L, 4);
321 lua_concat(L, 2);
322 return 2;
323}
diff --git a/src/lib/elua/elua_private.h b/src/lib/elua/elua_private.h
index 722d3f2b20..aa00cd300f 100644
--- a/src/lib/elua/elua_private.h
+++ b/src/lib/elua/elua_private.h
@@ -34,6 +34,8 @@ struct _Elua_State
34 Eina_Stringshare *moddir; 34 Eina_Stringshare *moddir;
35 Eina_Stringshare *appsdir; 35 Eina_Stringshare *appsdir;
36 Eina_List *cmods; 36 Eina_List *cmods;
37 Eina_List *lincs;
38 int requireref, apploadref;
37}; 39};
38 40
39extern int _elua_log_dom; 41extern int _elua_log_dom;