[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: Ben Kelly <ranavin@...>
- Date: Wed, 20 Aug 2008 13:04:10 -0400
E. Wing wrote:
> 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).
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.
> 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).