Skip to content

Commit

Permalink
fix tpt.set_property again
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Mar 9, 2014
1 parent e594195 commit 7603da0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/lua/LegacyLuaAPI.cpp
Expand Up @@ -1118,14 +1118,10 @@ int luatpt_set_property(lua_State* l)
size_t offset;
acount = lua_gettop(l);
prop = luaL_optstring(l, 1, "");
i = abs(luaL_optint(l, 3, -1)); //x coord or particle index, depending on arguments
y = abs(luaL_optint(l, 4, -1));
w = abs(luaL_optint(l, 5, -1));
h = abs(luaL_optint(l, 6, -1));

CommandInterface::FormatType format;
offset = luacon_ci->GetPropertyOffset(prop, format);
if(offset == -1)
if (offset == -1)
return luaL_error(l, "Invalid property '%s'", prop);

if (acount > 2)
Expand Down Expand Up @@ -1153,16 +1149,23 @@ int luatpt_set_property(lua_State* l)
if ((t = luacon_ci->GetParticleType(std::string(name)))==-1)
return luaL_error(l, "Unrecognised element '%s'", name);
}
if (i == -1 || (w != -1 && h != -1))
if (!lua_isnumber(l, 3) || acount >= 6)
{
// Got a region
if (i == -1)
if (acount < 6)
{
i = 0;
y = 0;
w = XRES;
h = YRES;
}
else
{
i = abs(luaL_checkint(l, 3));
y = abs(luaL_checkint(l, 4));
w = abs(luaL_checkint(l, 5));
h = abs(luaL_checkint(l, 6));
}
if (i>=XRES || y>=YRES)
return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
x = i;
Expand All @@ -1189,9 +1192,11 @@ int luatpt_set_property(lua_State* l)
}
else
{
i = abs(luaL_checkint(l, 3));
// Got coords or particle index
if (i != -1 && y != -1)
if (lua_isnumber(l, 4))
{
y = abs(luaL_checkint(l, 4));
if (i>=XRES || y>=YRES)
return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
r = luacon_sim->pmap[y][i];
Expand Down

0 comments on commit 7603da0

Please sign in to comment.