lua-users home
lua-l archive

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


Hi,

 

This is yet another question about lua threads. I’ve been looking though the archives but haven’t been able to find exactly what I’m looking for.

 

What I have is a main lua script that I create new states from using lua_newstate, one for each object that has a script. I have registered a wait() function so that the thread can be yielded and resumed. The wait() function is a C function that calls lua_yield() before returning.

 

The yield and resume all works fine.

 

What I don’t quite understand is how to call other functions inside a script that has been yielded. Example:

 

-- lua script

function onHit()

   playAnim()

   wait(10)

   playAnim2()

end

 

function onActivate()

   while 1==1 do

      moveTo(….)

      wait(10)

      playAnim()

      cameraShake()

      wait(10)

   end

end

 

So after calling onActivate I want to be able to call the function onHit.

 

I call my functions from C something like this:

lua_getglobal(L, “onActivate”);

lua_resume(L, 0);

 

Sorry if this has been covered already. Any pointers to how to setup Lua to work like this would be much appreciated.

 

Thanks!