//...
int Interpreter::v_create_thrustergroup (lua_State *L)
{
static const char *funcname = "create_thrustergroup";
AssertMtdMinPrmCount(L, 2, funcname);
VESSEL *v = lua_tovessel_safe(L, 1, funcname);
AssertMtdPrmType(L, 2, PRMTP_TABLE, funcname);
THGROUP_TYPE thgt;
if (lua_gettop(L) >= 3) {
thgt = (THGROUP_TYPE)luamtd_tointeger_safe(L, 3, funcname);
} else {
thgt = THGROUP_USER;
}
// traverse the thruster array
static int nht = 1;
static THRUSTER_HANDLE *ht = new THRUSTER_HANDLE[nht];
lua_pushnil(L);
int i = 0;
while (lua_next(L,2)) {
if (i >= nht) {
THRUSTER_HANDLE *tmp = new THRUSTER_HANDLE[i+1];
memcpy(tmp, ht, nht*sizeof(THRUSTER_HANDLE));
delete []ht;
ht = tmp;
nht = i+1;
}
ht[i++] = (THRUSTER_HANDLE)lua_touserdata(L,-1);
lua_pop(L,1);
}
lua_pop(L,1);
THGROUP_HANDLE htg = v->CreateThrusterGroup (ht, i, thgt);
lua_pushlightuserdata(L,htg);
return 1;
}
//...