#include <Main/fg_props.hxx>
#include "NasalSys.hxx"
+#include "NasalDisplay.hxx"
// Read and return file contents in a single buffer. Note use of
// stat() to get the file size. This is a win32 function, believe it
return naNum(sg_random());
}
+static naRef f_srand(naContext c, naRef me, int argc, naRef* args)
+{
+ sg_srandom_time();
+ return naNum(0);
+}
+
+// Wrapper function for screenPrint
+static naRef f_screenPrint(naContext c, naRef me, int argc, naRef* args)
+{
+ if(argc != 1 || !naIsString(args[0]))
+ naRuntimeError(c, "bad arguments to screenPrint()");
+ naRef lmsg = args[0];
+ FGNasalSys* nasal = (FGNasalSys*)globals->get_subsystem("nasal");
+ nasal->screenPrint(naStr_data(lmsg));
+ return naNil();
+}
+
+// Return an array listing of all files in a directory
+static naRef f_directory(naContext c, naRef me, int argc, naRef* args)
+{
+ if(argc != 1 || !naIsString(args[0]))
+ naRuntimeError(c, "bad arguments to directory()");
+ naRef ldir = args[0];
+ ulDir* dir = ulOpenDir(naStr_data(args[0]));
+ if(!dir) return naNil();
+ naRef result = naNewVector(c);
+ ulDirEnt* dent;
+ while((dent = ulReadDir(dir)))
+ naVec_append(result, naStr_fromdata(naNewString(c), dent->d_name,
+ strlen(dent->d_name)));
+ ulCloseDir(dir);
+ return result;
+}
+
// Table of extension functions. Terminate with zeros.
static struct { char* name; naCFunction func; } funcs[] = {
{ "getprop", f_getprop },
{ "_cmdarg", f_cmdarg },
{ "_interpolate", f_interpolate },
{ "rand", f_rand },
+ { "srand", f_srand },
+ { "screenPrint", f_screenPrint },
+ { "directory", f_directory },
{ 0, 0 }
};
node->addChangeListener(new FGNasalListener(handler, this, gcSave(handler)));
}
+// functions providing access to the NasalDisplay - used to display text directly on the screen
+void FGNasalSys::screenPrint(const char* src)
+{
+ globals->get_Nasal_display()->RegisterSingleMessage(src, 0);
+}