From 065204dc85a6eba1e126754536f8954a95d6ff30 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 8 Dec 2013 22:36:43 +0100 Subject: [PATCH] fix lua foo --- lua-foo.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lua-foo.c b/lua-foo.c index 7457454..c26ac8b 100644 --- a/lua-foo.c +++ b/lua-foo.c @@ -37,12 +37,22 @@ static int l_mysin(lua_State *L) { int main(void) { /* Set up Lua. */ lua_State *L; - L = lua_open(); + L = luaL_newstate(); - luaopen_base(L); - luaopen_string(L); - /* Alternatively: - luaL_openlibs(L); */ + /* Load necessary libs. */ + luaL_Reg lualibs[] = { + { "base", luaopen_base }, + { "string", luaopen_string }, + { NULL, NULL} + }; + for(luaL_Reg *lib = lualibs; lib->func; lib++) { + printf("Loading %s\n", lib->name); + lib->func(L); + lua_setglobal(L, lib->name); + lua_settop(L, 0); + } + /* Alternatively, we could have called LuaL_openlibs(L) but that would have + loaded *all* libs. */ /* Register 'mysin'. */ lua_pushcfunction(L, l_mysin);