Nicer implementation of sim.parts
This commit is contained in:
parent
28d5345bf9
commit
51b78be139
@ -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);
|
||||
|
Reference in New Issue
Block a user