gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > LUA problems in my engine

#70881 - TwinD - Thu Feb 09, 2006 7:00 am

Ok

I have a fairly flexible engine that has been built on for awhile. Originally I was just doing the scripting using C but recently decided to change over to LUA. I use GBFS and seeing as they aren't 'real' files in GBFS I figured I have to use lua_dobuffer instead of lua_dofile so i have a compiled lua file in my GBFS named mithla.lub

my loading code:
u32 size;
const char* scriptFile = (const char*)gbfs_get_obj(dat, filename, &size);
lua_dobuffer(luaScript, scriptFile, size, filename);

then to call the autoexec (the one thing im testing)
runFunction("autoexec");


// runs a function in the current script
void CScriptHandler::runFunction(char *funcname)
{
int top = lua_gettop(luaScript);

lua_getglobal(luaScript, funcname);
lua_call(luaScript, 0, 0);
lua_settop(luaScript, top);
}

the lua file has:
-- Test Script File for GBA Engine
function autoexec ()
loadMap("Mithla Village");
end

loadMap right now is a hacked function that loads the same map everytime, sets everything up and puts it on screen for testing purposes

ive made sure im initializing the luaVM, registering all my functions, loading the right file, checked that its in the gbfs, etc but im not seeing the problem and it just isnt doing anything when it calls the autoexec

any ideas?

#70886 - sajiimori - Thu Feb 09, 2006 8:36 am

There are too many possibilities to troubleshoot. Find a minimal sample and get it running on your PC, then get the same thing running on GBA. After that it's easy.

#71023 - tepples - Fri Feb 10, 2006 1:02 am

In fact, you can even test the GBFS handling code on the PC by malloc()ing a buffer and loading your .gbfs file into that. Provided you're running on a 32-bit little-endian platform (e.g. x86), it should work out of the box.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#71592 - TwinD - Mon Feb 13, 2006 5:40 pm

well i've researched this issue further and come to the following conclusion:

if i use a .lua file containing no functions such as:

loadMap("blahba");
setCameraFocus(0);

it will work fine,

however if i do
function autoexec()
loadMap("blahba");
setCameraFocus(0);
end

it will load up fine, but when i do lua_getglobal(l, "autoexec); and then do a lua_call it never calls the function... it's a bit bizarre, i'm confused as to why it must be reading it right but won't be calling it... maybe someone with some lua experience could help

#71704 - Joat - Tue Feb 14, 2006 1:42 am

Not knowing anything at all about lua, have you tried looking for a get last error function or similar (seems to be using a stack mentality, since you don't get any return values from the global lookup), and instrumenting the runFunction call to make sure it's working as expected?

Also, heya, it's been forever :D
_________________
Joat
http://www.bottledlight.com