Fix certain Lua APIs mangling integers
Also fix a few warnings.
This commit is contained in:
parent
133c8db0c7
commit
c0e065cc76
@ -94,7 +94,7 @@ GameModel::GameModel():
|
|||||||
//Load config into simulation
|
//Load config into simulation
|
||||||
edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0);
|
edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0);
|
||||||
sim->SetEdgeMode(edgeMode);
|
sim->SetEdgeMode(edgeMode);
|
||||||
ambientAirTemp = R_TEMP + 273.15;
|
ambientAirTemp = float(R_TEMP) + 273.15f;
|
||||||
{
|
{
|
||||||
auto temp = Client::Ref().GetPrefNumber("Simulation.AmbientAirTemp", ambientAirTemp);
|
auto temp = Client::Ref().GetPrefNumber("Simulation.AmbientAirTemp", ambientAirTemp);
|
||||||
if (MIN_TEMP <= temp && MAX_TEMP >= temp)
|
if (MIN_TEMP <= temp && MAX_TEMP >= temp)
|
||||||
|
@ -387,7 +387,7 @@ void OptionsView::UpdateAirTemp(String temp, bool isDefocus)
|
|||||||
if (temp.empty())
|
if (temp.empty())
|
||||||
{
|
{
|
||||||
isValid = true;
|
isValid = true;
|
||||||
airTemp = R_TEMP + 273.15;
|
airTemp = float(R_TEMP) + 273.15f;
|
||||||
}
|
}
|
||||||
else if (!isValid)
|
else if (!isValid)
|
||||||
return;
|
return;
|
||||||
|
@ -2630,9 +2630,6 @@ void LuaScriptInterface::LuaGetProperty(lua_State* l, StructProperty property, i
|
|||||||
case StructProperty::Float:
|
case StructProperty::Float:
|
||||||
lua_pushnumber(l, *((float*)propertyAddress));
|
lua_pushnumber(l, *((float*)propertyAddress));
|
||||||
break;
|
break;
|
||||||
case StructProperty::Char:
|
|
||||||
lua_pushnumber(l, *((char*)propertyAddress));
|
|
||||||
break;
|
|
||||||
case StructProperty::UChar:
|
case StructProperty::UChar:
|
||||||
lua_pushnumber(l, *((unsigned char*)propertyAddress));
|
lua_pushnumber(l, *((unsigned char*)propertyAddress));
|
||||||
break;
|
break;
|
||||||
@ -2660,6 +2657,15 @@ void LuaScriptInterface::LuaGetProperty(lua_State* l, StructProperty property, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t int32_truncate(double n)
|
||||||
|
{
|
||||||
|
if (n >= 0x1p31)
|
||||||
|
{
|
||||||
|
n -= 0x1p32;
|
||||||
|
}
|
||||||
|
return int32_t(n);
|
||||||
|
}
|
||||||
|
|
||||||
void LuaScriptInterface::LuaSetProperty(lua_State* l, StructProperty property, intptr_t propertyAddress, int stackPos)
|
void LuaScriptInterface::LuaSetProperty(lua_State* l, StructProperty property, intptr_t propertyAddress, int stackPos)
|
||||||
{
|
{
|
||||||
switch (property.Type)
|
switch (property.Type)
|
||||||
@ -2667,19 +2673,16 @@ void LuaScriptInterface::LuaSetProperty(lua_State* l, StructProperty property, i
|
|||||||
case StructProperty::TransitionType:
|
case StructProperty::TransitionType:
|
||||||
case StructProperty::ParticleType:
|
case StructProperty::ParticleType:
|
||||||
case StructProperty::Integer:
|
case StructProperty::Integer:
|
||||||
*((int*)propertyAddress) = luaL_checkinteger(l, stackPos);
|
*((int*)propertyAddress) = int32_truncate(luaL_checknumber(l, stackPos));
|
||||||
break;
|
break;
|
||||||
case StructProperty::UInteger:
|
case StructProperty::UInteger:
|
||||||
*((unsigned int*)propertyAddress) = luaL_checkinteger(l, stackPos);
|
*((unsigned int*)propertyAddress) = int32_truncate(luaL_checknumber(l, stackPos));
|
||||||
break;
|
break;
|
||||||
case StructProperty::Float:
|
case StructProperty::Float:
|
||||||
*((float*)propertyAddress) = luaL_checknumber(l, stackPos);
|
*((float*)propertyAddress) = luaL_checknumber(l, stackPos);
|
||||||
break;
|
break;
|
||||||
case StructProperty::Char:
|
|
||||||
*((char*)propertyAddress) = luaL_checkinteger(l, stackPos);
|
|
||||||
break;
|
|
||||||
case StructProperty::UChar:
|
case StructProperty::UChar:
|
||||||
*((unsigned char*)propertyAddress) = luaL_checkinteger(l, stackPos);
|
*((unsigned char*)propertyAddress) = int32_truncate(luaL_checknumber(l, stackPos));
|
||||||
break;
|
break;
|
||||||
case StructProperty::BString:
|
case StructProperty::BString:
|
||||||
*((ByteString*)propertyAddress) = ByteString(luaL_checkstring(l, stackPos));
|
*((ByteString*)propertyAddress) = ByteString(luaL_checkstring(l, stackPos));
|
||||||
@ -2689,9 +2692,9 @@ void LuaScriptInterface::LuaSetProperty(lua_State* l, StructProperty property, i
|
|||||||
break;
|
break;
|
||||||
case StructProperty::Colour:
|
case StructProperty::Colour:
|
||||||
#if PIXELSIZE == 4
|
#if PIXELSIZE == 4
|
||||||
*((unsigned int*)propertyAddress) = luaL_checkinteger(l, stackPos);
|
*((unsigned int*)propertyAddress) = int32_truncate(luaL_checknumber(l, stackPos));
|
||||||
#else
|
#else
|
||||||
*((unsigned short*)propertyAddress) = luaL_checkinteger(l, stackPos);
|
*((unsigned short*)propertyAddress) = int32_truncate(luaL_checknumber(l, stackPos));
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case StructProperty::Removed:
|
case StructProperty::Removed:
|
||||||
@ -3458,7 +3461,7 @@ int LuaScriptInterface::graphics_fillCircle(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::graphics_getColors(lua_State * l)
|
int LuaScriptInterface::graphics_getColors(lua_State * l)
|
||||||
{
|
{
|
||||||
unsigned int color = lua_tointeger(l, 1);
|
unsigned int color = int32_truncate(lua_tonumber(l, 1));
|
||||||
|
|
||||||
int a = color >> 24;
|
int a = color >> 24;
|
||||||
int r = (color >> 16)&0xFF;
|
int r = (color >> 16)&0xFF;
|
||||||
|
@ -16,7 +16,6 @@ struct StructProperty
|
|||||||
Float,
|
Float,
|
||||||
BString,
|
BString,
|
||||||
String,
|
String,
|
||||||
Char,
|
|
||||||
UChar,
|
UChar,
|
||||||
Removed
|
Removed
|
||||||
};
|
};
|
||||||
@ -34,7 +33,7 @@ struct StructProperty
|
|||||||
|
|
||||||
StructProperty():
|
StructProperty():
|
||||||
Name(""),
|
Name(""),
|
||||||
Type(Char),
|
Type(Integer),
|
||||||
Offset(0)
|
Offset(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user