这工作...Lua的错误没有通过布尔
if (tileType == "water" or
(otherObj and otherObj:GetType() == "IceBlock")) then
self:SetNoClip(true)
else
self:SetNoClip(false)
end
- 这些不...
self:SetNoClip(tileType == "water" or
(otherObj and otherObj:GetType() == "IceBlock"))
//----------------------------------------------------------
local noClip = (tileType == "water" or
(otherObj and otherObj:GetType == "IceBlock"))
self:SetNoClip(noClip)
的otherObj
测试只是计算结果为otherObj是否nil
与否。给出的变量在前一行中检索。我得到了应用程序运行时的错误是:
unprotected error to call in Lua API(script path...: Did not pass boolean to SetNoClip).
SetNoClip是,抓住论证通过lua_toboolean
压入堆栈LUA应用程序的功能。
那么为什么第一个工作和第二个和第三个返回错误?
编辑:
SetNoClip 有这个定义。
int GameObject::LuaSetNoClip(lua_State *L) {
if (!lua_isboolean(L, -1)) {
LogLuaErr("Did not pass boolean to SetNoClip for GameObject: " + m_type);
return luaL_error(L, "Did not pass boolean to SetNoClip");
}
m_noClip = lua_toboolean(L, -1);
return 0;
}
的问题是,lua_isboolean
没有做任何隐式类型转换(但lua_toboolean
那样),将只用于文字布尔值返回true。所以如果它看到零,它会返回一个布尔值不被传递。我只是删除了布尔文字的错误检查,因为人们(包括我)通常依赖于非布尔文字的参数被正确对待为布尔值。
FWIW,错误消息不只是胡言乱语。无论何时遇到错误,发布消息总是有帮助的。通常他们会告诉你究竟在哪里以及是什么问题。我们很乐意帮助他们解决问题,以便下次可以利用他们。 – Cogwheel 2010-07-11 17:50:45
我没有发布它。这不是胡言乱语。问题是什么非常清楚。没有将布尔值传递给SetNoClip。 – random 2010-07-11 18:04:03
哦,对不起,我错过了它<需要更多的咖啡因(对我的评论投票的人也是如此:P)。我让它脱颖而出... – Cogwheel 2010-07-11 18:13:12