]> git.mxchange.org Git - flightgear.git/blob - src/Scripting/NasalSys.hxx
c1dfa92ad3483c8c3686c603916d228a4dd37a2b
[flightgear.git] / src / Scripting / NasalSys.hxx
1 #ifndef __NASALSYS_HXX
2 #define __NASALSYS_HXX
3
4 #include <simgear/misc/sg_path.hxx>
5 #include <simgear/structure/subsystem_mgr.hxx>
6 #include <simgear/nasal/nasal.h>
7
8 class FGNasalSys : public SGSubsystem
9 {
10 public:
11     FGNasalSys();
12     virtual ~FGNasalSys();
13     virtual void init();
14     virtual void update(double dt) { /* noop */ }
15
16     virtual bool handleCommand(const SGPropertyNode* arg);
17
18     // Simple hook to run arbitrary source code.  Returns a bool to
19     // indicate successful execution.  Does *not* return any Nasal
20     // values, because handling garbage-collected objects from C space
21     // is deep voodoo and violates the "simple hook" idea.
22     bool parseAndRun(const char* sourceCode);
23
24     // Implementation of the settimer extension function
25     void setTimer(naRef args);
26
27     // Returns a ghost wrapper for the current _cmdArg
28     naRef cmdArgGhost();
29     
30 private:
31     //
32     // FGTimer subclass for handling Nasal timer callbacks.
33     // See the implementation of the settimer() extension function for
34     // more notes.
35     //
36     struct NasalTimer {
37         virtual void timerExpired();
38         naRef handler;
39         int hashKey;
40         FGNasalSys* nasal;
41     };
42
43     void loadPropertyScripts();
44     void initModule(const char* moduleName, const char* fileName,
45                     const char* src, int len);
46     void readScriptFile(SGPath file, const char* lib);
47     void hashset(naRef hash, const char* key, naRef val);
48     void logError();
49     naRef parse(const char* filename, const char* buf, int len);
50     naRef genPropsModule();
51     naRef propNodeGhost(SGPropertyNode* handle);
52
53     naContext _context;
54     naRef _globals;
55     naRef _timerHash;
56
57     SGPropertyNode* _cmdArg;
58
59     int _nextTimerHashKey;
60
61 public:
62          void handleTimer(NasalTimer* t);
63 };
64
65 #endif // __NASALSYS_HXX