Slide 24
Slide 24 text
if (luaL_loadfile(L, "foo.lua") || lua_pcall(L, 0, 0, 0)){
// if either call fails, will return non-zero error code
and print
// it out here
printc("error %s", lua_tostring(L, -1));
}
// loads the fib function
lua_getglobal(L, "fib");
// pushes param onto lua stack
int fib_num = 20
lua_pushnumber(L,fib_num);
// executes function into lua state
lua_pcall(L,1,1,0);
int result = (int)lua_tonumber(L, -1);
printc("Fib of %d is %d", fib_num, result);
=== Fib of 20 is 6765