[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How do I get the filename and line number from a failed luaL_loadfile?
- From: "E. Wing" <ewmailing@...>
- Date: Wed, 20 Aug 2008 01:54:35 -0700
On 8/20/08, Peter Odding <xolox@home.nl> wrote:
> E. Wing wrote:
>> I want to get the filename (with absolute path) and line number
>> reported from luaL_loadfile. Is there a reliable way to get at this
>> data?
>>
>> I have thought about parsing the error string returned on the stack,
>> but I see two problems with this. First, I don't consider parsing a
>> very reliable way of doing this. Second, I noticed that for long path
>> names, the file/path name gets truncated so it isn't very useful for
>> me even if I did successfully parse the string.
>>
>> My intention is to use the filename and line number returned to launch
>> a text editor from my program at the location of the lua error to make
>> fixing bugs much easier.
>
> Sorry I can't help you with regards to luaL_loadfile(), however I
> /might/ have an alternate solution... My favorite text editor is Vim and
> it supports user-defined actions on events like saving a file. I've set
> up such an action that runs `luac -p ...` when I save a Lua script. If
> luac finds any parse errors in my script then Vim will show me a list of
> those errors and jump to the first one. I'm not suggesting you switch
> text editors but maybe your text editor can be scripted in a similar manner?
>
> - Peter Odding
>
Thanks for the thought, though I don't think this fits well with my
situation. I have a native Mac/Cocoa application which has a Lua
scripting element for specific pieces. The application is responsible
for firing certain events which call into Lua. In the case of a Lua
error, I have code that will open the file in the user's preferred
text editor. If it is a text editor I know about, I have additional
code that will open the file at the line number.
So in this case, the application is really calling the shots, not the
text editor.
Thanks,
Eric