]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalSys.hxx
Clean-up: move autosave.xml loading code to proper method
[flightgear.git] / src / Scripting / NasalSys.hxx
index 99ef409d6050d858e318916a5caa7e51211dc95f..ceff996dab1531375abb4d1243424db55e8e8933 100644 (file)
@@ -3,12 +3,13 @@
 
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/misc/sg_dir.hxx>
 #include <simgear/nasal/nasal.h>
-#include <simgear/scene/model/model.hxx>
+#include <simgear/scene/model/modellib.hxx>
 #include <simgear/xml/easyxml.hxx>
 
 #include <map>
-SG_USING_STD(map);
+using std::map;
 
 
 class FGNasalScript;
@@ -24,7 +25,7 @@ public:
 
     // Loads a nasal script from an external file and inserts it as a
     // global module of the specified name.
-    void loadModule(SGPath file, const char* moduleName);
+    bool loadModule(SGPath file, const char* moduleName);
 
     // Simple hook to run arbitrary source code.  Returns a bool to
     // indicate successful execution.  Does *not* return any Nasal
@@ -53,16 +54,19 @@ public:
     // Callbacks for command and timer bindings
     virtual bool handleCommand(const SGPropertyNode* arg);
 
-    void createModule(const char* moduleName, const char* fileName,
-                    const char* src, int len, const SGPropertyNode* arg=0);
+    bool createModule(const char* moduleName, const char* fileName,
+                      const char* src, int len, const SGPropertyNode* cmdarg=0,
+                      int argc=0, naRef*args=0);
 
     void deleteModule(const char* moduleName);
 
-    naRef call(naRef code, naRef locals);
+    naRef call(naRef code, int argc, naRef* args, naRef locals);
+    naRef propNodeGhost(SGPropertyNode* handle);
 
 private:
     friend class FGNasalScript;
     friend class FGNasalListener;
+    friend class FGNasalModuleListener;
 
     //
     // FGTimer subclass for handling Nasal timer callbacks.
@@ -79,15 +83,17 @@ private:
 
     // Listener
     map<int, FGNasalListener *> _listener;
+    vector<FGNasalListener *> _dead_listener;
     static int _listenerId;
-    bool _purgeListeners;
 
     void loadPropertyScripts();
+    void loadPropertyScripts(SGPropertyNode* n);
+    void loadScriptDirectory(simgear::Dir nasalDir);
+    void addModule(string moduleName, simgear::PathList scripts);
     void hashset(naRef hash, const char* key, naRef val);
     void logError(naContext);
     naRef parse(const char* filename, const char* buf, int len);
     naRef genPropsModule();
-    naRef propNodeGhost(SGPropertyNode* handle);
 
     // This mechanism is here to allow naRefs to be passed to
     // locations "outside" the interpreter.  Normally, such a
@@ -131,39 +137,44 @@ private:
 
 class FGNasalListener : public SGPropertyChangeListener {
 public:
-    FGNasalListener(SGPropertyNode_ptr node, naRef handler,
-                    FGNasalSys* nasal, int key, int id, bool persistent);
+    FGNasalListener(SGPropertyNode* node, naRef code, FGNasalSys* nasal,
+                    int key, int id, int init, int type);
 
-    ~FGNasalListener();
-    void valueChanged(SGPropertyNode* node);
-    bool changed(SGPropertyNode* node);
+    virtual ~FGNasalListener();
+    virtual void valueChanged(SGPropertyNode* node);
+    virtual void childAdded(SGPropertyNode* parent, SGPropertyNode* child);
+    virtual void childRemoved(SGPropertyNode* parent, SGPropertyNode* child);
 
 private:
+    bool changed(SGPropertyNode* node);
+    void call(SGPropertyNode* which, naRef mode);
+
     friend class FGNasalSys;
     SGPropertyNode_ptr _node;
-    naRef _handler;
+    naRef _code;
     int _gcKey;
     int _id;
     FGNasalSys* _nas;
+    int _init;
+    int _type;
     unsigned int _active;
     bool _dead;
-    bool _first_call;
-    bool _persistent;
     long _last_int;
     double _last_float;
     string _last_string;
 };
 
 
-class FGNasalModelData : public SGModelData {
+class FGNasalModelData : public simgear::SGModelData {
 public:
-    FGNasalModelData(SGPropertyNode *props = 0) : _props(props), _unload(0) {}
+    FGNasalModelData(SGPropertyNode *root = 0) : _root(root), _unload(0) {}
     ~FGNasalModelData();
     void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *);
 
 private:
+    static unsigned int _module_id;
     string _module;
-    SGPropertyNode_ptr _props;
+    SGPropertyNode_ptr _root;
     SGConstPropertyNode_ptr _unload;
 };