static int tracker_new(lua_State * L) { const char * body = luaL_checkstring(L, 1); const char * ip = luaL_checkstring(L, 2); int port = luaL_optint(L, 3, 3883); Tracker * u = (Tracker*)lua_newuserdata(L, sizeof(Tracker)); sprintf(u->name, "%s@%s:%d", body, ip, port); if (u->open(u->name)) { luaL_getmetatable(L, "vrpn_Tracker_Remote"); lua_setmetatable(L, -2); // create environment table to hold pos, quat etc. lua_createtable(L, 0, 3); lua_pushinteger(L, 0); lua_setfield(L, -2, "sensor"); lua_createtable(L, 3, 0); lua_pushnumber(L, 0); lua_rawseti(L, -2, 1); lua_pushnumber(L, 0); lua_rawseti(L, -2, 2); lua_pushnumber(L, 0); lua_rawseti(L, -2, 3); lua_setfield(L, -2, "pos"); lua_createtable(L, 4, 0); lua_pushnumber(L, 0); lua_rawseti(L, -2, 1); lua_pushnumber(L, 0); lua_rawseti(L, -2, 2); lua_pushnumber(L, 0); lua_rawseti(L, -2, 3); lua_pushnumber(L, 1); lua_rawseti(L, -2, 4); lua_setfield(L, -2, "quat"); lua_setfenv(L, -2); return 1; } return 0; }
bool configure(ResourceFinder &rf) { return tracker.open(); }