diff options
| author | jacksonmj <mj-pt@jacksonmj.co.uk> | 2011-07-02 12:40:29 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-07-03 16:11:43 (GMT) |
| commit | 80fd7edd7f6ddb6f02c756f63ede818c9940c0f5 (patch) | |
| tree | 42e96782c296c7f9a259b7aecf8baf6ba620c89e /src | |
| parent | 25a2b52b64a3cbe52f4d9d1b2f39360a29b92c62 (diff) | |
| download | powder-80fd7edd7f6ddb6f02c756f63ede818c9940c0f5.zip powder-80fd7edd7f6ddb6f02c756f63ede818c9940c0f5.tar.gz | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luaconsole.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/luaconsole.c b/src/luaconsole.c index ba8529d..22e528b 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) |
