+ SGGeod pos = getPosition(ctx);
+
+ if( ctx.argc > 1 )
+ naRuntimeError(ctx.c, "airportinfo() with invalid function arguments");
+
+ // optional type/ident
+ std::string ident("airport");
+ if( ctx.isString(0) )
+ ident = ctx.requireArg<std::string>(0);
+
+ FGAirport::TypeRunwayFilter filter;
+ if( !filter.fromTypeString(ident) )
+ // user provided an <id>, hopefully
+ return ctx.to_nasal(FGAirport::findByIdent(ident));
+
+ double maxRange = 10000.0; // expose this? or pick a smaller value?
+ return ctx.to_nasal( FGAirport::findClosest(pos, maxRange, &filter) );
+}
+
+/**
+ * findAirportsWithinRange([<position>,] <range-nm> [, type])
+ */
+static naRef f_findAirportsWithinRange(nasal::CallContext ctx)
+{
+ SGGeod pos = getPosition(ctx);
+ double range_nm = ctx.requireArg<double>(0);
+
+ FGAirport::TypeRunwayFilter filter; // defaults to airports only
+ filter.fromTypeString( ctx.getArg<std::string>(1) );
+
+ FGPositionedList apts = FGPositioned::findWithinRange(pos, range_nm, &filter);
+ FGPositioned::sortByRange(apts, pos);
+
+ return ctx.to_nasal(apts);
+}
+
+/**
+ * findAirportsByICAO(<ident/prefix> [, type])
+ */
+static naRef f_findAirportsByICAO(nasal::CallContext ctx)
+{
+ std::string prefix = ctx.requireArg<std::string>(0);
+
+ FGAirport::TypeRunwayFilter filter; // defaults to airports only
+ filter.fromTypeString( ctx.getArg<std::string>(1) );
+
+ return ctx.to_nasal( FGPositioned::findAllWithIdent(prefix, &filter, false) );
+}
+
+// Returns vector of data hash for navaid of a <type>, nil on error
+// navaids sorted by ascending distance
+// navinfo([<lat>,<lon>],[<type>],[<id>])
+// lat/lon (numeric): use latitude/longitude instead of ac position
+// type: ("fix"|"vor"|"ndb"|"ils"|"dme"|"tacan"|"any")
+// id: (partial) id of the fix
+// examples:
+// navinfo("vor") returns all vors
+// navinfo("HAM") return all navaids who's name start with "HAM"
+// navinfo("vor", "HAM") return all vor who's name start with "HAM"
+//navinfo(34,48,"vor","HAM") return all vor who's name start with "HAM"
+// sorted by distance relative to lat=34, lon=48
+static naRef f_navinfo(nasal::CallContext ctx)
+{
+ SGGeod pos = getPosition(ctx);
+ std::string id = ctx.getArg<std::string>(0);
+
+ FGNavList::TypeFilter filter;
+ if( filter.fromTypeString(id) )
+ id = ctx.getArg<std::string>(1);
+ else if( ctx.argc > 1 )
+ naRuntimeError(ctx.c, "navinfo() already got an ident");
+
+ return ctx.to_nasal( FGNavList::findByIdentAndFreq(pos, id, 0.0, &filter) );