lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm considering doing some sort of callbacks from my game to the 
level script (for events). What I need is some kind of 
lua_isFunctionPresent.

What I'm considering is something along the lines of:

function LoadLevel()
         -- do stuff
         object = LoadObject("object\fred.x","fredname")
         --
end

function fredname_IsDestroyed()
         -- do something
end

function fredname_IsHitByEnemy()
         -- do something else
end

So when "fredname" is destroyed something like:

if( lua_isFunctionPresent("fredname_IsDestroyed")
      {
      lua_fn = lua_getglobal("fredname_IsDestroyed");
      lua_callfunction(lua_fn);
      }

gets called.

Am I barking up the wrong tree here? No doubt the lua gods will say 
theres some devastatingly simple way to do it (there usually is...) 
but I cannot find it.

Benedict