[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: C preprocessor style #line support
- From: Joshua Jensen <josh.jjensen@...>
- Date: Thu, 25 Aug 2011 17:06:16 -0600
I was reading through the archives to determine what became of the
recent #line mention in the "goto" conversation, but I didn't see anything.
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.
So I started thinking about how to coax Lua into doing this _and_ allow
a Lua debugger to still work.
In fileA.lua, we could have:
local MY_DEFINE = 5 -- Equivalent of #define MY_DEFINE 5
local YOUR_DEFINE = 10 -- Equivalent of #define YOUR_DEFINE 10
In fileB.lua, we would use them:
This doesn't work of course.
If I concatenate the two files together manually, it would only work for
execution, not for debugging.
It would be nice to feed this to Lua (or equivalent):
#line 1 "fileA.lua"
local MY_DEFINE = 5
#line 2 "fileA.lua"
local YOUR_DEFINE = 10
#line 1 "fileB.lua"
#line 2 "fileB.lua"
In this case, the debugger could properly step between files, because
Lua would return the proper script filename. In fact, there are all
kinds of spiffy tricks that could be done with #line.
Are there any fancy techniques to pull this off? Noticing the layout of
the Proto structure, I don't think there are. It seems to have only one
filename per Proto.