fix lua foo
This commit is contained in:
parent
1b2935353e
commit
065204dc85
1 changed files with 15 additions and 5 deletions
20
lua-foo.c
20
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue