Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow old lua scripts which use state to work
  • Loading branch information
jacob1 committed Dec 18, 2015
1 parent 95ab91e commit b9c3eea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/lua/LegacyLuaAPI.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
30 changes: 20 additions & 10 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/simulation/StructProperty.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/Element.cpp
Expand Up @@ -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)));
Expand Down

0 comments on commit b9c3eea

Please sign in to comment.