diff -r fc196bb4bcc2 -r b6b183fbf373 src/nexus_lua.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/nexus_lua.c Wed Apr 01 00:57:34 2009 +0300 @@ -0,0 +1,50 @@ +#include "nexus_lua.h" +#include "lua_objs.h" + +#include + +#include +#include + +err_t nexus_lua_create (struct nexus_lua **lua_ptr, struct nexus *nexus, struct error_info *err) +{ + struct nexus_lua *lua; + + // alloc + if ((lua = calloc(1, sizeof(*lua))) == NULL) + return SET_ERROR(err, ERR_CALLOC); + + // store + lua->nexus = nexus; + + // create the lua state + if ((lua->st = luaL_newstate()) == NULL) + JUMP_SET_ERROR(err, ERR_LUA_MEM); + + // we can then load the core libs + // XXX: we don't need all of these + // XXX: errors? + luaL_openlibs(lua->st); + + // then our own things + if ((ERROR_CODE(err) = lua_objs_init(lua))) + goto error; + + // ok + *lua_ptr = lua; + + return SUCCESS; + +error: + nexus_lua_destroy(lua); + + return ERROR_CODE(err); +} + +void nexus_lua_destroy (struct nexus_lua *lua) +{ + // close the lua stuff + lua_close(lua->st); + + free(lua); +}