summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-30 20:41:50 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-30 20:41:50 (GMT)
commitb7a2d38bdcee3bf85a32dea7ac74b144d5ef40fa (patch)
treebade629bcca6b6a1417cb45be4349a3c27ea0feb /src/uscxml/plugins/datamodel
parentafbd0c4463c6f28ec1cd6ea45a68fdbcfcfeae6c (diff)
downloaduscxml-b7a2d38bdcee3bf85a32dea7ac74b144d5ef40fa.zip
uscxml-b7a2d38bdcee3bf85a32dea7ac74b144d5ef40fa.tar.gz
uscxml-b7a2d38bdcee3bf85a32dea7ac74b144d5ef40fa.tar.bz2
See detailled log
- Forcing Data.Type for Data(String) constructor now, default used to be INTERPRETED. - setDataModel and addIOProcessor on interpreter now - fixed a bug with Data(bool) constructor - various smaller fixes
Diffstat (limited to 'src/uscxml/plugins/datamodel')
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp5
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp6
-rw-r--r--src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp147
-rw-r--r--src/uscxml/plugins/datamodel/lua/LuaDataModel.h2
-rw-r--r--src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp2
5 files changed, 88 insertions, 74 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
index 64b61af..6d15f72 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
@@ -474,16 +474,17 @@ void JSCDataModel::setForeach(const std::string& item,
// assign array element to item
std::stringstream ss;
ss << array << "[" << iteration << "]";
- assign(item, ss.str());
+ assign(item, Data(ss.str(), Data::INTERPRETED));
if (index.length() > 0) {
// assign iteration element to index
std::stringstream ss;
ss << iteration;
- assign(index, ss.str());
+ assign(index, Data(ss.str(), Data::INTERPRETED));
}
}
bool JSCDataModel::isLocation(const std::string& expr) {
+ // location needs to be RHS and ++ is only valid for RHS
JSStringRef scriptJS = JSStringCreateWithUTF8CString((expr + "++").c_str());
JSValueRef exception = NULL;
bool valid = JSCheckScriptSyntax(_ctx, scriptJS, NULL, 0, &exception);
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp
index f4bfabd..cd27126 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp
@@ -499,12 +499,12 @@ void V8DataModel::setForeach(const std::string& item,
// assign array element to item
std::stringstream ss;
ss << array << "[" << iteration << "]";
- assign(item, ss.str());
+ assign(item, Data(ss.str(), Data::INTERPRETED));
if (index.length() > 0) {
// assign iteration element to index
std::stringstream ss;
ss << iteration;
- assign(index, ss.str());
+ assign(index, Data(ss.str(), Data::INTERPRETED));
}
}
@@ -753,7 +753,7 @@ void V8DataModel::throwExceptionEvent(const v8::TryCatch& tryCatch) {
std::stringstream ssLineNumber;
int lineNumber = message->GetLineNumber();
ssLineNumber << lineNumber;
- exceptionEvent.data.compound["linenumber"] = Data(ssLineNumber.str());
+ exceptionEvent.data.compound["linenumber"] = Data(ssLineNumber.str(), Data::INTERPRETED);
int startColumn = message->GetStartColumn();
int endColumn = message->GetEndColumn();
diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
index 018a8c4..bf8b538 100644
--- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
@@ -44,14 +44,65 @@ bool pluginConnect(pluma::Host& host) {
}
#endif
-LuaDataModel::LuaDataModel() {
- _luaState = NULL;
-}
-
static int luaInspect(lua_State * l) {
return 0;
}
+static luabridge::LuaRef getDataAsLua(lua_State* _luaState, const Data& data) {
+ luabridge::LuaRef luaData (_luaState);
+
+ if (data.node) {
+ ERROR_EXECUTION_THROW("No DOM support in Lua datamodel");
+ }
+ if (data.compound.size() > 0) {
+ luaData = luabridge::newTable(_luaState);
+ std::map<std::string, Data>::const_iterator compoundIter = data.compound.begin();
+ while(compoundIter != data.compound.end()) {
+ luaData[compoundIter->first] = getDataAsLua(_luaState, compoundIter->second);
+ compoundIter++;
+ }
+ luaData["inspect"] = luaInspect;
+ return luaData;
+ }
+ if (data.array.size() > 0) {
+ luaData = luabridge::newTable(_luaState);
+ std::list<Data>::const_iterator arrayIter = data.array.begin();
+ uint32_t index = 0;
+ while(arrayIter != data.array.end()) {
+ luaData[index++] = getDataAsLua(_luaState, *arrayIter);
+ arrayIter++;
+ }
+ luaData["inspect"] = luaInspect;
+ return luaData;
+ }
+ if (data.atom.size() > 0) {
+ switch (data.type) {
+ case Data::VERBATIM: {
+// luaData = "\"" + data.atom + "\"";
+ luaData = data.atom;
+ break;
+ }
+ case Data::INTERPRETED: {
+ if (isNumeric(data.atom.c_str(), 10)) {
+ if (data.atom.find(".") != std::string::npos) {
+ luaData = strTo<double>(data.atom);
+ } else {
+ luaData = strTo<long>(data.atom);
+ }
+ } else {
+ luaData = data.atom;
+ }
+ }
+ }
+ return luaData;
+ }
+ return luaData;
+}
+
+LuaDataModel::LuaDataModel() {
+ _luaState = NULL;
+}
+
static int luaInFunction(lua_State * l) {
luabridge::LuaRef ref = luabridge::getGlobal(l, "__interpreter");
InterpreterImpl* interpreter = ref.cast<InterpreterImpl*>();
@@ -78,23 +129,22 @@ boost::shared_ptr<DataModelImpl> LuaDataModel::create(InterpreterImpl* interpret
luaL_openlibs(dm->_luaState);
luabridge::getGlobalNamespace(dm->_luaState).beginClass<InterpreterImpl>("Interpreter").endClass();
+ luabridge::setGlobal(dm->_luaState, dm->_interpreter, "__interpreter");
+
luabridge::getGlobalNamespace(dm->_luaState).addCFunction("In", luaInFunction);
-// luabridge::getGlobalNamespace(dm->_luaState)
-// .beginClass <uscxml::Event> ("Event")
-// .addProperty("name", &uscxml::Event::getName)
-// .addProperty("raw", &uscxml::Event::getRaw)
-// .addProperty("data", &uscxml::Event::getData)
-// .addProperty("xml", &uscxml::Event::getXML)
-// .addProperty("eventType", &uscxml::Event::getEventType)
-// .addProperty("origin", &uscxml::Event::getOrigin)
-// .addProperty("originType", &uscxml::Event::getOriginType)
-// .addProperty("content", &uscxml::Event::getContent)
-// .addProperty("invokeId", &uscxml::Event::getInvokeId)
-// .addProperty("sendId", &uscxml::Event::getSendId)
-// .endClass ();
+ luabridge::LuaRef ioProcTable = luabridge::newTable(dm->_luaState);
- luabridge::setGlobal(dm->_luaState, dm->_interpreter, "__interpreter");
+ std::map<std::string, IOProcessor>::const_iterator ioProcIter = dm->_interpreter->getIOProcessors().begin();
+ while(ioProcIter != dm->_interpreter->getIOProcessors().end()) {
+ Data ioProcData = ioProcIter->second.getDataModelVariables();
+ ioProcTable[ioProcIter->first] = getDataAsLua(dm->_luaState, ioProcData);
+ ioProcIter++;
+ }
+ luabridge::setGlobal(dm->_luaState, ioProcTable, "_ioprocessors");
+
+ luabridge::setGlobal(dm->_luaState, dm->_interpreter->getName(), "_name");
+ luabridge::setGlobal(dm->_luaState, dm->_interpreter->getSessionId(), "_sessionid");
return dm;
}
@@ -142,56 +192,6 @@ static Data getLuaAsData(const luabridge::LuaRef& lua) {
return data;
}
-static luabridge::LuaRef getDataAsLua(lua_State* _luaState, const Data& data) {
- luabridge::LuaRef luaData (_luaState);
-
- if (data.node) {
- ERROR_EXECUTION_THROW("No DOM support in Lua datamodel");
- }
- if (data.compound.size() > 0) {
- luaData = luabridge::newTable(_luaState);
- std::map<std::string, Data>::const_iterator compoundIter = data.compound.begin();
- while(compoundIter != data.compound.end()) {
- luaData[compoundIter->first] = getDataAsLua(_luaState, compoundIter->second);
- compoundIter++;
- }
- luaData["inspect"] = luaInspect;
- return luaData;
- }
- if (data.array.size() > 0) {
- luaData = luabridge::newTable(_luaState);
- std::list<Data>::const_iterator arrayIter = data.array.begin();
- uint32_t index = 0;
- while(arrayIter != data.array.end()) {
- luaData[index++] = getDataAsLua(_luaState, *arrayIter);
- arrayIter++;
- }
- luaData["inspect"] = luaInspect;
- return luaData;
- }
- if (data.atom.size() > 0) {
- switch (data.type) {
- case Data::VERBATIM: {
- luaData = "\"" + data.atom + "\"";
- break;
- }
- case Data::INTERPRETED: {
- if (isNumeric(data.atom.c_str(), 10)) {
- if (data.atom.find(".") != std::string::npos) {
- luaData = strTo<double>(data.atom);
- } else {
- luaData = strTo<long>(data.atom);
- }
- } else {
- luaData = data.atom;
- }
- }
- }
- return luaData;
- }
- return luaData;
-}
-
void LuaDataModel::setEvent(const Event& event) {
luabridge::LuaRef luaEvent(_luaState);
luaEvent = luabridge::newTable(_luaState);
@@ -471,5 +471,16 @@ std::string LuaDataModel::evalAsString(const std::string& expr) {
return "";
}
+std::string LuaDataModel::andExpressions(std::list<std::string> exprs) {
+ std::stringstream exprSS;
+ std::list<std::string>::const_iterator listIter;
+ std::string andExpr;
+ for (listIter = exprs.begin(); listIter != exprs.end(); listIter++) {
+ exprSS << andExpr << *listIter;
+ andExpr = " && ";
+ }
+ return exprSS.str();
+}
+
} \ No newline at end of file
diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h
index 828db0e..86e7e17 100644
--- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h
+++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h
@@ -85,6 +85,8 @@ public:
virtual std::string evalAsString(const std::string& expr);
virtual bool evalAsBool(const Arabica::DOM::Node<std::string>& node, const std::string& expr);
+ virtual std::string andExpressions(std::list<std::string>);
+
protected:
virtual int luaEval(const Arabica::DOM::Element<std::string>& scriptElem,
diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp
index c38842b..41e015e 100644
--- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp
@@ -269,7 +269,7 @@ Data XPathDataModel::getStringAsData(const std::string& content) {
std::string idx = ss.str();
ss.str("");
ss << ns[i];
- data.compound[idx] = Data(ss.str());
+ data.compound[idx] = Data(ss.str(), Data::INTERPRETED);
}
data.type = Data::INTERPRETED;
return data;