#include "api.h" #include "log.h" bool lua_api_init(lua_api_t *lua) { lua->state = luaL_newstate(); if (!lua->state) return false; luaL_openlibs(lua->state); lua_api_require(lua, "log", lua_log_library); return true; } void lua_api_require(lua_api_t *lua, const char *name, lua_library_t lib_fn) { lua_pushcfunction(lua->state, lib_fn); lua_pushstring(lua->state, name); lua_call(lua->state, 1, 1); lua_pushvalue(lua->state, -1); lua_setglobal(lua->state, name); lua_pop(lua->state, 1); } void lua_api_close(lua_api_t *lua) { lua_close(lua->state); }