lua-users home
lua-l archive

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


On 8/20/08, Patrick Donnelly <batrick.donnelly@gmail.com> wrote:
> Hi,
>
> On Wed, Aug 20, 2008 at 2:07 AM, E. Wing <ewmailing@gmail.com> 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?
>
> You have the (relative) file name/path; you passed it to
> luaL_loadfile.


So the complication is that an error may have occurred in a file
invoked by require() or a dofile() inside the Lua script itself. So
the file I used in luaL_loadfile is not the same file that may have
triggered the error (and reported in the return string).


Parsing the error message is your best option (afaik):
>
> if (luaL_loadfile(L, "filepath") == LUA_ERRSYNTAX)
> {
>   lua_getfield(L, -1, "match");
>   lua_pushvalue(L, -2);
>   lua_pushliteral(L, ":(%d+):");
>   lua_call(L, 2, 1);
>   // Do something with the line number...
> }

Is it safe to continue using this Lua state after the luaL_loadfile()
failure, or should I be creating a separate Lua state to do this in?

Thanks,
Eric