[Date Prev][Date Next][Thread Prev][Thread Next]
- 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 02:02:35 -0700
On 8/20/08, Patrick Donnelly <firstname.lastname@example.org> wrote:
> On Wed, Aug 20, 2008 at 2:07 AM, E. Wing <email@example.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
> You have the (relative) file name/path; you passed it to
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?