tpt.element also converts numbers to names

This commit is contained in:
Simon Robertshaw 2012-08-28 16:12:30 +01:00
parent 92f3ad5814
commit 07a66dc3dc

View File

@ -936,10 +936,20 @@ int luatpt_test(lua_State* l)
int luatpt_getelement(lua_State *l) int luatpt_getelement(lua_State *l)
{ {
int t; int t;
char * name = (char*)luaL_optstring(l, 1, "dust"); if(lua_isnumber(l, 1))
if ((t = luacon_ci->GetParticleType(name))==-1) {
return luaL_error(l,"Unrecognised element '%s'", name); t = luaL_optint(l, 1, 1);
lua_pushinteger(l, t); if (t<0 || t>=PT_NUM)
return luaL_error(l, "Unrecognised element number '%d'", t);
lua_pushstring(l, luacon_sim->elements[t].Name);
}
else
{
char* name = (char*)luaL_optstring(l, 1, "dust");
if ((t = luacon_ci->GetParticleType(name))==-1)
return luaL_error(l, "Unrecognised element '%s'", name);
lua_pushinteger(l, t);
}
return 1; return 1;
} }