From 7603da0242923d1d88ffbee666ed39cca2edab65 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 9 Mar 2014 15:31:32 -0400 Subject: [PATCH] fix tpt.set_property again --- src/lua/LegacyLuaAPI.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 504dcef46..4c9649189 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -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) @@ -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; @@ -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];