From b9c3eeae92c03bd33c0e917ff995d271b82a4ac7 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 18 Dec 2015 02:07:16 -0500 Subject: [PATCH] Allow old lua scripts which use state to work --- src/lua/LegacyLuaAPI.cpp | 6 ++++-- src/lua/LuaScriptInterface.cpp | 30 +++++++++++++++++++---------- src/simulation/StructProperty.h | 2 +- src/simulation/elements/Element.cpp | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index deebccf2af..6f05718846 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -309,8 +309,8 @@ int luacon_element_getproperty(const char * key, int * format, unsigned int * mo *format = 3; } else if (!strcmp(key, "state")) { - offset = offsetof(Element, State); - *format = 3; + offset = 0; + *format = -1; } else if (!strcmp(key, "properties")) { offset = offsetof(Element, Properties); @@ -370,6 +370,8 @@ int luacon_elementread(lua_State* l) tempinteger = *((unsigned char*)(((unsigned char*)&luacon_sim->elements[i])+offset)); lua_pushnumber(l, tempinteger); break; + default: + lua_pushnumber(l, 0); } return 1; } diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 059a6856df..3fd2801ea1 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1015,11 +1015,13 @@ int LuaScriptInterface::simulation_partProperty(lua_State * l) *((char**)propertyAddress) = strdup(lua_tostring(l, 3)); break; case StructProperty::Colour: - #if PIXELSIZE == 4 +#if PIXELSIZE == 4 *((unsigned int*)propertyAddress) = lua_tointeger(l, 3); - #else +#else *((unsigned short*)propertyAddress) = lua_tointeger(l, 3); - #endif +#endif + break; + case StructProperty::Removed: break; } return 0; @@ -2234,10 +2236,14 @@ void LuaScriptInterface::initElementsAPI() SETCONST(l, FLAG_SKIPMOVE); SETCONST(l, FLAG_MOVABLE); SETCONST(l, FLAG_PHOTDECO); - SETCONST(l, ST_NONE); - SETCONST(l, ST_SOLID); - SETCONST(l, ST_LIQUID); - SETCONST(l, ST_GAS); + lua_pushinteger(l, 0); + lua_setfield(l, -2, "ST_NONE"); + lua_pushinteger(l, 0); + lua_setfield(l, -2, "ST_SOLID"); + lua_pushinteger(l, 0); + lua_setfield(l, -2, "ST_LIQUID"); + lua_pushinteger(l, 0); + lua_setfield(l, -2, "ST_GAS"); SETCONST(l, SC_WALL); SETCONST(l, SC_ELEC); @@ -2421,9 +2427,11 @@ int LuaScriptInterface::elements_element(lua_State * l) *((unsigned short*)(((unsigned char*)&luacon_sim->elements[id])+offset)) = lua_tointeger(l, -1); #endif break; + case StructProperty::Removed: + break; } - lua_pop(l, 1); } + lua_pop(l, 1); } lua_getfield(l, -1, "Update"); @@ -2497,8 +2505,8 @@ int LuaScriptInterface::elements_element(lua_State * l) lua_pushinteger(l, *((unsigned short*)(((unsigned char*)&luacon_sim->elements[id])+offset))); #endif break; - default: - lua_pushnil(l); + case StructProperty::Removed: + continue; } lua_setfield(l, -2, (*iter).Name.c_str()); } @@ -2570,6 +2578,8 @@ int LuaScriptInterface::elements_property(lua_State * l) *((unsigned short*)(((unsigned char*)&luacon_sim->elements[id])+offset)) = luaL_checkinteger(l, 3); #endif break; + case StructProperty::Removed: + break; } } diff --git a/src/simulation/StructProperty.h b/src/simulation/StructProperty.h index 06444e25f9..74816e88f2 100644 --- a/src/simulation/StructProperty.h +++ b/src/simulation/StructProperty.h @@ -6,7 +6,7 @@ struct StructProperty { - enum PropertyType { ParticleType, Colour, Integer, UInteger, Float, String, Char, UChar }; + enum PropertyType { ParticleType, Colour, Integer, UInteger, Float, String, Char, UChar, Removed }; std::string Name; PropertyType Type; intptr_t Offset; diff --git a/src/simulation/elements/Element.cpp b/src/simulation/elements/Element.cpp index 6ab808c2f5..f4c472a326 100644 --- a/src/simulation/elements/Element.cpp +++ b/src/simulation/elements/Element.cpp @@ -72,7 +72,7 @@ std::vector Element::GetProperties() properties.push_back(StructProperty("Temperature", StructProperty::Float, offsetof(Element, Temperature))); properties.push_back(StructProperty("HeatConduct", StructProperty::UChar, offsetof(Element, HeatConduct))); properties.push_back(StructProperty("Description", StructProperty::String, offsetof(Element, Description))); - //properties.push_back(StructProperty("State", StructProperty::Char, offsetof(Element, State))); + properties.push_back(StructProperty("State", StructProperty::Removed, 0)); properties.push_back(StructProperty("Properties", StructProperty::Integer, offsetof(Element, Properties))); properties.push_back(StructProperty("LowPressure", StructProperty::Float, offsetof(Element, LowPressure))); properties.push_back(StructProperty("LowPressureTransition", StructProperty::Integer, offsetof(Element, LowPressureTransition)));