static int addPotential(lua_State* luaSt) { NBodyCtx* ctx; if (lua_gettop(luaSt) != 2) return luaL_argerror(luaSt, 1, "Expected named 2 arguments"); ctx = checkNBodyCtx(luaSt, 1); ctx->pot = *checkPotential(luaSt, 2); return 0; }
static int luaPrintReverseOrbit(lua_State* luaSt) { mwvector finalPos, finalVel; static real dt = 0.0; static real tstop = 0.0; static real tstopf = 0.0; static Potential* pot = NULL; static const mwvector* pos = NULL; static const mwvector* vel = NULL; //static mwbool SecondDisk = FALSE; static const MWNamedArg argTable[] = { { "potential", LUA_TUSERDATA, POTENTIAL_TYPE, TRUE, &pot }, { "position", LUA_TUSERDATA, MWVECTOR_TYPE, TRUE, &pos }, { "velocity", LUA_TUSERDATA, MWVECTOR_TYPE, TRUE, &vel }, { "tstop", LUA_TNUMBER, NULL, TRUE, &tstop }, { "tstopf", LUA_TNUMBER, NULL, TRUE, &tstopf }, { "dt", LUA_TNUMBER, NULL, TRUE, &dt }, END_MW_NAMED_ARG }; switch (lua_gettop(luaSt)) { case 1: handleNamedArgumentTable(luaSt, argTable, 1); break; case 6: pot = checkPotential(luaSt, 1); pos = checkVector(luaSt, 2); vel = checkVector(luaSt, 3); tstop = luaL_checknumber(luaSt, 4); tstopf = luaL_checknumber(luaSt, 5); dt = luaL_checknumber(luaSt, 6); break; default: return luaL_argerror(luaSt, 1, "Expected 1 or 6 arguments"); } /* Make sure precalculated constants ready for use */ if (checkPotentialConstants(pot)) luaL_error(luaSt, "Error with potential"); nbPrintReverseOrbit(&finalPos, &finalVel, pot, *pos, *vel, tstop, tstopf, dt); pushVector(luaSt, finalPos); pushVector(luaSt, finalVel); return 2; }