Did pcall or include get changed?


Been working a bit on some code and I noticed some strange behaviour when using pcall and include.

Whenever I do local ok, err = pcall(include, “somefile.lua”) and there is an error in the file to include, then the error pops up on the screen (while it shouldn’t do that) and pcall just returns true, nil.

So now my question is, did anything change to any of the 2 functions?

By doing some tests it seems include (even if there is an error) doesn’t stop the script from running anymore, so it seems include is handling and printing the error itself, and not letting the file where the include is done know about the error anymore like it used to do…

no, include() returns nil and pcall returns bool succeeded and function return value.

told by the man below.

There was a LuaJIT bug that made it return nil. But we removed LuaJIT and now it works normally.

Make sure you don’t have any .dll’s installed that could be doing something weird.

Removed all addons except the one I’m testing.
Removed the bin directory (so that the latest dll’s are gotten from the gcf file again)
Removed the lua directory (same as above + removal of any unwanted dll’s)

Still the same problem.

The following code:

local function LoadFile(dir, name)
	local ok, err = pcall(include, "caf/"..tostring(dir).."/"..tostring(name)..".lua")
	Msg("LoadFile "..tostring(ok).."/"..tostring(err).."
	return ok, err

gives the following output:

caf/addons/client/LIFESUPPORT1.lua:89: attempt to call field 'RegisterAddon' (a nil value)
LoadFile true/nil

As you can see it’s giving an error in the included file and showing it right away instead of returning it in the pcall function. The pcall function itself just returns true (that everything is ok => no errors)

Isn’t that how it has always worked?

The error doesn’t occur in the include function, it occurs in the file that is included which means the pcall won’t pick up on it.

Could be wrong though.

MakeR is correct, this also happens with RunString.

I’ve been using lua_openscript_cl recently, and after the LuaJIT rollback, I’ve not been able to load the same script that has already been loaded with include() without renaming it a different name and lua_openscript_cl-ing it there. This is on a listen server.

I’ve used this in normal Lua (not GLua), pcall’ing include, and it gave me errors from the script rather than just the include function just fine. Perhaps it was introduced in a newer version of Lua.