[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 18:16:29 -0700
> No, this is not possible. Loadfile only compiles the file, it does not
> run it. If the file uses require(), dofile(), loadfile(), or similar
> functions, those will not be called until runtime, when you call the
> function created by luaL_loadfile using lua_pcall. At that point, if
> they try to load bad files, the compilation of *those* files will fail
> and you'll see a runtime error.
Thanks for the clarification. For lua_pcall, I've been providing my
own error function that does a stack trace and saves the line number
and file name. In the case of require(), this function wasn't being
called so I assumed it was due to the luaL_loadfile. But it turns out
that my error function doesn't get invoked in this case.
It seems that in this case, I don't get a truncated filepath/name, so
I can parse it. But now I'm rather confused on when I get a truncated
string or not.
>>
>> 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?
>>
> Yes, it's safe. As far as I'm aware it is not possible to get the lua
> state into an "unsafe" state as long as you are using the API properly
> (and if it is, this is a bug in lua, and should be reported).
I realized I needed a separate Lua state anyway because it's not clear
to me if the string library is loaded in my other state and if so, if
a script didn't remove the 'string' table.
Thanks,
Eric