summaryrefslogtreecommitdiff
path: root/src/cat/LuaScriptInterface.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-28 15:12:30 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-28 15:12:30 (GMT)
commit07a66dc3dc48197236c3bdb8240b271db465d60f (patch)
tree8d448273f2f8c029faa06247e195ee93be0f41db /src/cat/LuaScriptInterface.cpp
parent92f3ad5814fcf77da7782f4664d4041370a41884 (diff)
downloadpowder-07a66dc3dc48197236c3bdb8240b271db465d60f.zip
powder-07a66dc3dc48197236c3bdb8240b271db465d60f.tar.gz
tpt.element also converts numbers to names
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
-rw-r--r--src/cat/LuaScriptInterface.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 9d563a8..4561d5d 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -936,10 +936,20 @@ int luatpt_test(lua_State* l)
int luatpt_getelement(lua_State *l)
{
int t;
- 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);
+ if(lua_isnumber(l, 1))
+ {
+ t = luaL_optint(l, 1, 1);
+ 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;
}