BlitzMax LUA: unprotected error in call to Lua API
BlitzMax Forums/BlitzMax Programming/BlitzMax LUA: unprotected error in call to Lua API| 
 | ||
| I have this lua file which, as far as I can tell, is being properly loaded and compiled: function runonce() end function main() end when I do this in BlitzMax, lua_getfield(script, LUA_GLOBALSINDEX, "main") lua_call(script, 0, 0) I get the critical error "PANIC: unprotected error in call to Lua API (attempt to call a nil value)" What am I doing wrong here? Last edited 2012 | 
| 
 | ||
| Local script@ Ptr=luaL_newstate() luaL_openlibs(script) luaL_loadstring(script,"function main()~nprint(~qtest~q)~nend") lua_getfield(script, LUA_GLOBALSINDEX, "main") 'Puts the function onto the stack lua_call(script, 0, 0) This doesn't work either. What? | 
| 
 | ||
| Also, this code does nothing. Local script@ Ptr=luaL_newstate() luaL_openlibs(script) lua_register script,"pr",pr luaL_loadstring(script,"pr") lua_pcall(script,1,-1,-1) Function pr%(state@ Ptr) Print "ok" Return 0 End Function Last edited 2012 | 
| 
 | ||
| I got it to work. for the reference of any future person who stumbles upon this seeking answers: Local state@ Ptr=luaL_newstate() luaL_openlibs(state) lua_register state,"pr",pr luaL_loadstring(state,"function test()~n~rprint(~qtest~q)~n~rpr()~n~rend~n~r") lua_pcall(state,1,-1,-1) lua_getfield(state, LUA_GLOBALSINDEX, "test") 'Puts the function onto the stack lua_call(state, 0, 0) Function pr%(state@ Ptr) Print "ok" Return 0 End Function |