[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua line numbers when concatenating multiple lua chunks
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sun, 27 Feb 2005 21:51:20 -0300
On Sat, Feb 26, 2005 at 08:12:52PM +1100, Michael Abbott wrote:
> I've been playing around with prefixing the scripts I load with startup
> code. This I've been doing with lua_load() and chunks. I've come
> across the problem that if I want to flag a specific error in the code
> that the user wrote I want to be able to tell them in which line number
> in /their/ code this error occurred on.
>
> Is the only way to do this to scan the characters for \r?\n before they
> reach lua_load()?
Unfortunately, I cannot see a better way. Just be careful to translate \r and
\n to a space, instead of deleting them...
You can do this with a simple lua_load callback that hands back one char at
a time. This probably won't slow things down because the core already buffers
incoming data. (And so does stdio...)
>Also, if this is the case, is there some means of
> solving this when loading a pre-compiled lua chunk?
How so? Text and pre-compiled chunks cannot be mixed. The code that loads
pre-compiled chunks stops as soon as it loads the chunk; it loads only one
chunk. Unless you're pretty intimate with the format of pre-compiled chunks,
there's not much you can change. And even if you are, changing something will
require code equivalent to loading the pre-compiled chunk...
--lhf