lua-users home
lua-l archive

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


----- Original Message -----
From: Tony Finch
Date: 8/26/2011 5:00 AM
Joshua Jensen<josh.jjensen@gmail.com>  wrote:
I'm porting scripts from an in-house scripting language to Lua.  The in-house
scripting language uses a lot of C-style #includes and #defines for values.
Originally, I thought the use of the preprocessor was silly, but as I've
ported more and more scripts, I've come to realize there are some good uses of
#define in there.
Sorry this isn't a helpful answer but I would be interested to see some
examples.

I kept it simple with the initial post, but I can describe a little better what is going on.

Excel spreadsheets are processed at certain points in the asset build to generate files with #defines containing values for both the game and the script system (which was run through a preprocessor). So one script would #include "MeteorStuff.h" and then #include "BehaviorStuff.h" and another script would #include completely separate files.

The idea behind the original post would enable me to fake a #include system with Lua by having an equivalent #line <number> <filename> directive. I would, for a given script, concatenate MeteorStuff.lua and then BehaviorStuff.lua and then the script would follow. These lines could be stepped through in the Lua debugger properly, and given the use of local variables, they would contain fastest access to the value.

For now, I am loading MeteorStuff.lua and BehaviorStuff.lua into a Constants table and assigning an __index metatable entry to that Constants table. This stinks. Performance suffers due to the hashed lookups in what could just be local variable lookups.

So, I am likely going to have to use a preprocessor to expand the values in place. I lose useful debugging capabilities.

Alternatively, I am considering a modification to the Proto structure where I:

* Change to a TString sources array:  TString  **source
* Embed which source file index into the upper bits of a line number entry in int *lineinfo.

-Josh