summaryrefslogtreecommitdiff
path: root/src/lib/elua/elua.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-04-08 14:29:58 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:18 +0100
commit357d902b87d0b0e74f3db400f77db985f8add19f (patch)
tree52ba3f320e8163174caae7fc2a90a4fd2d4bef44 /src/lib/elua/elua.c
parente0066ca9e7d7ad1c667d17d7d7a6e84f29f1a546 (diff)
elua lib: add elua_state_from_lua_get
Diffstat (limited to 'src/lib/elua/elua.c')
-rw-r--r--src/lib/elua/elua.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index a6bb3914cd..bdd5606fed 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -72,6 +72,8 @@ elua_state_new(void)
72 ret = malloc(sizeof(Elua_State)); 72 ret = malloc(sizeof(Elua_State));
73 ret->luastate = L; 73 ret->luastate = L;
74 luaL_openlibs(L); 74 luaL_openlibs(L);
75 lua_pushlightuserdata(L, ret);
76 lua_setfield(L, LUA_REGISTRYINDEX, "elua_ptr");
75 return ret; 77 return ret;
76} 78}
77 79
@@ -83,6 +85,20 @@ elua_state_free(Elua_State *state)
83 free(state); 85 free(state);
84} 86}
85 87
88EAPI Elua_State *
89elua_state_from_lua_get(lua_State *L)
90{
91 lua_getfield(L, LUA_REGISTRYINDEX, "elua_ptr");
92 if (!lua_isnil(L, -1))
93 {
94 void *st = lua_touserdata(L, -1);
95 lua_pop(L, 1);
96 return (Elua_State *)st;
97 }
98 lua_pop(L, 1);
99 return NULL;
100}
101
86static void 102static void
87_elua_errmsg(const char *pname, const char *msg) 103_elua_errmsg(const char *pname, const char *msg)
88{ 104{