lua-users home
lua-l archive

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


On Mon, Jul 14, 2014 at 10:15 PM, Tim Hill <drtimhill@gmail.com> wrote:

On Jul 14, 2014, at 10:09 AM, Jerome Vuarand <jerome.vuarand@gmail.com> wrote:

> 2014-07-14 16:24 GMT+01:00 Xavier Wang <weasley.wx@gmail.com>:
>> 2014-07-14 22:54 GMT+08:00 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>>>> I just hopes to know how Luiz & Roberto think about add a #line (or
>>>> other syntax) to Lua, specific the line number of next line, this is
>>>> useful when you write a preprocessor (somethings like [1] or [2] or
>>>> LuaMacro[3])
>>>>
>>>> the implement may very easy: when llex read a #line, it set the
>>>> lastline (or linenumber?) field of LexState.
>>>
>>> It is not that easy. A #line directive without a file name is a half
>>> baked solution, and to store multiple file names in a chunk would
>>> require some new data structures. (Nothing impossible, but it is
>>> not trivial.)
>>>
>>> -- Roberto
>>>
>>

I have a generic CPP-like macro processor for Lua (written in Lua, of course!), and all I do is have it emit a “mapping” file that contains the source file and line number for each line in the output file. It’s not elegant, but it’s simple and works with standard Lua (and any other language). If you get an error on line XXX in Lua, you just look on line XXX in the mapping file and it tells you what file/line number originated the code.

Cheap, but works.
—Tim




I suppose you could also wrap some functions such as error() and assert() to automatically look up the correct line in the mapping.

--
Sent from my Game Boy.