2003-11-25 21:08:36 +00:00
|
|
|
#ifndef __NASALSYS_HXX
|
|
|
|
#define __NASALSYS_HXX
|
|
|
|
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
|
|
#include <simgear/nasal/nasal.h>
|
|
|
|
|
|
|
|
class FGNasalSys : public SGSubsystem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FGNasalSys();
|
|
|
|
virtual ~FGNasalSys();
|
|
|
|
virtual void init();
|
|
|
|
virtual void update(double dt) { /* noop */ }
|
|
|
|
|
|
|
|
virtual bool handleCommand(const SGPropertyNode* arg);
|
|
|
|
|
2003-12-01 14:35:49 +00:00
|
|
|
// Simple hook to run arbitrary source code. Returns a bool to
|
|
|
|
// indicate successful execution. Does *not* return any Nasal
|
|
|
|
// values, because handling garbage-collected objects from C space
|
|
|
|
// is deep voodoo and violates the "simple hook" idea.
|
|
|
|
bool parseAndRun(const char* sourceCode);
|
|
|
|
|
2003-11-25 21:08:36 +00:00
|
|
|
// Implementation of the settimer extension function
|
|
|
|
void setTimer(naRef args);
|
|
|
|
|
2003-12-01 14:35:49 +00:00
|
|
|
// Returns a ghost wrapper for the current _cmdArg
|
|
|
|
naRef cmdArgGhost();
|
|
|
|
|
2003-11-25 21:08:36 +00:00
|
|
|
private:
|
|
|
|
//
|
|
|
|
// FGTimer subclass for handling Nasal timer callbacks.
|
|
|
|
// See the implementation of the settimer() extension function for
|
|
|
|
// more notes.
|
|
|
|
//
|
|
|
|
struct NasalTimer {
|
|
|
|
virtual void timerExpired();
|
|
|
|
naRef handler;
|
|
|
|
int hashKey;
|
|
|
|
FGNasalSys* nasal;
|
|
|
|
};
|
|
|
|
|
2003-12-01 14:35:49 +00:00
|
|
|
void loadPropertyScripts();
|
|
|
|
void initModule(const char* moduleName, const char* fileName,
|
|
|
|
const char* src, int len);
|
2003-11-25 21:08:36 +00:00
|
|
|
void readScriptFile(SGPath file, const char* lib);
|
|
|
|
void hashset(naRef hash, const char* key, naRef val);
|
|
|
|
void logError();
|
|
|
|
naRef parse(const char* filename, const char* buf, int len);
|
2003-12-01 14:35:49 +00:00
|
|
|
naRef genPropsModule();
|
|
|
|
naRef propNodeGhost(SGPropertyNode* handle);
|
2003-11-25 21:08:36 +00:00
|
|
|
|
|
|
|
naContext _context;
|
|
|
|
naRef _globals;
|
|
|
|
naRef _timerHash;
|
|
|
|
|
2003-12-01 14:35:49 +00:00
|
|
|
SGPropertyNode* _cmdArg;
|
|
|
|
|
2003-11-25 21:08:36 +00:00
|
|
|
int _nextTimerHashKey;
|
2003-11-27 14:34:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
void handleTimer(NasalTimer* t);
|
2003-11-25 21:08:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __NASALSYS_HXX
|