[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: Lua line numbers when concatenating multiple lua chunks
From:       Luiz Henrique de Figueiredo <lhf () tecgraf ! puc-rio ! br>
Date:       2005-02-28 0:51:20
Message-ID: 20050227215120.A6475 () lua ! tecgraf ! puc-rio ! br
[Download RAW message or body]

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 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic