[q2x] OT: Lua questions

Nick Trout nick at rockstarvancouver.com
Fri Jan 30 20:20:10 EST 2004


> > It's true Lua could have a few more warnings here and there. Its
> > pretty good though.
> 
> Things I would really like:
> 
> 1.  The ability to limit VM cycles and force preemption.

You may be able to do this with coroutines and a line hook. We have a
debugger that can single step.

> 2.  At the very least, a compiler flag to warn on assignment to
> uninitialized variables.

You can do this with metatables.

> 3.  A real regex library.  They complain that a POSIX regex
> implementation would take up 4000 lines of code, but at least making
> it optional would have been nice given all the other optional cruft
> they provide.

There is a posix regex library. Have a look in the Lua addons on the
wiki.

> > leap from static programming to dynamic programming is as great as
> > the one from functional programming to OO.
> 
> Um, not quite, but I understand your point =)

Perhaps not, but I daren't use the phrase "paradigm shift". :)

> > to read code and spot bugs more readily. Unit testing is very easy
> > in modular dynamic languages and this may help you too.
> 
> Unit tests are fine, except a lot of the stuff I'm testing can't be
> put into units because they're dependent on my kernel running (if that
> makes sense).  If it was a pure Lua program, that's fine, but since
> it's all embedded, everything is a freakin mess.

True. Which is part of the reason I'd have engineered the whole thing in
Python. Even if you throw it away and write an optimised version in C,
the (far less painful) prototyping in Python has helped you loads with
where you're going. Its better to extend python than embed it, and you
can unit test. You could extend Lua because it does handle dynamic libs,
then you'd run the unit tests on your modules. It just depends how you
set everything up, ie. Lua has main(), not the exe. You must be able to
run some kinds of tests/diagnostics when the exe fires up?

BTW I've almost got the flyer converted over to Lua in q2x. I've written
a Python script to generate an auto binding wrapper for the q2x stuff.
Even after the refactoring Quake seems quite hardcoded. I think that's
how you envisaged it though Brian, that Lua would just bind to a stub
which is the game DLL. Then the monster scripts and config live in the
game. (Oh, Lua is a DLL as well now, which links with game exe and game
DLL. They all share the same Lua state.) This way you could write
monsters in Lua or C. I think it's going to be too much work for me to
convert all of the monsters over to Lua so I may ask to check it all in
after 2-3 of them and ask for help. i.e. some will be Lua and some C.

Nick







More information about the q2x mailing list