From afbd0c4463c6f28ec1cd6ea45a68fdbcfcfeae6c Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 23 Jul 2014 22:34:15 +0200 Subject: More work on lua datamodel --- README.md | 11 ++- apps/uscxml-dot.cpp | 59 +++++++----- docs/BUILDING.md | 21 +++++ src/uscxml/Interpreter.cpp | 2 +- src/uscxml/UUID.cpp | 36 ++++---- src/uscxml/debug/SCXMLDotWriter.cpp | 108 +++++++++++----------- src/uscxml/debug/SCXMLDotWriter.h | 22 ++--- src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 81 ++++++++-------- src/uscxml/plugins/datamodel/lua/LuaDataModel.h | 12 +-- test/src/test-vxml-mmi-socket.cpp | 12 +-- test/w3c/lua/test176.scxml | 5 + test/w3c/lua/test178.scxml | 4 +- test/w3c/lua/test183.scxml | 2 +- test/w3c/lua/test187.scxml | 4 +- test/w3c/lua/test223.scxml | 2 +- test/w3c/lua/test224.scxml | 2 +- test/w3c/lua/test225.scxml | 4 +- test/w3c/lua/test463.scxml | 14 --- test/w3c/lua/test464.scxml | 13 --- test/w3c/lua/test465.scxml | 19 ---- test/w3c/lua/test466.scxml | 13 --- test/w3c/lua/test467.scxml | 10 -- test/w3c/lua/test468.scxml | 22 ----- test/w3c/lua/test469.scxml | 23 ----- test/w3c/lua/test470.scxml | 22 ----- test/w3c/lua/test473.scxml | 36 -------- test/w3c/lua/test474.scxml | 35 ------- test/w3c/lua/test475.scxml | 35 ------- test/w3c/lua/test476.scxml | 35 ------- test/w3c/lua/test477.scxml | 35 ------- test/w3c/lua/test478.scxml | 34 ------- test/w3c/lua/test479.scxml | 34 ------- test/w3c/lua/test480.scxml | 30 ------ test/w3c/lua/test481.scxml | 35 ------- test/w3c/lua/test482.scxml | 14 --- test/w3c/lua/test483.scxml | 25 ----- test/w3c/lua/test537.scxml | 14 --- test/w3c/lua/test539.scxml | 24 ----- test/w3c/lua/test540.scxml | 20 ---- test/w3c/lua/test542.scxml | 32 ------- test/w3c/lua/test543.scxml | 16 ---- test/w3c/lua/test544.scxml | 15 --- test/w3c/lua/test545.scxml | 19 ---- test/w3c/lua/test546.scxml | 15 --- test/w3c/lua/test547.scxml | 31 ------- test/w3c/lua/test555.scxml | 24 ----- test/w3c/lua/test568.scxml | 12 --- 47 files changed, 213 insertions(+), 880 deletions(-) delete mode 100644 test/w3c/lua/test463.scxml delete mode 100644 test/w3c/lua/test464.scxml delete mode 100644 test/w3c/lua/test465.scxml delete mode 100644 test/w3c/lua/test466.scxml delete mode 100644 test/w3c/lua/test467.scxml delete mode 100644 test/w3c/lua/test468.scxml delete mode 100644 test/w3c/lua/test469.scxml delete mode 100644 test/w3c/lua/test470.scxml delete mode 100644 test/w3c/lua/test473.scxml delete mode 100644 test/w3c/lua/test474.scxml delete mode 100644 test/w3c/lua/test475.scxml delete mode 100644 test/w3c/lua/test476.scxml delete mode 100644 test/w3c/lua/test477.scxml delete mode 100644 test/w3c/lua/test478.scxml delete mode 100644 test/w3c/lua/test479.scxml delete mode 100644 test/w3c/lua/test480.scxml delete mode 100644 test/w3c/lua/test481.scxml delete mode 100644 test/w3c/lua/test482.scxml delete mode 100644 test/w3c/lua/test483.scxml delete mode 100644 test/w3c/lua/test537.scxml delete mode 100644 test/w3c/lua/test539.scxml delete mode 100644 test/w3c/lua/test540.scxml delete mode 100644 test/w3c/lua/test542.scxml delete mode 100644 test/w3c/lua/test543.scxml delete mode 100644 test/w3c/lua/test544.scxml delete mode 100644 test/w3c/lua/test545.scxml delete mode 100644 test/w3c/lua/test546.scxml delete mode 100644 test/w3c/lua/test547.scxml delete mode 100644 test/w3c/lua/test555.scxml delete mode 100644 test/w3c/lua/test568.scxml diff --git a/README.md b/README.md index 527509a..5b50687 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,9 @@ even in C# and Java. It runs on Linux, Windows and Mac OSX, * Support for binary data via [TypedArrays](https://www.khronos.org/registry/typedarray/specs/latest/) (will not throw exceptions yet) * Full [NULL datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/null) with required In predicate * [Prolog datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/prolog/swi) using SWI prolog - * Early [Promela datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/promela) for use + * Experimental [Promela datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/promela) for use with the [SPIN](http://spinroot.com/spin/whatispin.html) model-checker + * Early support for a [Lua datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/lua) * Rudimentary support for [XPath datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/xpath) * Invokers * scxml: Invoke a nested scxml interpreter @@ -68,10 +69,12 @@ uSCXML still fails the following ecmascript tests: Test#StatusDescriptionComment - 326 / - 329 + + 326 / + 329 + - Failed for v8 + Fail for v8 "test that _ioprocessors stays bound till the session ends" / "test that none of the system variables can be modified" The v8 implementation will return a new _ioprocessor object for each access. diff --git a/apps/uscxml-dot.cpp b/apps/uscxml-dot.cpp index 56f5c57..2b230b4 100644 --- a/apps/uscxml-dot.cpp +++ b/apps/uscxml-dot.cpp @@ -3,6 +3,7 @@ #include "uscxml/DOMUtils.h" #include "uscxml/debug/SCXMLDotWriter.h" #include +#include "getopt.h" #include "uscxml/Factory.h" #include @@ -67,7 +68,7 @@ int main(int argc, char** argv) { google::LogToStderr(); google::InitGoogleLogging(argv[0]); - + if (argc < 2) printUsageAndExit(argv[0]); @@ -77,25 +78,30 @@ int main(int argc, char** argv) { int option; while ((option = getopt(argc, argv, "d:t:")) != -1) { switch(option) { - case 'd': currAnchor.childDepth = strTo(optarg); break; - case 't': currAnchor.transDepth = strTo(optarg); break; - case 'e': { - std::string edgeType(optarg); - if (edgeType == "target") { - currAnchor.type = SCXMLDotWriter::PORT_TARGET; - } else if (edgeType == "event") { - currAnchor.type = SCXMLDotWriter::PORT_EVENT; - } else if (edgeType == "transition") { - currAnchor.type = SCXMLDotWriter::PORT_TRANSITION; - } else { - printUsageAndExit(argv[0]); - } - break; + case 'd': + currAnchor.childDepth = strTo(optarg); + break; + case 't': + currAnchor.transDepth = strTo(optarg); + break; + case 'e': { + std::string edgeType(optarg); + if (edgeType == "target") { + currAnchor.type = SCXMLDotWriter::PORT_TARGET; + } else if (edgeType == "event") { + currAnchor.type = SCXMLDotWriter::PORT_EVENT; + } else if (edgeType == "transition") { + currAnchor.type = SCXMLDotWriter::PORT_TRANSITION; + } else { + printUsageAndExit(argv[0]); } - default: break; + break; + } + default: + break; } } - + if (currAnchor) stateAnchors.push_back(currAnchor); @@ -104,14 +110,19 @@ int main(int argc, char** argv) { URL inputFile(argv[optind]); Interpreter interpreter = Interpreter::fromURI(inputFile); optind++; - + while(optind < argc) { // are while ((option = getopt(argc, argv, "d:t:")) != -1) { switch(option) { - case 'd': currAnchor.childDepth = strTo(optarg); break; - case 't': currAnchor.transDepth = strTo(optarg); break; - default: break; + case 'd': + currAnchor.childDepth = strTo(optarg); + break; + case 't': + currAnchor.transDepth = strTo(optarg); + break; + default: + break; } } if (argc > optind) { @@ -120,14 +131,14 @@ int main(int argc, char** argv) { } else { printUsageAndExit(argv[0]); } - + if (currAnchor) { stateAnchors.push_back(currAnchor); } - + currAnchor = SCXMLDotWriter::StateAnchor(); } - + std::string outName = inputFile.file() + ".dot"; SCXMLDotWriter::toDot(outName, interpreter, stateAnchors); diff --git a/docs/BUILDING.md b/docs/BUILDING.md index 95582ed..4a16aad 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -15,6 +15,7 @@ - [Java](#java) - [CSharp](#csharp) - [Important Note for Windows](#important-note-for-windows) +- [Optional Functionality](#optional-functionality) - [About 32/64Bit Support](#about-3264bit-support) @@ -394,6 +395,26 @@ Command Prompt (2010) and type: > nmake && nmake csharp && nmake java ... +## Optional Functionality + +At configure time, CMake will search for various libraries and conditionally compile only the part of uSCXML for +which libraries have been found. On unices, it is straight forward to add libraries and - if you installed them to +their default location - CMake will usually pick them up. On Windows, however, the process is more complicated. +While we try to search in the locations where the various installers saved the header files and libraries, there are +some of distributed only as an archive. + +If you want to give CMake the best chance of picking up these libraries, put them into the platform prebuilt path. +This path is located in <USCXML_SRC>/contrib/prebuilt/<PLATFORM>/<COMPILER>. For Windows 32bit, +with MSVC this path is <USCXML_SRC>/contrib/prebuilt/windows-x86/msvc. + +For instance, in order to enable the lua datamodel on windows, download the static lua libraries and save +the dll in <PREBUILT>/lib/lua52.lib and the header files directly in <PREBUILT>/include/. +When you run CMake for the first time, it will automatically create these paths for you. + +Note: Actually, we would have to differentiate the various MSVC versions as well: v16 (VS2010) and v18 (VS2012/13) +employ a different application binary interface (ABI). This is approach is taken e.g. in uMundo with msvc16 +vs msvc18, but not yet realized for uSCXML. + ## About 32/64Bit Support We do support both, 32 and 64Bit for Linux and Windows. On Macintosh, most prebuilt dependencies are compiled as diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 5a1df44..8767242 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -2347,7 +2347,7 @@ bool InterpreterImpl::isInitial(const Arabica::DOM::Element& state) if (isParallel(parent)) return true; - + return false; } diff --git a/src/uscxml/UUID.cpp b/src/uscxml/UUID.cpp index b56b727..ae103ed 100644 --- a/src/uscxml/UUID.cpp +++ b/src/uscxml/UUID.cpp @@ -34,31 +34,31 @@ std::string UUID::getUUID() { bool UUID::isUUID(const std::string& uuid) { if (uuid.size() != 36) return false; - + if (uuid[8] != '-' || uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-') return false; - + for (int i = 0; i < 36; i++) { if (i == 8 || i == 13 || i == 18 || i ==23) continue; - + char c = uuid[i]; if (c == 'a' || - c == 'b' || - c == 'c' || - c == 'd' || - c == 'e' || - c == 'f' || - c == '0' || - c == '1' || - c == '2' || - c == '3' || - c == '4' || - c == '5' || - c == '6' || - c == '7' || - c == '8' || - c == '9') { + c == 'b' || + c == 'c' || + c == 'd' || + c == 'e' || + c == 'f' || + c == '0' || + c == '1' || + c == '2' || + c == '3' || + c == '4' || + c == '5' || + c == '6' || + c == '7' || + c == '8' || + c == '9') { continue; } else { return false; diff --git a/src/uscxml/debug/SCXMLDotWriter.cpp b/src/uscxml/debug/SCXMLDotWriter.cpp index 88db575..16269a9 100644 --- a/src/uscxml/debug/SCXMLDotWriter.cpp +++ b/src/uscxml/debug/SCXMLDotWriter.cpp @@ -28,7 +28,7 @@ namespace uscxml { using namespace Arabica::DOM; using namespace Arabica::XPath; - + SCXMLDotWriter::SCXMLDotWriter() { _iteration = 0; _indentation = 0; @@ -56,7 +56,7 @@ SCXMLDotWriter::SCXMLDotWriter(Interpreter interpreter, anchIter->element = _scxml; if (anchIter->childDepth >= 0 && anchIter->transDepth == -1) anchIter->transDepth = anchIter->childDepth; - + _portType = anchIter->type; assembleGraph(anchIter->element, anchIter->childDepth, anchIter->transDepth + 1); } @@ -121,7 +121,7 @@ void SCXMLDotWriter::writeTo(std::ostream& os) { if (_histories.find(edgeIter->to)->second.from == _histories.find(edgeIter->to)->second.to) continue; } - + os << getPrefix() << "\"" << edgeIter->from << "\""; if (edgeIter->fromPort.size() > 0) { os << std::string(":\"") + edgeIter->fromPort + "\":e"; @@ -129,7 +129,7 @@ void SCXMLDotWriter::writeTo(std::ostream& os) { os << ":__name"; } os << " -> "; - + if (_histories.find(edgeIter->to) != _histories.end()) { os << getPrefix() << "\"" << _histories.find(edgeIter->to)->second.to << "\""; if (_histories.find(edgeIter->to)->second.toPort.size() > 0) { @@ -153,11 +153,11 @@ void SCXMLDotWriter::writeTo(std::ostream& os) { os << " [color=\"black\"]"; } os << std::endl; - + } - + _indentation--; - + os << "}" << std::endl; } @@ -191,7 +191,7 @@ void SCXMLDotWriter::assembleGraph(const Element& state, int32_t ch _graph[nodeId].node = state; _graph[nodeId].portType = _portType; - + if (childDepth == 0 && transDepth == 0) { _graph[nodeId].isBorder = true; } @@ -250,7 +250,7 @@ void SCXMLDotWriter::assembleGraph(const Element& state, int32_t ch } } - + /** * Walk the complete graph and draw reachable subset */ @@ -263,11 +263,11 @@ void SCXMLDotWriter::writeStateElement(std::ostream& os, const Element > invisParents; bool isVisible = (_graph.find(stateId) != _graph.end()); - + bool subgraph = InterpreterImpl::isCompound(stateElem) || InterpreterImpl::isParallel(stateElem); bool fatherIsParallel = (stateElem.getParentNode() && - stateElem.getParentNode().getNodeType() == Node_base::ELEMENT_NODE && - InterpreterImpl::isParallel(Element(stateElem.getParentNode()))); + stateElem.getParentNode().getNodeType() == Node_base::ELEMENT_NODE && + InterpreterImpl::isParallel(Element(stateElem.getParentNode()))); if (subgraph) { _indentation++; @@ -282,13 +282,13 @@ void SCXMLDotWriter::writeStateElement(std::ostream& os, const Elementsecond; - + // is this a subgraph? os << std::endl; @@ -321,32 +321,32 @@ void SCXMLDotWriter::writeStateElement(std::ostream& os, const ElementisInitial(stateElem); - // if (isInitial) - // os << getPrefix() << "style=filled, fillcolor=lightgrey, " << std::endl; + // if (isInitial) + // os << getPrefix() << "style=filled, fillcolor=lightgrey, " << std::endl; DotState::mmap_s_e_t::const_iterator destIterF, destIterB; std::list outPorts; // count unique keys switch (dotState.portType) { - case PORT_TARGET: // outports are per target - for(DotState::mmap_s_e_t::const_iterator it = dotState.targets.begin(), end = dotState.targets.end(); - it != end; - it = dotState.targets.upper_bound(it->first)) { - outPorts.push_back(it->first); - } - break; - case PORT_EVENT: // outports are per event - for(DotState::mmap_s_e_t::const_iterator it = dotState.events.begin(), end = dotState.events.end(); - it != end; - it = dotState.events.upper_bound(it->first)) { - outPorts.push_back(it->first); - } - break; - case PORT_TRANSITION: - for (int i = 0; i < dotState.transitions.size(); i++) { - outPorts.push_back(idForNode(dotState.transitions[i])); - } - break; + case PORT_TARGET: // outports are per target + for(DotState::mmap_s_e_t::const_iterator it = dotState.targets.begin(), end = dotState.targets.end(); + it != end; + it = dotState.targets.upper_bound(it->first)) { + outPorts.push_back(it->first); + } + break; + case PORT_EVENT: // outports are per event + for(DotState::mmap_s_e_t::const_iterator it = dotState.events.begin(), end = dotState.events.end(); + it != end; + it = dotState.events.upper_bound(it->first)) { + outPorts.push_back(it->first); + } + break; + case PORT_TRANSITION: + for (int i = 0; i < dotState.transitions.size(); i++) { + outPorts.push_back(idForNode(dotState.transitions[i])); + } + break; } os << getPrefix() << "label = < " << std::endl; @@ -366,17 +366,17 @@ void SCXMLDotWriter::writeStateElement(std::ostream& os, const Element" << nameForNode(stateElem) << "" << std::endl; switch (dotState.portType) { - case PORT_TARGET: // outports are per target - writePerTargetPorts(os, outPorts, dotState); - break; - case PORT_EVENT: // outports are per event - writePerEventPorts(os, outPorts, dotState); - break; - case PORT_TRANSITION: - writePerTransitionPorts(os, outPorts, dotState); - break; + case PORT_TARGET: // outports are per target + writePerTargetPorts(os, outPorts, dotState); + break; + case PORT_EVENT: // outports are per event + writePerEventPorts(os, outPorts, dotState); + break; + case PORT_TRANSITION: + writePerTransitionPorts(os, outPorts, dotState); + break; } - + // write details of the state if (details.size() > 0) { @@ -445,12 +445,12 @@ void SCXMLDotWriter::writePerTargetPorts(std::ostream& os, const std::list::const_iterator nameIter = outPorts.begin(); nameIter != outPorts.end(); nameIter++) { - + // gather all events that activate the transition std::string portName = *nameIter; DotEdge edge(stateId, portName); edge.fromPort = portName; - + std::multimap eventConds; // event to condition std::pair targetKeyRange = dotState.targets.equal_range(portName); for (destIterB = targetKeyRange.first; destIterB != targetKeyRange.second; ++destIterB) { @@ -467,11 +467,11 @@ void SCXMLDotWriter::writePerTargetPorts(std::ostream& os, const std::list::iterator condIter_t; std::stringstream outPortSS; outPortSS << "" << portName << "
"; - + std::string opener = "{"; std::string closer; std::string seperator; @@ -479,19 +479,19 @@ void SCXMLDotWriter::writePerTargetPorts(std::ostream& os, const std::listfirst; bool hasCondition = false; - + std::pair condRange = eventConds.equal_range(eventName); for (iterB = condRange.first; iterB != condRange.second; ++iterB) { hasCondition = true; } - + outPortSS << opener << seperator << eventName << (hasCondition ? "" : ""); seperator = ", "; opener = ""; closer = "}"; } outPortSS << closer; - + os << " " << outPortSS.str() << "" << std::endl; } @@ -582,7 +582,7 @@ std::string SCXMLDotWriter::getDetailedLabel(const Element& elem, i if (HAS_ATTR(childElems.item(i), "event ")) details.name += "
event = " + ATTR(childElems.item(i), "event"); } - + // send --------- if (iequals(TAGNAME(childElems.item(i)), "send")) { if (HAS_ATTR(childElems.item(i), "id")) @@ -718,7 +718,7 @@ std::string SCXMLDotWriter::nameForNode(const Node& node) { std::string elemName; if (node.getNodeType() == Node_base::ELEMENT_NODE) { Element elem = (Element)node; - + if (false) { } else if (elem.getTagName() == "scxml") { if (elem.hasAttribute("name") && !UUID::isUUID(elem.getAttribute("name"))) { diff --git a/src/uscxml/debug/SCXMLDotWriter.h b/src/uscxml/debug/SCXMLDotWriter.h index 79ea6c1..3ac697f 100644 --- a/src/uscxml/debug/SCXMLDotWriter.h +++ b/src/uscxml/debug/SCXMLDotWriter.h @@ -68,9 +68,9 @@ public: Arabica::DOM::Element element; int32_t childDepth; int32_t transDepth; - + PortType type; - + operator bool() const { return childDepth != -1 || transDepth != -1 || element; } @@ -94,7 +94,7 @@ public: std::set childs; std::set initialchilds; - + typedef std::multimap > mmap_s_e_t; }; @@ -108,7 +108,7 @@ public: DotEdge() : type(EDGE_TRANSIION) {} DotEdge(const std::string& from, const std::string& to) : type(EDGE_TRANSIION), from(from), to(to) { } - + bool operator< (const DotEdge& other) const { return from + fromPort + to + toPort > other.from + other.fromPort + other.to + other.toPort; } @@ -121,7 +121,7 @@ public: std::string toPort; std::string toCompass; }; - + SCXMLDotWriter(); ~SCXMLDotWriter(); @@ -162,14 +162,14 @@ protected: const Arabica::DOM::Element& transition); void assembleGraph(const Arabica::DOM::Element& start, - int32_t childDepth = std::numeric_limits::max(), - int32_t transDepth = std::numeric_limits::max()); + int32_t childDepth = std::numeric_limits::max(), + int32_t transDepth = std::numeric_limits::max()); void writeStateElement(std::ostream& os, const Arabica::DOM::Element& state); - + void writePerTransitionPorts(std::ostream& os, const std::list& outPorts, const DotState& dotState); void writePerEventPorts(std::ostream& os, const std::list& outPorts, const DotState& dotState); void writePerTargetPorts(std::ostream& os, const std::list& outPorts, const DotState& dotState); - + void writeUnknownNode(std::ostream& os, const std::string& targetId); int _iteration; @@ -179,7 +179,7 @@ protected: std::map _graph; std::set _edges; - + // these are only set in ephemeral instances per monitor call Arabica::DOM::Element _transition; Arabica::DOM::Element _scxml; @@ -187,7 +187,7 @@ protected: std::string _xmlNSPrefix; std::list _anchors; std::map _histories; - + PortType _portType; }; diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index 84833fb..018a8c4 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -48,6 +48,10 @@ LuaDataModel::LuaDataModel() { _luaState = NULL; } +static int luaInspect(lua_State * l) { + return 0; +} + static int luaInFunction(lua_State * l) { luabridge::LuaRef ref = luabridge::getGlobal(l, "__interpreter"); InterpreterImpl* interpreter = ref.cast(); @@ -151,6 +155,7 @@ static luabridge::LuaRef getDataAsLua(lua_State* _luaState, const Data& data) { luaData[compoundIter->first] = getDataAsLua(_luaState, compoundIter->second); compoundIter++; } + luaData["inspect"] = luaInspect; return luaData; } if (data.array.size() > 0) { @@ -161,6 +166,7 @@ static luabridge::LuaRef getDataAsLua(lua_State* _luaState, const Data& data) { luaData[index++] = getDataAsLua(_luaState, *arrayIter); arrayIter++; } + luaData["inspect"] = luaInspect; return luaData; } if (data.atom.size() > 0) { @@ -170,7 +176,15 @@ static luabridge::LuaRef getDataAsLua(lua_State* _luaState, const Data& data) { break; } case Data::INTERPRETED: { - luaData = data.atom; // not sure + if (isNumeric(data.atom.c_str(), 10)) { + if (data.atom.find(".") != std::string::npos) { + luaData = strTo(data.atom); + } else { + luaData = strTo(data.atom); + } + } else { + luaData = data.atom; + } } } return luaData; @@ -190,6 +204,7 @@ void LuaDataModel::setEvent(const Event& event) { luaEvent["content"] = event.content; luaEvent["invokeId"] = event.invokeid; luaEvent["sendId"] = event.sendid; + luaEvent["inspect"] = luaInspect; switch (event.eventType) { case Event::INTERNAL: @@ -214,7 +229,15 @@ void LuaDataModel::setEvent(const Event& event) { if (!json.empty()) { luaEvent["data"] = getDataAsLua(_luaState, json); } else { - luaEvent["data"] = InterpreterImpl::spaceNormalize(event.content); + // test179 + std::string trimmed = boost::trim_copy(event.content); + if ((boost::starts_with(trimmed, "'") && boost::ends_with(trimmed, "'")) || + (boost::starts_with(trimmed, "\"") && boost::ends_with(trimmed, "\""))) { + luaEvent["data"] = InterpreterImpl::spaceNormalize(event.content); + } else { + Data tmp(event.content, Data::INTERPRETED); + luaEvent["data"] = getDataAsLua(_luaState, tmp); + } } } else { // _event.data is KVP @@ -254,15 +277,11 @@ Data LuaDataModel::getStringAsData(const std::string& content) { trimmedExpr = "return(" + trimmedExpr + ");"; } - int preStack = lua_gettop(_luaState); - eval(Arabica::DOM::Element(), trimmedExpr); - int postStack = lua_gettop(_luaState); - int retVals = postStack - preStack; + int retVals = luaEval(Arabica::DOM::Element(), trimmedExpr); if (retVals == 1) { data = getLuaAsData(luabridge::LuaRef::fromStack(_luaState, -1)); } - postStack = lua_gettop(_luaState); - lua_pop(_luaState, postStack - preStack); + lua_pop(_luaState, retVals); } return data; @@ -280,17 +299,11 @@ uint32_t LuaDataModel::getLength(const std::string& expr) { // we need the result of the expression on the lua stack -> has to "return"! std::string trimmedExpr = boost::trim_copy(expr); -// luabridge::LuaRef val = luabridge::getGlobal(_luaState, expr.c_str()); -// std::cout << val.tostring() << std::endl; - if (!boost::starts_with(trimmedExpr, "return")) { trimmedExpr = "return(#" + trimmedExpr + ")"; } - int preStack = lua_gettop(_luaState); - eval(Arabica::DOM::Element(), trimmedExpr); - int postStack = lua_gettop(_luaState); - int retVals = postStack - preStack; + int retVals = luaEval(Arabica::DOM::Element(), trimmedExpr); if (retVals == 1 && lua_isnumber(_luaState, -1)) { int result = lua_tointeger(_luaState, -1); @@ -311,19 +324,14 @@ void LuaDataModel::setForeach(const std::string& item, const luabridge::LuaRef& arrRef = luabridge::getGlobal(_luaState, array.c_str()); if (arrRef.isTable()) { - int preStack = lua_gettop(_luaState); // trigger syntax error for invalid items - eval(Arabica::DOM::Element(), "return(" + item + ");"); - int postStack = lua_gettop(_luaState); - lua_pop(_luaState, postStack - preStack); + int retVals = luaEval(Arabica::DOM::Element(), "return(" + item + ");"); + lua_pop(_luaState, retVals); const luabridge::LuaRef& val = arrRef[iteration]; luabridge::setGlobal(_luaState, val, item.c_str()); -// luabridge::LuaRef retVal = luabridge::getGlobal(_luaState, item.c_str()); -// std::cout << retVal.tostring() << std::endl; - if (index.length() > 0) { // assign iteration element to index luabridge::setGlobal(_luaState, iteration, index.c_str()); @@ -333,12 +341,20 @@ void LuaDataModel::setForeach(const std::string& item, void LuaDataModel::eval(const Arabica::DOM::Element& scriptElem, const std::string& expr) { + luaEval(scriptElem, expr); +} + +int LuaDataModel::luaEval(const Arabica::DOM::Element& scriptElem, + const std::string& expr) { + int preStack = lua_gettop(_luaState); int error = luaL_loadstring(_luaState, expr.c_str()) || lua_pcall(_luaState, 0, LUA_MULTRET, 0); if (error) { std::string errMsg = lua_tostring(_luaState, -1); lua_pop(_luaState, 1); /* pop error message from the stack */ ERROR_EXECUTION_THROW(errMsg); } + int postStack = lua_gettop(_luaState); + return postStack - preStack; } bool LuaDataModel::isDeclared(const std::string& expr) { @@ -378,10 +394,10 @@ void LuaDataModel::assign(const Arabica::DOM::Element& assignElem, // luabridge::LuaRef val = luabridge::getGlobal(_luaState, key.c_str()); // std::cout << val.tostring() << std::endl; - int preStack = lua_gettop(_luaState); + int retVals = 0; if (HAS_ATTR(assignElem, "expr")) { - eval(Arabica::DOM::Element(), key + " = " + ATTR(assignElem, "expr") + ";"); + retVals = luaEval(Arabica::DOM::Element(), key + " = " + ATTR(assignElem, "expr") + ";"); } else if (node) { ERROR_EXECUTION_THROW("Cannot assign xml nodes in lua datamodel"); } else if (content.size() > 0) { @@ -397,13 +413,10 @@ void LuaDataModel::assign(const Arabica::DOM::Element& assignElem, // val = luabridge::getGlobal(_luaState, key.c_str()); // std::cout << val.tostring() << std::endl; - int postStack = lua_gettop(_luaState); - int retVals = postStack - preStack; - } void LuaDataModel::assign(const std::string& location, const Data& data) { - std::cout << "assign" << std::endl; + luabridge::setGlobal(_luaState, getDataAsLua(_luaState, data), location.c_str()); } void LuaDataModel::init(const Arabica::DOM::Element& dataElem, @@ -413,7 +426,7 @@ void LuaDataModel::init(const Arabica::DOM::Element& dataElem, } void LuaDataModel::init(const std::string& location, const Data& data) { - std::cout << "init" << std::endl; + assign(location, data); } /** @@ -429,10 +442,7 @@ bool LuaDataModel::evalAsBool(const Arabica::DOM::Node& node, const trimmedExpr = "return(" + trimmedExpr + ");"; } - int preStack = lua_gettop(_luaState); - eval(Arabica::DOM::Element(), trimmedExpr); - int postStack = lua_gettop(_luaState); - int retVals = postStack - preStack; + int retVals = luaEval(Arabica::DOM::Element(), trimmedExpr); if (retVals == 1 && lua_isboolean(_luaState, -1)) { bool result = lua_toboolean(_luaState, -1); @@ -450,10 +460,7 @@ std::string LuaDataModel::evalAsString(const std::string& expr) { trimmedExpr = "return(" + trimmedExpr + ")"; } - int preStack = lua_gettop(_luaState); - eval(Arabica::DOM::Element(), trimmedExpr); - int postStack = lua_gettop(_luaState); - int retVals = postStack - preStack; + int retVals = luaEval(Arabica::DOM::Element(), trimmedExpr); if (retVals == 1 && lua_isstring(_luaState, -1)) { std::string result = lua_tostring(_luaState, -1); diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index c5d9e4b..828db0e 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -87,16 +87,8 @@ public: protected: - static int luaEventData(lua_State * l); - static int luaEventOrigin(lua_State * l); - static int luaEventOriginType(lua_State * l); - static int luaEventRaw(lua_State * l); - static int luaEventXML(lua_State * l); - static int luaEventName(lua_State * l); - static int luaEventContent(lua_State * l); - static int luaEventSendId(lua_State * l); - static int luaEventInvokeId(lua_State * l); - static int luaEventDestructor(lua_State * l); + virtual int luaEval(const Arabica::DOM::Element& scriptElem, + const std::string& expr); lua_State* _luaState; }; diff --git a/test/src/test-vxml-mmi-socket.cpp b/test/src/test-vxml-mmi-socket.cpp index b57b7f6..a79cec7 100644 --- a/test/src/test-vxml-mmi-socket.cpp +++ b/test/src/test-vxml-mmi-socket.cpp @@ -52,21 +52,21 @@ int main(int argc, char** argv) { // TestClient client(PF_INET, SOCK_STREAM, 0); // client.connect("epikur.local", 4343); - + StartRequest startReq; startReq.source = "undefined.source"; startReq.target = "epikur.local:4343"; startReq.requestId = "131234141234"; startReq.data = - "" - " Goodbye!" - ""; + "" + " Goodbye!" + ""; Arabica::DOM::Document reqXML = startReq.toXML(); std::stringstream xmlSS; xmlSS << reqXML; std::cout << reqXML; - + // client.write(xmlSS.str().data(), xmlSS.str().size()); } \ No newline at end of file diff --git a/test/w3c/lua/test176.scxml b/test/w3c/lua/test176.scxml index 97f8f51..7e5f460 100644 --- a/test/w3c/lua/test176.scxml +++ b/test/w3c/lua/test176.scxml @@ -19,6 +19,11 @@ aParam in event1 is 2 so that var2 gets set to 2, success, otherwise failure -- + + + + + diff --git a/test/w3c/lua/test178.scxml b/test/w3c/lua/test178.scxml index 11361e1..c4df704 100644 --- a/test/w3c/lua/test178.scxml +++ b/test/w3c/lua/test178.scxml @@ -13,11 +13,11 @@ inspection.) --> - + - + diff --git a/test/w3c/lua/test183.scxml b/test/w3c/lua/test183.scxml index 2b36df9..13378c9 100644 --- a/test/w3c/lua/test183.scxml +++ b/test/w3c/lua/test183.scxml @@ -7,7 +7,7 @@ var1 has a value and we pass. Otherwise we fail --> - + diff --git a/test/w3c/lua/test187.scxml b/test/w3c/lua/test187.scxml index 48aac56..0b6daa1 100644 --- a/test/w3c/lua/test187.scxml +++ b/test/w3c/lua/test187.scxml @@ -6,7 +6,7 @@ parent session, should not receive childToParent. If it does, we fail. Otherwis - + @@ -14,7 +14,7 @@ parent session, should not receive childToParent. If it does, we fail. Otherwis - + diff --git a/test/w3c/lua/test223.scxml b/test/w3c/lua/test223.scxml index 92cf1a9..dcbf061 100644 --- a/test/w3c/lua/test223.scxml +++ b/test/w3c/lua/test223.scxml @@ -8,7 +8,7 @@ - + diff --git a/test/w3c/lua/test224.scxml b/test/w3c/lua/test224.scxml index 7a095e0..acca9f6 100644 --- a/test/w3c/lua/test224.scxml +++ b/test/w3c/lua/test224.scxml @@ -9,7 +9,7 @@ - + diff --git a/test/w3c/lua/test225.scxml b/test/w3c/lua/test225.scxml index d370f9b..17f80c3 100644 --- a/test/w3c/lua/test225.scxml +++ b/test/w3c/lua/test225.scxml @@ -9,14 +9,14 @@ - + - + diff --git a/test/w3c/lua/test463.scxml b/test/w3c/lua/test463.scxml deleted file mode 100644 index 23ca9cf..0000000 --- a/test/w3c/lua/test463.scxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - diff --git a/test/w3c/lua/test464.scxml b/test/w3c/lua/test464.scxml deleted file mode 100644 index ddbef86..0000000 --- a/test/w3c/lua/test464.scxml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/test/w3c/lua/test465.scxml b/test/w3c/lua/test465.scxml deleted file mode 100644 index 50e708a..0000000 --- a/test/w3c/lua/test465.scxml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test466.scxml b/test/w3c/lua/test466.scxml deleted file mode 100644 index 51896b4..0000000 --- a/test/w3c/lua/test466.scxml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/test/w3c/lua/test467.scxml b/test/w3c/lua/test467.scxml deleted file mode 100644 index 673a561..0000000 --- a/test/w3c/lua/test467.scxml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/test/w3c/lua/test468.scxml b/test/w3c/lua/test468.scxml deleted file mode 100644 index 8c0c74a..0000000 --- a/test/w3c/lua/test468.scxml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - New York - Boston - - - - - - - - - - - - - diff --git a/test/w3c/lua/test469.scxml b/test/w3c/lua/test469.scxml deleted file mode 100644 index 487029d..0000000 --- a/test/w3c/lua/test469.scxml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test470.scxml b/test/w3c/lua/test470.scxml deleted file mode 100644 index 68d55bc..0000000 --- a/test/w3c/lua/test470.scxml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - 2 - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test473.scxml b/test/w3c/lua/test473.scxml deleted file mode 100644 index 45dfb40..0000000 --- a/test/w3c/lua/test473.scxml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - 12334455 - some author - - - - - - - - - diff --git a/test/w3c/lua/test474.scxml b/test/w3c/lua/test474.scxml deleted file mode 100644 index fdbce30..0000000 --- a/test/w3c/lua/test474.scxml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - 12334455 - some author - - - - - - - - - diff --git a/test/w3c/lua/test475.scxml b/test/w3c/lua/test475.scxml deleted file mode 100644 index dc01a91..0000000 --- a/test/w3c/lua/test475.scxml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - 12334455 - some author - - - - - - - - - diff --git a/test/w3c/lua/test476.scxml b/test/w3c/lua/test476.scxml deleted file mode 100644 index fcb7bd9..0000000 --- a/test/w3c/lua/test476.scxml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - 12334455 - some author - - - - - - - - - diff --git a/test/w3c/lua/test477.scxml b/test/w3c/lua/test477.scxml deleted file mode 100644 index b9ebba9..0000000 --- a/test/w3c/lua/test477.scxml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - 12334455 - some author - - - - - - - - - diff --git a/test/w3c/lua/test478.scxml b/test/w3c/lua/test478.scxml deleted file mode 100644 index d687487..0000000 --- a/test/w3c/lua/test478.scxml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - This is not a book - - - - - - - - - diff --git a/test/w3c/lua/test479.scxml b/test/w3c/lua/test479.scxml deleted file mode 100644 index a26ae7b..0000000 --- a/test/w3c/lua/test479.scxml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - This is not a book - - - - - - - - - diff --git a/test/w3c/lua/test480.scxml b/test/w3c/lua/test480.scxml deleted file mode 100644 index 866444f..0000000 --- a/test/w3c/lua/test480.scxml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test481.scxml b/test/w3c/lua/test481.scxml deleted file mode 100644 index 930b60d..0000000 --- a/test/w3c/lua/test481.scxml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test482.scxml b/test/w3c/lua/test482.scxml deleted file mode 100644 index 33b35a6..0000000 --- a/test/w3c/lua/test482.scxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test483.scxml b/test/w3c/lua/test483.scxml deleted file mode 100644 index 375ca05..0000000 --- a/test/w3c/lua/test483.scxml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test537.scxml b/test/w3c/lua/test537.scxml deleted file mode 100644 index a231a97..0000000 --- a/test/w3c/lua/test537.scxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - diff --git a/test/w3c/lua/test539.scxml b/test/w3c/lua/test539.scxml deleted file mode 100644 index fced2e6..0000000 --- a/test/w3c/lua/test539.scxml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test540.scxml b/test/w3c/lua/test540.scxml deleted file mode 100644 index b0298b7..0000000 --- a/test/w3c/lua/test540.scxml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - 123 -4 5 - - - - - - - - - - - - - diff --git a/test/w3c/lua/test542.scxml b/test/w3c/lua/test542.scxml deleted file mode 100644 index 69b6ea3..0000000 --- a/test/w3c/lua/test542.scxml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - 123 -4 5 - - - - - - - diff --git a/test/w3c/lua/test543.scxml b/test/w3c/lua/test543.scxml deleted file mode 100644 index 55946ed..0000000 --- a/test/w3c/lua/test543.scxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test544.scxml b/test/w3c/lua/test544.scxml deleted file mode 100644 index 5d935ab..0000000 --- a/test/w3c/lua/test544.scxml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test545.scxml b/test/w3c/lua/test545.scxml deleted file mode 100644 index 7443ff2..0000000 --- a/test/w3c/lua/test545.scxml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - 3 - - - - - - - - - - diff --git a/test/w3c/lua/test546.scxml b/test/w3c/lua/test546.scxml deleted file mode 100644 index 68efb84..0000000 --- a/test/w3c/lua/test546.scxml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - some string - - - - - - - - diff --git a/test/w3c/lua/test547.scxml b/test/w3c/lua/test547.scxml deleted file mode 100644 index 26e5cc8..0000000 --- a/test/w3c/lua/test547.scxml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - The Zen Mind - - - Freakonomics - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test555.scxml b/test/w3c/lua/test555.scxml deleted file mode 100644 index 2609689..0000000 --- a/test/w3c/lua/test555.scxml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/w3c/lua/test568.scxml b/test/w3c/lua/test568.scxml deleted file mode 100644 index aaa1023..0000000 --- a/test/w3c/lua/test568.scxml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - -- cgit v0.12