diff options
author | Daniel Kolesa <d.kolesa@samsung.com> | 2015-04-10 12:02:08 +0100 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2015-05-06 15:05:19 +0100 |
commit | 6be9b662fbad73d76690daea3631e0d37c0ae896 (patch) | |
tree | c4a0bd077a1a29e9a6cef4f42ee210217c627a3f /src/lib/elua/elua.c | |
parent | 87a8e51cd3457fc8a0cc89add65bc281e0f122db (diff) |
elua lib: add APIs for include path management
Diffstat (limited to 'src/lib/elua/elua.c')
-rw-r--r-- | src/lib/elua/elua.c | 45 |
1 files changed, 44 insertions, 1 deletions
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) | |||
80 | EAPI void | 80 | EAPI void |
81 | elua_state_free(Elua_State *es) | 81 | elua_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 | ||
173 | EAPI void | ||
174 | elua_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 | |||
171 | EAPI lua_State * | 182 | EAPI lua_State * |
172 | elua_state_lua_state_get(const Elua_State *es) | 183 | elua_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 | |||
293 | EAPI int | ||
294 | elua_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 | } | ||