Original Post
I'm writing a 2D RPG engine in C using LUA for scripting and I want to implement a function in LUA that when called pauses script execution until a specified event occurs e.g. NPCMove(NPC1, 20, 20) waitForNPCMove(NPC1) It wouldn't look exactly like that but you should get the idea. At first I thought I could implement this with coroutines, however there is a snag, if I did do it with coroutines I'd have to create a new thread with lua_newthread( ) and then call a function, the waitForNPCMove statement would then be in that function and would do add the script to a list of scripts waiting for something and then do a lua_yield( ), when the event happened scripting execution would continue using lua_resume( ). I'd don't like this way of doing things though because it means I cannot shove a waitForNPCMove call anywhere in a LUA script, I'd have to explicitly call a function to create a new thread and execute a function that had the waitForNPCMove call in it and creating a new thread creates a new lua_state which means the thread function could not alter stuff in the main script (well not easily and transparently anyway). Can anyone think of a better way to acomplish this?