From 80fd7edd7f6ddb6f02c756f63ede818c9940c0f5 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 2 Jul 2011 20:40:29 +0800 Subject: [PATCH] Some fixes for non-existent particles in Lua Return 0 for get_property("type", ...) instead of erroring, to make checking for particles easier. Also stop x coordinate being used as a particle index if no particle exists at that location. --- src/luaconsole.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/luaconsole.c b/src/luaconsole.c index ba8529de3..22e528bc3 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -455,6 +455,8 @@ int luatpt_set_property(lua_State* l) r = pmap[y][i]; if (!r || (r>>8)>=NPART || (partsel && partsel != parts[r>>8].type)) r = photons[y][i]; + if (!r || (r>>8)>=NPART || (partsel && partsel != parts[r>>8].type)) + return 0; i = r>>8; } if (i < 0 || i >= NPART) @@ -483,6 +485,14 @@ int luatpt_get_property(lua_State* l) r = pmap[y][i]; if (!r || (r>>8)>=NPART) r = photons[y][i]; + if (!r || (r>>8)>=NPART) + { + if (strcmp(prop,"type")==0){ + lua_pushinteger(l, 0); + return 1; + } + return luaL_error(l, "Particle does not exist"); + } i = r>>8; } else if (y!=-1) @@ -528,7 +538,11 @@ int luatpt_get_property(lua_State* l) return 1; } } - return luaL_error(l, "Particle does not exist", i); + else if (strcmp(prop,"type")==0){ + lua_pushinteger(l, 0); + return 1; + } + return luaL_error(l, "Particle does not exist"); } int luatpt_drawpixel(lua_State* l)