lua-users home
lua-l archive

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


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).
	Ben Kelly