Allow old lua scripts which use state to work

This commit is contained in:
jacob1 2015-12-18 02:07:16 -05:00
parent 95ab91e91d
commit b9c3eeae92
4 changed files with 26 additions and 14 deletions

View File

@ -309,8 +309,8 @@ int luacon_element_getproperty(const char * key, int * format, unsigned int * mo
*format = 3; *format = 3;
} }
else if (!strcmp(key, "state")) { else if (!strcmp(key, "state")) {
offset = offsetof(Element, State); offset = 0;
*format = 3; *format = -1;
} }
else if (!strcmp(key, "properties")) { else if (!strcmp(key, "properties")) {
offset = offsetof(Element, 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)); tempinteger = *((unsigned char*)(((unsigned char*)&luacon_sim->elements[i])+offset));
lua_pushnumber(l, tempinteger); lua_pushnumber(l, tempinteger);
break; break;
default:
lua_pushnumber(l, 0);
} }
return 1; return 1;
} }

View File

@ -1015,11 +1015,13 @@ int LuaScriptInterface::simulation_partProperty(lua_State * l)
*((char**)propertyAddress) = strdup(lua_tostring(l, 3)); *((char**)propertyAddress) = strdup(lua_tostring(l, 3));
break; break;
case StructProperty::Colour: case StructProperty::Colour:
#if PIXELSIZE == 4 #if PIXELSIZE == 4
*((unsigned int*)propertyAddress) = lua_tointeger(l, 3); *((unsigned int*)propertyAddress) = lua_tointeger(l, 3);
#else #else
*((unsigned short*)propertyAddress) = lua_tointeger(l, 3); *((unsigned short*)propertyAddress) = lua_tointeger(l, 3);
#endif #endif
break;
case StructProperty::Removed:
break; break;
} }
return 0; return 0;
@ -2234,10 +2236,14 @@ void LuaScriptInterface::initElementsAPI()
SETCONST(l, FLAG_SKIPMOVE); SETCONST(l, FLAG_SKIPMOVE);
SETCONST(l, FLAG_MOVABLE); SETCONST(l, FLAG_MOVABLE);
SETCONST(l, FLAG_PHOTDECO); SETCONST(l, FLAG_PHOTDECO);
SETCONST(l, ST_NONE); lua_pushinteger(l, 0);
SETCONST(l, ST_SOLID); lua_setfield(l, -2, "ST_NONE");
SETCONST(l, ST_LIQUID); lua_pushinteger(l, 0);
SETCONST(l, ST_GAS); 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_WALL);
SETCONST(l, SC_ELEC); 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); *((unsigned short*)(((unsigned char*)&luacon_sim->elements[id])+offset)) = lua_tointeger(l, -1);
#endif #endif
break; break;
case StructProperty::Removed:
break;
} }
lua_pop(l, 1);
} }
lua_pop(l, 1);
} }
lua_getfield(l, -1, "Update"); 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))); lua_pushinteger(l, *((unsigned short*)(((unsigned char*)&luacon_sim->elements[id])+offset)));
#endif #endif
break; break;
default: case StructProperty::Removed:
lua_pushnil(l); continue;
} }
lua_setfield(l, -2, (*iter).Name.c_str()); 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); *((unsigned short*)(((unsigned char*)&luacon_sim->elements[id])+offset)) = luaL_checkinteger(l, 3);
#endif #endif
break; break;
case StructProperty::Removed:
break;
} }
} }

View File

@ -6,7 +6,7 @@
struct StructProperty 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; std::string Name;
PropertyType Type; PropertyType Type;
intptr_t Offset; intptr_t Offset;

View File

@ -72,7 +72,7 @@ std::vector<StructProperty> Element::GetProperties()
properties.push_back(StructProperty("Temperature", StructProperty::Float, offsetof(Element, Temperature))); properties.push_back(StructProperty("Temperature", StructProperty::Float, offsetof(Element, Temperature)));
properties.push_back(StructProperty("HeatConduct", StructProperty::UChar, offsetof(Element, HeatConduct))); properties.push_back(StructProperty("HeatConduct", StructProperty::UChar, offsetof(Element, HeatConduct)));
properties.push_back(StructProperty("Description", StructProperty::String, offsetof(Element, Description))); 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("Properties", StructProperty::Integer, offsetof(Element, Properties)));
properties.push_back(StructProperty("LowPressure", StructProperty::Float, offsetof(Element, LowPressure))); properties.push_back(StructProperty("LowPressure", StructProperty::Float, offsetof(Element, LowPressure)));
properties.push_back(StructProperty("LowPressureTransition", StructProperty::Integer, offsetof(Element, LowPressureTransition))); properties.push_back(StructProperty("LowPressureTransition", StructProperty::Integer, offsetof(Element, LowPressureTransition)));