lua-users home
lua-l archive

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


First post - hi everyone!  My name is Guy.  You might remember me from such products as Rome:Total War where I wrote the scripting language.

For our next effort, I am investigating Lua.  I have integrated the library into our prototype and executed commands from its CLI.  This is all good - I even have batch files running.  However, I have a number of issues I need to resolve.  I don't need code to be written, merely some pointers in the right direction for investigation before I funnel my efforts too tightly.  I should also point out that I went straight to Roberto Ierusalimschy's online version of Programming in Lua before I read the html manual, so if there is any apparent version collisions with function calls, or if I'm doing deprecated stuff, that may be why.  Feel free to point it out.

Firstly, my "batch files" can't do control structures.  I am merely passing each command to luaL_loadbuffer and lua_pcall which means that "for" gets short shrift.  I am currently looking through the interpreter source code with a fine toothed comb and a pith helmet.  I'm a C++ developer, and I haven't used C since the 80s, so this is proving to be a testing time for me.

It seems to be the case that the interpreter collects together commands within structures and executes them when the structure is complete.  Is that correct?

Next, we want to use Lua as a scripting language.  Now, we are clearly suffering a bit of a semantic cock-up here, as everyone on the team seems to have a different idea of what a scripting language is.  For example, some see a scripting language as a setup system for UI layout management, others for speedy macros, while there are those who tell me a scripting language is for narrating the movement of armies about the battlefield.  Frankly, I'm not so bothered about this, but I need to accommodate all these uses.

Some things have worried me about this during my investigations.  In Rome the scripting language had a concept of game time, and you could suspend execution for a few seconds while the game did its thing.  For example, you could direct troops to move thirty metres to the south, and suspend execution until they had done that.  Given my earlier observation about execution being lined up in big chunks, I'm concerned this isn't going to be possible without fundamentally altering the way that Lua executes its commands.  I'm a big boy, I can do that, I've been coding for many years, but it makes me shudder a little because it strikes at the heart of the language and suggests I'm in the wrong place.

Additionally, we had interrupts.  You could monitor an event (such as a general dying) and execute code when that event occurred.  Additionally, you could poll for conditions, so that code would be executed when your (the scripter's) own kind of event occurred.  I imagine I would implement this by putting a lua_pcall construct at the event dispatch, and calling the polling functions at every tick.

What this really boils down to is:

Is it possible to direct Lua to "execute only the next instruction in the script" regardless of whether it's in a loop?
Is it possible to re-enter a script with a prior context so that the lua_State of one function can be used as the lua_State of another?

Lua may be inappropriate for this endeavour - the concept of partial execution of scripts may be problematic.  If that's the case, tell me and I'll move on to another option - maybe I'll expand what I have at the moment.

Cheers,
Guy Davidson