Script: Fixed that the value of the Script measure is not reset when an error occurs.

In the following case, for example, the value of the measure used to remain 10 even after an error. Now it will default to 0 on error.

function Initialize()
	i = 0
end

function Update()
	if i < 5 then
		i = i + 1
		return 10
	else
		i() -- error here, execution stops
		return 2
	end
end
This commit is contained in:
Birunthan Mohanathas
2011-07-25 17:59:43 +00:00
parent b23217d840
commit 23f4a31bf0
2 changed files with 11 additions and 25 deletions

View File

@ -171,14 +171,12 @@ bool LuaScript::RunFunctionWithReturn(const char* funcName, double& numValue, st
{
if (lua_isstring(m_State, -1))
{
// Type is LUA_TSTRING or LUA_TNUMBER
const char* str = lua_tostring(m_State, -1);
strValue = ConvertToWide(str);
// A number is a string and numerical string (e.g. "10") is a number, so check for it here
if (lua_isnumber(m_State, -1))
{
numValue = lua_tonumber(m_State, -1);
}
// lua_tonumber() returns 0 when type is non-number
numValue = lua_tonumber(m_State, -1);
ret = true;
}