summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/elua/elua.c26
-rw-r--r--src/lib/elua/elua_private.h1
2 files changed, 13 insertions, 14 deletions
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index 2d9eebe..44b5c32 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -70,6 +70,7 @@ EAPI Elua_State *
70elua_state_new(const char *progname) 70elua_state_new(const char *progname)
71{ 71{
72 Elua_State *ret = NULL; 72 Elua_State *ret = NULL;
73 Eina_Safepointer *sp;
73 lua_State *L = luaL_newstate(); 74 lua_State *L = luaL_newstate();
74 if (!L) 75 if (!L)
75 return NULL; 76 return NULL;
@@ -77,7 +78,9 @@ elua_state_new(const char *progname)
77 ret->luastate = L; 78 ret->luastate = L;
78 if (progname) ret->progname = eina_stringshare_add(progname); 79 if (progname) ret->progname = eina_stringshare_add(progname);
79 luaL_openlibs(L); 80 luaL_openlibs(L);
80 lua_pushlightuserdata(L, ret); 81 sp = (Eina_Safepointer *)eina_safepointer_register(ret);
82 ret->sp = sp;
83 lua_pushlightuserdata(L, sp);
81 lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr"); 84 lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr");
82 return ret; 85 return ret;
83} 86}
@@ -106,6 +109,7 @@ elua_state_free(Elua_State *es)
106 eina_stringshare_del(es->coredir); 109 eina_stringshare_del(es->coredir);
107 eina_stringshare_del(es->moddir); 110 eina_stringshare_del(es->moddir);
108 eina_stringshare_del(es->appsdir); 111 eina_stringshare_del(es->appsdir);
112 eina_safepointer_unregister(es->sp);
109 free(es); 113 free(es);
110} 114}
111 115
@@ -260,7 +264,8 @@ elua_state_from_lua_state_get(lua_State *L)
260 lua_getfield(L, LUA_REGISTRYINDEX, "elua_ptr"); 264 lua_getfield(L, LUA_REGISTRYINDEX, "elua_ptr");
261 if (!lua_isnil(L, -1)) 265 if (!lua_isnil(L, -1))
262 { 266 {
263 void *st = lua_touserdata(L, -1); 267 Eina_Safepointer *sp = lua_touserdata(L, -1);
268 void *st = eina_safepointer_get(sp);
264 lua_pop(L, 1); 269 lua_pop(L, 1);
265 return (Elua_State *)st; 270 return (Elua_State *)st;
266 } 271 }
@@ -360,17 +365,16 @@ const luaL_Reg gettextlib[] =
360 { "bind_textdomain", _elua_gettext_bind_textdomain }, 365 { "bind_textdomain", _elua_gettext_bind_textdomain },
361 { "get_message_language", _elua_get_message_language }, 366 { "get_message_language", _elua_get_message_language },
362 { "get_localeconv", _elua_get_localeconv }, 367 { "get_localeconv", _elua_get_localeconv },
368#ifdef ENABLE_NLS
369 { "dgettext", dgettext },
370 { "dgettext", dngettext },
371#endif
363 { NULL, NULL } 372 { NULL, NULL }
364}; 373};
365 374
366static Eina_Bool 375static Eina_Bool
367_elua_state_i18n_setup(const Elua_State *es) 376_elua_state_i18n_setup(Elua_State *es)
368{ 377{
369#ifdef ENABLE_NLS
370 char *(*dgettextp)(const char*, const char*) = dgettext;
371 char *(*dngettextp)(const char*, const char*, const char*, unsigned long)
372 = dngettext;
373#endif
374 char buf[PATH_MAX]; 378 char buf[PATH_MAX];
375 EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE); 379 EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
376 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE); 380 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
@@ -380,12 +384,6 @@ _elua_state_i18n_setup(const Elua_State *es)
380 return EINA_FALSE; 384 return EINA_FALSE;
381 lua_createtable(es->luastate, 0, 0); 385 lua_createtable(es->luastate, 0, 0);
382 luaL_register(es->luastate, NULL, gettextlib); 386 luaL_register(es->luastate, NULL, gettextlib);
383#ifdef ENABLE_NLS
384 lua_pushlightuserdata(es->luastate, *((void**)&dgettextp));
385 lua_setfield(es->luastate, -2, "dgettext");
386 lua_pushlightuserdata(es->luastate, *((void**)&dngettextp));
387 lua_setfield(es->luastate, -2, "dngettext");
388#endif
389 lua_call(es->luastate, 1, 0); 387 lua_call(es->luastate, 1, 0);
390 return EINA_TRUE; 388 return EINA_TRUE;
391} 389}
diff --git a/src/lib/elua/elua_private.h b/src/lib/elua/elua_private.h
index f4392f6..1fd955c 100644
--- a/src/lib/elua/elua_private.h
+++ b/src/lib/elua/elua_private.h
@@ -40,6 +40,7 @@ struct _Elua_State
40 Eina_List *lmods; 40 Eina_List *lmods;
41 Eina_List *cmods; 41 Eina_List *cmods;
42 Eina_List *lincs; 42 Eina_List *lincs;
43 Eina_Safepointer *sp;
43 int requireref, apploadref; 44 int requireref, apploadref;
44}; 45};
45 46