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;
}
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;
}

View File

@ -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;
}
}

View File

@ -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;

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("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)));