#include <Main/fg_props.hxx>
#include <Main/util.hxx>
#include <Scenery/scenery.hxx>
+#include <Navaids/navrecord.hxx>
#include "NasalSys.hxx"
// nil if it doesn't exist.
static naRef f_getprop(naContext c, naRef me, int argc, naRef* args)
{
+ using namespace simgear;
const SGPropertyNode* p = findnode(c, args, argc);
if(!p) return naNil();
switch(p->getType()) {
- case SGPropertyNode::BOOL: case SGPropertyNode::INT:
- case SGPropertyNode::LONG: case SGPropertyNode::FLOAT:
- case SGPropertyNode::DOUBLE:
+ case props::BOOL: case props::INT:
+ case props::LONG: case props::FLOAT:
+ case props::DOUBLE:
return naNum(p->getDoubleValue());
- case SGPropertyNode::STRING:
- case SGPropertyNode::UNSPECIFIED:
+ case props::STRING:
+ case props::UNSPECIFIED:
{
naRef nastr = naNewString(c);
const char* val = p->getStringValue();
naStr_fromdata(nastr, (char*)val, strlen(val));
return nastr;
}
- case SGPropertyNode::ALIAS: // <--- FIXME, recurse?
+ case props::ALIAS: // <--- FIXME, recurse?
default:
return naNil();
}
buf[BUFLEN] = 0;
char* p = buf;
int buflen = BUFLEN;
+ if(argc < 2) naRuntimeError(c, "setprop() expects at least 2 arguments");
for(int i=0; i<argc-1; i++) {
naRef s = naStringValue(c, args[i]);
if(naIsNil(s)) return naNil();
return result;
}
+/**
+ * Given a data path, resolve it in FG_ROOT or an FG_AIRCRFT directory
+ */
+static naRef f_resolveDataPath(naContext c, naRef me, int argc, naRef* args)
+{
+ if(argc != 1 || !naIsString(args[0]))
+ naRuntimeError(c, "bad arguments to resolveDataPath()");
+
+ SGPath p = globals->resolve_maybe_aircraft_path(naStr_data(args[0]));
+ const char* pdata = p.c_str();
+ return naStr_fromdata(naNewString(c), const_cast<char*>(pdata), strlen(pdata));
+}
+
// Parse XML file.
// parsexml(<path> [, <start-tag> [, <end-tag> [, <data> [, <pi>]]]]);
//
// Return UNIX epoch time in seconds.
static naRef f_systime(naContext c, naRef me, int argc, naRef* args)
{
-#ifdef WIN32
+#ifdef _WIN32
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
double t = (4294967296.0 * ft.dwHighDateTime + ft.dwLowDateTime);
// user provided an <id>, hopefully
apt = FGAirport::findByIdent(s);
if (!apt) {
- naRuntimeError(c, "airportinfo() couldn't find airport: %s", s);
+ // return nil here, but don't raise a runtime error; this is a
+ // legitamate way to validate an ICAO code, for example in a
+ // dialog box or similar.
return naNil();
}
}
HASHSET("width", 5, naNum(rwy->widthM()));
HASHSET("threshold", 9, naNum(rwy->displacedThresholdM()));
HASHSET("stopway", 7, naNum(rwy->stopwayM()));
+
+ if (rwy->ILS()) {
+ HASHSET("ils_frequency_mhz", 17, naNum(rwy->ILS()->get_freq() / 100.0));
+ }
+
#undef HASHSET
naHash_set(rwys, rwyid, rwydata);
}
{ "srand", f_srand },
{ "abort", f_abort },
{ "directory", f_directory },
+ { "resolvepath", f_resolveDataPath },
{ "parsexml", f_parsexml },
{ "systime", f_systime },
{ "carttogeod", f_carttogeod },
while((fn = n->getChild("file", j)) != NULL) {
file_specified = true;
const char* file = fn->getStringValue();
- SGPath p(globals->get_fg_root());
- p.append(file);
+ SGPath p = globals->resolve_maybe_aircraft_path(file);
loadModule(p, module);
j++;
}
const char* src = n->getStringValue("script");
if(!n->hasChild("script")) src = 0; // Hrm...
if(src)
- createModule(module, n->getPath(), src, strlen(src));
+ createModule(module, n->getPath().c_str(), src, strlen(src));
if(!file_specified && !src)
SG_LOG(SG_NASAL, SG_ALERT, "Nasal error: " <<
{
const char* nasal = arg->getStringValue("script");
const char* moduleName = arg->getStringValue("module");
- naRef code = parse(arg->getPath(true), nasal, strlen(nasal));
+ naRef code = parse(arg->getPath(true).c_str(), nasal, strlen(nasal));
if(naIsNil(code)) return false;
// Commands can be run "in" a module. Make sure that module
bool FGNasalListener::changed(SGPropertyNode* node)
{
- SGPropertyNode::Type type = node->getType();
- if(type == SGPropertyNode::NONE) return false;
- if(type == SGPropertyNode::UNSPECIFIED) return true;
+ using namespace simgear;
+ props::Type type = node->getType();
+ if(type == props::NONE) return false;
+ if(type == props::UNSPECIFIED) return true;
bool result;
switch(type) {
- case SGPropertyNode::BOOL:
- case SGPropertyNode::INT:
- case SGPropertyNode::LONG:
+ case props::BOOL:
+ case props::INT:
+ case props::LONG:
{
long l = node->getLongValue();
result = l != _last_int;
_last_int = l;
return result;
}
- case SGPropertyNode::FLOAT:
- case SGPropertyNode::DOUBLE:
+ case props::FLOAT:
+ case props::DOUBLE:
{
double d = node->getDoubleValue();
result = d != _last_float;
arg[1] = nasalSys->propNodeGhost(prop);
nasalSys->createModule(_module.c_str(), path.c_str(), s, strlen(s),
_root, 2, arg);
- _props = 0;
}
FGNasalModelData::~FGNasalModelData()