lua-users home
lua-l archive

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


| But the global variables stays in the state even if your program exsts... My
| suggestion is to use lua_callfunction  from your primary C loop ... All the
| global variables will still work between calls..

Certainly...

| Example:
|
| lua_dofile("source file with all functions and initialization code");
| while(!Quit)
| {
|   lua_callfunction(lua_getglobal("primary script function");
|   RenderDisplayAndOtherCstuff();
| }
|
| This is my suggestion to an effective Lua game engine.. The only problem is
| that the call to Lua must not take to much time.. On way could be to split

The way I've handled it is that each Lua script is basically an event handler. At startup each script registers its
'interest' in a number of events. When these occur (in the C part of the code), the script gets called, and the event
gets handled (or not) by the script. Typically it spits out some text and sets some state variables - nothing very time
consuming, and no loops to get out of control.

For example, a script can tell the C engine it wants to be notified of an EVENT_COLLISION happening on a certain object.
Then, when that object (e.g. a switch) gets hit by something, the script handles it.