[dss-commits] r8760 - in dss/trunk/core: . scripting

dss-commits at forum.digitalstrom.org dss-commits at forum.digitalstrom.org
Mon Sep 14 10:39:29 CEST 2009


Author: pstaehlin
Date: 2009-09-14 10:39:28 +0200 (Mon, 14 Sep 2009)
New Revision: 8760

Modified:
   dss/trunk/core/jshandler.cpp
   dss/trunk/core/scripting/modeljs.cpp
Log:
Publish devices zoneID and circuitID in modeljs

Modified: dss/trunk/core/jshandler.cpp
===================================================================
--- dss/trunk/core/jshandler.cpp	2009-09-14 08:30:07 UTC (rev 8759)
+++ dss/trunk/core/jshandler.cpp	2009-09-14 08:39:28 UTC (rev 8760)
@@ -155,7 +155,8 @@
   };
 
   ScriptContext::ScriptContext(ScriptEnvironment& _env, JSContext* _pContext)
-  : m_Environment(_env),
+  : m_pScriptToExecute(NULL),
+    m_Environment(_env),
     m_pContext(_pContext)
   {
     JS_SetOptions(m_pContext, JSOPTION_VAROBJFIX | JSOPTION_DONT_REPORT_UNCAUGHT);
@@ -188,6 +189,9 @@
   } // dtor
 
   void ScriptContext::loadFromFile(const std::string& _fileName) {
+    if(m_pScriptToExecute != NULL) {
+      JS_DestroyScript(m_pContext, m_pScriptToExecute);
+    }
     m_FileName = _fileName;
     if(!fileExists(_fileName)) {
       throw ScriptException(std::string("File \"") + _fileName + "\" not found");
@@ -208,6 +212,9 @@
   } // loadFromFile
 
   void ScriptContext::loadFromMemory(const char* _script) {
+    if(m_pScriptToExecute != NULL) {
+      JS_DestroyScript(m_pContext, m_pScriptToExecute);
+    }
     m_pScriptToExecute = JS_CompileScript(m_pContext, m_pRootObject, _script, strlen(_script), "memory", 1);
     if(m_pScriptToExecute == NULL) {
       throw ScriptException(std::string("Could not parse in-memory script"));

Modified: dss/trunk/core/scripting/modeljs.cpp
===================================================================
--- dss/trunk/core/scripting/modeljs.cpp	2009-09-14 08:30:07 UTC (rev 8759)
+++ dss/trunk/core/scripting/modeljs.cpp	2009-09-14 08:39:28 UTC (rev 8760)
@@ -567,6 +567,12 @@
         case 2:
           *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dev->getDevice().getName().c_str()));
           return JS_TRUE;
+        case 3: 
+          *rval = INT_TO_JSVAL(dev->getDevice().getZoneID());
+          return JS_TRUE;
+        case 4:
+          *rval = INT_TO_JSVAL(dev->getDevice().getModulatorID());
+          return JS_TRUE;
       }
     }
     return JS_FALSE;
@@ -590,6 +596,8 @@
     {"className", 0, 0, dev_JSGet},
     {"dsid", 1, 0, dev_JSGet},
     {"name", 2, 0, dev_JSGet},
+    {"zoneID", 3, 0, dev_JSGet},
+    {"circuitID", 4, 0, dev_JSGet},
     {NULL}
   };
 



More information about the dss-commits mailing list