Nicer implementation of sim.parts

This commit is contained in:
Tamás Bálint Misius 2019-09-15 22:14:46 +02:00
parent 28d5345bf9
commit 51b78be139
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -1888,27 +1888,6 @@ int LuaScriptInterface::simulation_canMove(lua_State * l)
}
}
int PartsClosure(lua_State * l)
{
int i = lua_tointeger(l, lua_upvalueindex(1));
do
{
if (++i >= NPART)
return 0;
} while (!luacon_sim->parts[i].type);
lua_pushnumber(l, i);
lua_replace(l, lua_upvalueindex(1));
lua_pushnumber(l, i);
return 1;
}
int LuaScriptInterface::simulation_parts(lua_State * l)
{
lua_pushnumber(l, -1);
lua_pushcclosure(l, PartsClosure, 1);
return 1;
}
int BrushClosure(lua_State * l)
{
// see Simulation::ToolBrush
@ -2004,6 +1983,28 @@ int LuaScriptInterface::simulation_brush(lua_State * l)
return 1;
}
int PartsClosure(lua_State *l)
{
for (int i = lua_tointeger(l, lua_upvalueindex(1)); i <= luacon_sim->parts_lastActiveIndex; ++i)
{
if (luacon_sim->parts[i].type)
{
lua_pushnumber(l, i + 1);
lua_replace(l, lua_upvalueindex(1));
lua_pushnumber(l, i);
return 1;
}
}
return 0;
}
int LuaScriptInterface::simulation_parts(lua_State *l)
{
lua_pushnumber(l, 0);
lua_pushcclosure(l, PartsClosure, 1);
return 1;
}
int LuaScriptInterface::simulation_pmap(lua_State * l)
{
int x = luaL_checkint(l, 1);