From bf4837dbbfdb300372b9fe7a57378e580e4dad23 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 8 Apr 2015 14:00:57 +0100 Subject: [PATCH] elua lib: add elua_state_new and elua_state_free --- src/lib/elua/Elua.h | 3 +++ src/lib/elua/elua.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h index 7fdd19f..69c72b0 100644 --- a/src/lib/elua/Elua.h +++ b/src/lib/elua/Elua.h @@ -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); diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c index 2f88e7b..a6bb391 100644 --- a/src/lib/elua/elua.c +++ b/src/lib/elua/elua.c @@ -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) { -- 2.7.4