summaryrefslogtreecommitdiff
path: root/src/lib/elua
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
parente0066ca9e7d7ad1c667d17d7d7a6e84f29f1a546 (diff)
elua lib: add elua_state_from_lua_get
Diffstat (limited to 'src/lib/elua')
-rw-r--r--src/lib/elua/Elua.h2
-rw-r--r--src/lib/elua/elua.c16
2 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index 69c72b05b9..2f1f41af68 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -69,6 +69,8 @@ EAPI int elua_shutdown(void);
69EAPI Elua_State *elua_state_new(void); 69EAPI Elua_State *elua_state_new(void);
70EAPI void elua_state_free(Elua_State *state); 70EAPI void elua_state_free(Elua_State *state);
71 71
72EAPI Elua_State *elua_state_from_lua_get(lua_State *L);
73
72EAPI int elua_report_error(lua_State *L, const char *pname, int status); 74EAPI int elua_report_error(lua_State *L, const char *pname, int status);
73 75
74EAPI void elua_state_setup_i18n(lua_State *L); 76EAPI void elua_state_setup_i18n(lua_State *L);
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{