elua lib: add elua_state_new and elua_state_free
authorDaniel Kolesa <d.kolesa@samsung.com>
Wed, 8 Apr 2015 13:00:57 +0000 (14:00 +0100)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Wed, 6 May 2015 14:05:18 +0000 (15:05 +0100)
src/lib/elua/Elua.h
src/lib/elua/elua.c

index 7fdd19f..69c72b0 100644 (file)
@@ -66,6 +66,9 @@ typedef struct _Elua_State
 EAPI int elua_init(void);
 EAPI int elua_shutdown(void);
 
+EAPI Elua_State *elua_state_new(void);
+EAPI void elua_state_free(Elua_State *state);
+
 EAPI int elua_report_error(lua_State *L, const char *pname, int status);
 
 EAPI void elua_state_setup_i18n(lua_State *L);
index 2f88e7b..a6bb391 100644 (file)
@@ -62,6 +62,27 @@ elua_shutdown(void)
    return _elua_init_counter;
 }
 
+EAPI Elua_State *
+elua_state_new(void)
+{
+   Elua_State *ret = NULL;
+   lua_State *L = luaL_newstate();
+   if (!L)
+     return NULL;
+   ret = malloc(sizeof(Elua_State));
+   ret->luastate = L;
+   luaL_openlibs(L);
+   return ret;
+}
+
+EAPI void
+elua_state_free(Elua_State *state)
+{
+   if (!state) return;
+   if (state->luastate) lua_close(state->luastate);
+   free(state);
+}
+
 static void
 _elua_errmsg(const char *pname, const char *msg)
 {