在 Visual Studio 中构建 Lua,“setfenv” 无法更改给定对象的环境。

我想用 Visual Studio 2010 构建 lua-5.1.4;一切看起来都没问题,但下面的脚本:

local P = {}
P._G = _G

if _REQUIREDNAME == nil then
smartinput = P
else
_G[_REQUIREDNAME] = P
end
setfenv(1, P)

出现了错误信息:

setfenv’ cannot change environment of given object

我从这里得到了二进制文件

http://sigttou.com/lua-visual-studio-2010-2#comment-209

这些二进制文件也是由 Visual Studio 2010 构建的。这个脚本可以正常工作,但当我使用项目文件自己构建源代码时,错误再次出现。

我需要做什么来避免这个问题?

点赞