lua-users home
lua-l archive

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


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