+static naRef f_procedure_route(naContext c, naRef me, int argc, naRef* args)
+{
+ Procedure* proc = procedureGhost(me);
+ if (!proc) {
+ naRuntimeError(c, "procedure.route called on non-procedure object");
+ }
+
+// wrapping up tow different routines here - approach routing from the IAF
+// to the associated runway, and SID/STAR routing via an enroute transition
+// and possibly a runway transition or not.
+ if (Approach::isApproach(proc->type())) {
+ WayptRef iaf;
+ if (argc > 0) {
+ iaf = wayptFromArg(args[0]);
+ }
+
+ WayptVec r;
+ Approach* app = (Approach*) proc;
+ if (!app->route(iaf, r)) {
+ SG_LOG(SG_NASAL, SG_WARN, "procedure.route failed for Approach somehow");
+ return naNil();
+ }
+
+ return convertWayptVecToNasal(c, r);
+ } else if ((proc->type() != PROCEDURE_SID) && (proc->type() != PROCEDURE_STAR)) {
+ naRuntimeError(c, "procedure.route called on unsuitable procedure type");
+ }
+
+ int argOffset = 0;
+ FGRunway* rwy = runwayGhost(args[0]);
+ if (rwy) ++argOffset;
+
+ ArrivalDeparture* ad = (ArrivalDeparture*) proc;
+ Transition* trans = NULL;
+ if (argOffset < argc) {
+ trans = (Transition*) procedureGhost(args[argOffset]);
+ }
+
+ // note either runway or trans may be NULL - that's ok
+ WayptVec r;
+ if (!ad->route(rwy, trans, r)) {
+ SG_LOG(SG_NASAL, SG_WARN, "prcoedure.route failed for ArrvialDeparture somehow");
+ return naNil();
+ }
+
+ return convertWayptVecToNasal(c, r);
+}
+
+