From 75bf929119ca976e0d6b8da75770d07b510d5824 Mon Sep 17 00:00:00 2001 From: alexzhornyak Date: Sun, 7 May 2017 19:35:49 +0300 Subject: 1) correcting for issue 120 2) making exported SCXMLIOProcessor --- src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp | 1 + src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h | 1 + src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index 1248205..abe9055 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -191,6 +191,7 @@ void USCXMLInvoker::invoke(const std::string& source, const Event& invokeEvent) al.internalQueue = alOrig->internalQueue.getImplBase()->create(); al.externalQueue = alOrig->externalQueue.getImplBase()->create(); al.microStepper = alOrig->microStepper.getImpl()->create(invoked); + al.logger = alOrig->logger.getImpl()->create(); _invokedInterpreter.setActionLanguage(al); } diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index 61931c6..b030d8b 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -23,6 +23,7 @@ #include "uscxml/config.h" #include "uscxml/interpreter/InterpreterImpl.h" #include "uscxml/interpreter/BasicEventQueue.h" +#include "uscxml/interpreter/LoggingImpl.h" #include "uscxml/plugins/InvokerImpl.h" diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h index 328e18e..0207b00 100644 --- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h +++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h @@ -33,7 +33,7 @@ namespace uscxml { * @ingroup ioproc * The scxml I/O processor as per standard. */ -class SCXMLIOProcessor : public IOProcessorImpl { +class USCXML_API SCXMLIOProcessor : public IOProcessorImpl { public: SCXMLIOProcessor(); virtual ~SCXMLIOProcessor(); -- cgit v0.12 From 43936ecb53a0eb582eaf3a56ec0c016f8c47ae7f Mon Sep 17 00:00:00 2001 From: alexzhornyak Date: Sun, 7 May 2017 20:00:12 +0300 Subject: evalAsScript Implemented evalAsScript function --- src/uscxml/interpreter/BasicContentExecutor.cpp | 2 +- src/uscxml/interpreter/ContentExecutorImpl.h | 1 + src/uscxml/interpreter/InterpreterImpl.h | 4 ++ src/uscxml/plugins/DataModel.cpp | 4 ++ src/uscxml/plugins/DataModel.h | 2 + src/uscxml/plugins/DataModelImpl.h | 6 +++ src/uscxml/plugins/datamodel/c89/C89DataModel.h | 1 + .../ecmascript/JavaScriptCore/JSCDataModel.h | 1 + .../plugins/datamodel/ecmascript/v8/V8DataModel.h | 1 + src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 46 ++++++---------------- src/uscxml/plugins/datamodel/lua/LuaDataModel.h | 1 + src/uscxml/plugins/datamodel/null/NullDataModel.h | 3 ++ .../plugins/datamodel/promela/PromelaDataModel.h | 1 + 13 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 7ffda91..96777b1 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -291,7 +291,7 @@ void BasicContentExecutor::processLog(XERCESC_NS::DOMElement* content) { void BasicContentExecutor::processScript(XERCESC_NS::DOMElement* content) { // download as necessary std::string scriptContent(X(content->getTextContent())); - _callbacks->evalAsData(scriptContent); + _callbacks->evalAsScript(scriptContent); } diff --git a/src/uscxml/interpreter/ContentExecutorImpl.h b/src/uscxml/interpreter/ContentExecutorImpl.h index 5f0acfe..6afeca8 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.h +++ b/src/uscxml/interpreter/ContentExecutorImpl.h @@ -59,6 +59,7 @@ public: uint32_t iteration) = 0; virtual Data evalAsData(const std::string& expr) = 0; + virtual void evalAsScript(const std::string& content) = 0; virtual Data getAsData(const std::string& expr) = 0; virtual void assign(const std::string& location, const Data& data, const std::map& attrs) = 0; diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index a68298b..aa439c0 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -187,6 +187,10 @@ public: return _dataModel.evalAsData(expr); } + virtual void evalAsScript(const std::string& content) { + _dataModel.evalAsScript(content); + } + virtual Data getAsData(const std::string& expr) { return _dataModel.getAsData(expr); } diff --git a/src/uscxml/plugins/DataModel.cpp b/src/uscxml/plugins/DataModel.cpp index 07fd4b4..bb1324d 100644 --- a/src/uscxml/plugins/DataModel.cpp +++ b/src/uscxml/plugins/DataModel.cpp @@ -42,6 +42,10 @@ Data DataModel::evalAsData(const std::string& content) { return _impl->evalAsData(content); } +void DataModel::evalAsScript(const std::string& content) { + _impl->evalAsScript(content); +} + bool DataModel::evalAsBool(const std::string& expr) { return _impl->evalAsBool(expr); } diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index 9185cc8..d141f32 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -54,6 +54,8 @@ public: virtual Data getAsData(const std::string& content); /// @copydoc DataModelImpl::evalAsData() virtual Data evalAsData(const std::string& content); + /// @copydoc DataModelImpl::evalAsScript() + virtual void evalAsScript(const std::string& content); /// @copydoc DataModelImpl::evalAsBool() virtual bool evalAsBool(const std::string& expr); diff --git a/src/uscxml/plugins/DataModelImpl.h b/src/uscxml/plugins/DataModelImpl.h index 8326871..da56bd1 100644 --- a/src/uscxml/plugins/DataModelImpl.h +++ b/src/uscxml/plugins/DataModelImpl.h @@ -153,6 +153,12 @@ public: virtual Data evalAsData(const std::string& content) = 0; /** + * evaluating script content without return + * @param mostly script content. + */ + virtual void evalAsScript(const std::string& content) = 0; + + /** * Evaluate a given expression as a boolean. * This function is a subset of evalAsData() but saves on creating and copying a Data object. * @param expr An expression in the data-model's language. diff --git a/src/uscxml/plugins/datamodel/c89/C89DataModel.h b/src/uscxml/plugins/datamodel/c89/C89DataModel.h index 4e9eef0..34aaf04 100644 --- a/src/uscxml/plugins/datamodel/c89/C89DataModel.h +++ b/src/uscxml/plugins/datamodel/c89/C89DataModel.h @@ -76,6 +76,7 @@ public: virtual bool evalAsBool(const std::string& expr); virtual Data evalAsData(const std::string& expr); + virtual void evalAsScript(const std::string& content) { evalAsData(content); } virtual Data getAsData(const std::string& content); virtual bool isDeclared(const std::string& expr); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 5a0e830..562593a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -77,6 +77,7 @@ public: virtual Data getAsData(const std::string& content); virtual Data evalAsData(const std::string& expr); + virtual void evalAsScript(const std::string& content) { evalAsData(content); } virtual bool evalAsBool(const std::string& expr); virtual bool isDeclared(const std::string& expr); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index 00a871b..3d3d25f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -70,6 +70,7 @@ public: virtual bool evalAsBool(const std::string& expr); virtual Data evalAsData(const std::string& expr); + virtual void evalAsScript(const std::string& content) { evalAsData(content); } virtual Data getAsData(const std::string& content); virtual bool isDeclared(const std::string& expr); diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index 2071d39..97d3637 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -350,49 +350,25 @@ void LuaDataModel::setEvent(const Event& event) { Data LuaDataModel::evalAsData(const std::string& content) { Data data; - ErrorEvent originalError; std::string trimmedExpr = boost::trim_copy(content); - try { - int retVals = luaEval(_luaState, "return(" + trimmedExpr + ")"); - if (retVals == 1) { - data = getLuaAsData(_luaState, luabridge::LuaRef::fromStack(_luaState, -1)); - } - lua_pop(_luaState, retVals); - return data; - } catch (ErrorEvent e) { - originalError = e; - } - - int retVals = 0; - try { - // evaluate again without the return() - retVals = luaEval(_luaState, trimmedExpr); - } catch (ErrorEvent e) { - throw originalError; // we will assume syntax error and throw - } - -#if 1 - // Note: Empty result is not an error test302, but how to do test488? - if (retVals == 0 && !isValidSyntax(trimmedExpr)) { - throw originalError; // we will assume syntax error and throw + int retVals = luaEval(_luaState, "return(" + trimmedExpr + ")"); + if (retVals == 1) { + data = getLuaAsData(_luaState, luabridge::LuaRef::fromStack(_luaState, -1)); } -#endif + lua_pop(_luaState, retVals); + return data; +} - try { - if (retVals == 1) { - data = getLuaAsData(_luaState, luabridge::LuaRef::fromStack(_luaState, -1)); - } - lua_pop(_luaState, retVals); - return data; +void LuaDataModel::evalAsScript(const std::string& content) { + Data data; - } catch (ErrorEvent e) { - throw e; // we will assume syntax error and throw - } + std::string trimmedExpr = boost::trim_copy(content); + int retVals = luaEval(_luaState, trimmedExpr); - return data; + lua_pop(_luaState, retVals); } bool LuaDataModel::isValidSyntax(const std::string& expr) { diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index c64656a..a71a734 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -74,6 +74,7 @@ public: virtual bool evalAsBool(const std::string& expr); virtual Data evalAsData(const std::string& expr); + virtual void evalAsScript(const std::string& content); virtual Data getAsData(const std::string& content); virtual bool isDeclared(const std::string& expr); diff --git a/src/uscxml/plugins/datamodel/null/NullDataModel.h b/src/uscxml/plugins/datamodel/null/NullDataModel.h index 8c9f5b9..9a7ea0e 100644 --- a/src/uscxml/plugins/datamodel/null/NullDataModel.h +++ b/src/uscxml/plugins/datamodel/null/NullDataModel.h @@ -77,6 +77,9 @@ public: virtual Data evalAsData(const std::string& content) { return getAsData(content); } + virtual void evalAsScript(const std::string& content) { + getAsData(content); + } virtual std::string evalAsString(const std::string& expr) { return expr; } diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h index f19bd5d..37a2cf7 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h @@ -57,6 +57,7 @@ public: virtual bool evalAsBool(const std::string& expr); virtual Data evalAsData(const std::string& expr); + virtual void evalAsScript(const std::string& expr) { evalAsData(expr); } virtual Data getAsData(const std::string& content); virtual bool isDeclared(const std::string& expr); -- cgit v0.12 From 4f2dee08e0e77fcccd55a17add874f4a1ebc1be8 Mon Sep 17 00:00:00 2001 From: alexzhornyak Date: Sun, 7 May 2017 22:00:01 +0300 Subject: Issue with test 179 Corrected BasicContentExecutor to pass test 179 --- src/uscxml/interpreter/BasicContentExecutor.cpp | 12 +- test/w3c/lua/test562.scxml | 176 ++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 test/w3c/lua/test562.scxml diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 96777b1..a21255a 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -691,9 +691,19 @@ Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element, bool a contentSS << X((*textIter)->getNodeValue()); } + // this must be handled in getAsData // test294, test562 if (LOCALNAME(element) == "content") { - return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); + // need first try getAsData because how to pass 179 ? + try { + // test153, we need to throw for test150 in promela + Data d = _callbacks->getAsData(contentSS.str()); + if (!d.empty()) + return d; + } + catch (ErrorEvent &) { + return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); + } } if (asExpression) // not actually used, but likely expected diff --git a/test/w3c/lua/test562.scxml b/test/w3c/lua/test562.scxml new file mode 100644 index 0000000..3be5072 --- /dev/null +++ b/test/w3c/lua/test562.scxml @@ -0,0 +1,176 @@ + + + + + + +this is a +string + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v0.12 From 3654c1e42a3145658b2503309b74d0ad6c4066ea Mon Sep 17 00:00:00 2001 From: alexzhornyak Date: Mon, 8 May 2017 09:43:55 +0300 Subject: Fix issue 116 Creating temporary variable for assigning function --- src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 9 +++-- test/issues/test-issue116.scxml | 43 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/issues/test-issue116.scxml diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index 97d3637..899237a 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -79,9 +79,12 @@ static int luaEval(lua_State* luaState, const std::string& expr) { static Data getLuaAsData(lua_State* _luaState, const luabridge::LuaRef& lua) { Data data; if (lua.isFunction()) { - // TODO: this might lead to a stack-overflow - luabridge::LuaRef luaEvald = lua(); - return getLuaAsData(_luaState, luaEvald); + // we are creating __tmpFunc + // then it will be assigned to data variable + luabridge::setGlobal(_luaState, lua, "__tmpFunc"); + + data.atom = "__tmpFunc"; + data.type = Data::INTERPRETED; } else if(lua.isLightUserdata() || lua.isUserdata()) { // not sure what to do } else if(lua.isThread()) { diff --git a/test/issues/test-issue116.scxml b/test/issues/test-issue116.scxml new file mode 100644 index 0000000..ca1cc56 --- /dev/null +++ b/test/issues/test-issue116.scxml @@ -0,0 +1,43 @@ + + + function() + print("Hello from function") +end + + function() + return 2 +end + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v0.12 From dacba30880611af98b40ed908797da935a185d81 Mon Sep 17 00:00:00 2001 From: alexzhornyak Date: Mon, 8 May 2017 09:51:38 +0300 Subject: Corrected for successful build all --- src/bindings/swig/wrapped/WrappedDataModel.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bindings/swig/wrapped/WrappedDataModel.h b/src/bindings/swig/wrapped/WrappedDataModel.h index e0bd422..d836c09 100644 --- a/src/bindings/swig/wrapped/WrappedDataModel.h +++ b/src/bindings/swig/wrapped/WrappedDataModel.h @@ -73,6 +73,9 @@ public: virtual Data evalAsData(const std::string& expr) { return Data(); } + virtual void evalAsScript(const std::string& expr) { + Data(); + } virtual bool evalAsBool(const std::string& expr) { return true; } -- cgit v0.12 From 82087b37adc295d1aab5afd51f855f8d9f0923f8 Mon Sep 17 00:00:00 2001 From: azhornyak Date: Sat, 13 May 2017 18:43:52 +0300 Subject: Fixes issue #126 Fixes issue #128 Fixes issue #124 Fixes issue #118 --- src/uscxml/interpreter/BasicContentExecutor.cpp | 30 +++++----- src/uscxml/messages/Event.h | 8 +++ src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 73 +++++++++++++---------- src/uscxml/plugins/datamodel/lua/LuaDataModel.h | 2 + src/uscxml/util/Convenience.h | 6 +- 5 files changed, 71 insertions(+), 48 deletions(-) diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index a21255a..cb77d9a 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -67,7 +67,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { sendEvent.name = ATTR(element, kXMLCharEvent); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element eventexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element eventexpr", element); } try { @@ -78,7 +78,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { target = ATTR(element, kXMLCharTarget); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element targetexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element targetexpr", element); } try { @@ -89,7 +89,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { type = ATTR(element, kXMLCharType); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element typeexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element typeexpr", element); } try { @@ -124,7 +124,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { } } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element idlocation", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element idlocation", element); } try { @@ -148,14 +148,14 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { } } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element delayexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element delayexpr", element); } try { // namelist processNameLists(sendEvent.namelist, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element namelist", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element namelist", element); } @@ -163,7 +163,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { // params processParams(sendEvent.params, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element param expr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element param expr", element); } try { @@ -173,7 +173,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { sendEvent.data = elementAsData(contents.front()); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element content", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element content", element); } // if (sendReq->dom) { @@ -431,14 +431,14 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { element->setUserData(kXMLCharInvokeId, (void*)invokeId, NULL); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in invoke element idlocation", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in invoke element idlocation", element); } try { // namelist processNameLists(invokeEvent.namelist, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element namelist", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element namelist", element); } @@ -446,7 +446,7 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { // params processParams(invokeEvent.params, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element param expr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element param expr", element); } try { @@ -467,7 +467,7 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { #endif } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in invoke element content", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in invoke element content", element); } // autoforward @@ -513,7 +513,7 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC // namelist processNameLists(doneEvent.namelist, doneData); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in donedata element namelist", doneData); + ERROR_EXECUTION_THROW3(e,"Syntax error in donedata element namelist", doneData); } @@ -521,7 +521,7 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC // params processParams(doneEvent.params, doneData); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in donedata element param expr", doneData); + ERROR_EXECUTION_THROW3(e,"Syntax error in donedata element param expr", doneData); } try { @@ -531,7 +531,7 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC doneEvent.data = elementAsData(contents.front()); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in donedata element content", doneData); + ERROR_EXECUTION_THROW3(e,"Syntax error in donedata element content", doneData); } } catch (ErrorEvent exc) { diff --git a/src/uscxml/messages/Event.h b/src/uscxml/messages/Event.h index b774f8a..fd9dd42 100644 --- a/src/uscxml/messages/Event.h +++ b/src/uscxml/messages/Event.h @@ -77,6 +77,14 @@ throw exc;\ } +#define ERROR_EXECUTION_THROW3(evt,caption,node) \ +{\ + auto it = evt.data.compound.find("cause"); \ + ERROR_EXECUTION2(exc,it!=evt.data.compound.end() ? it->second.atom : "",node); \ + exc.data.compound["caption"] = uscxml::Data(caption, uscxml::Data::VERBATIM); \ + throw exc;\ +} + #define ERROR_COMMUNICATION_THROW(cause) \ {\ ERROR_COMMUNICATION(exc, cause); \ diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index 899237a..ea90e8c 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -212,12 +212,23 @@ int LuaDataModel::luaInFunction(lua_State * l) { std::shared_ptr LuaDataModel::create(DataModelCallbacks* callbacks) { std::shared_ptr dm(new LuaDataModel()); - dm->_callbacks = callbacks; - dm->_luaState = luaL_newstate(); - luaL_openlibs(dm->_luaState); + dm->doCreate(callbacks); + + return dm; +} + +LuaDataModel::~LuaDataModel() { + if (_luaState != NULL) + lua_close(_luaState); +} + +void LuaDataModel::doCreate(DataModelCallbacks* callbacks) { + this->_callbacks = callbacks; + this->_luaState = luaL_newstate(); + luaL_openlibs(this->_luaState); try { - const luabridge::LuaRef& requireFunc = luabridge::getGlobal(dm->_luaState, "require"); + const luabridge::LuaRef& requireFunc = luabridge::getGlobal(this->_luaState, "require"); if (requireFunc.isFunction()) { const luabridge::LuaRef& resultLxp = requireFunc("lxp"); const luabridge::LuaRef& resultLxpLOM = requireFunc("lxp.lom"); @@ -225,48 +236,42 @@ std::shared_ptr LuaDataModel::create(DataModelCallbacks* callback // MSVC compiler bug with implicit cast operators, see comments in LuaRef class if ((bool)resultLxp && (bool)resultLxpLOM) { _luaHasXMLParser = true; - luabridge::setGlobal(dm->_luaState, resultLxp, "lxp"); - luabridge::setGlobal(dm->_luaState, resultLxpLOM, "lxp.lom"); + luabridge::setGlobal(this->_luaState, resultLxp, "lxp"); + luabridge::setGlobal(this->_luaState, resultLxpLOM, "lxp.lom"); } } - } catch (luabridge::LuaException e) { - LOG(dm->_callbacks->getLogger(), USCXML_INFO) << e.what() << std::endl; + } + catch (luabridge::LuaException e) { + LOG(this->_callbacks->getLogger(), USCXML_INFO) << e.what() << std::endl; } - luabridge::getGlobalNamespace(dm->_luaState).beginClass("DataModel").endClass(); - luabridge::setGlobal(dm->_luaState, dm.get(), "__datamodel"); + luabridge::getGlobalNamespace(this->_luaState).beginClass("DataModel").endClass(); + luabridge::setGlobal(this->_luaState, this, "__datamodel"); - luabridge::getGlobalNamespace(dm->_luaState).addCFunction("In", luaInFunction); + luabridge::getGlobalNamespace(this->_luaState).addCFunction("In", luaInFunction); - luabridge::LuaRef ioProcTable = luabridge::newTable(dm->_luaState); - std::map ioProcs = dm->_callbacks->getIOProcessors(); + luabridge::LuaRef ioProcTable = luabridge::newTable(this->_luaState); + std::map ioProcs = this->_callbacks->getIOProcessors(); std::map::const_iterator ioProcIter = ioProcs.begin(); - while(ioProcIter != ioProcs.end()) { + while (ioProcIter != ioProcs.end()) { Data ioProcData = ioProcIter->second.getDataModelVariables(); - ioProcTable[ioProcIter->first] = getDataAsLua(dm->_luaState, ioProcData); + ioProcTable[ioProcIter->first] = getDataAsLua(this->_luaState, ioProcData); ioProcIter++; } - luabridge::setGlobal(dm->_luaState, ioProcTable, "_ioprocessors"); + luabridge::setGlobal(this->_luaState, ioProcTable, "_ioprocessors"); - luabridge::LuaRef invTable = luabridge::newTable(dm->_luaState); - std::map invokers = dm->_callbacks->getInvokers(); + luabridge::LuaRef invTable = luabridge::newTable(this->_luaState); + std::map invokers = this->_callbacks->getInvokers(); std::map::const_iterator invIter = invokers.begin(); - while(invIter != invokers.end()) { + while (invIter != invokers.end()) { Data invData = invIter->second.getDataModelVariables(); - invTable[invIter->first] = getDataAsLua(dm->_luaState, invData); + invTable[invIter->first] = getDataAsLua(this->_luaState, invData); invIter++; } - luabridge::setGlobal(dm->_luaState, invTable, "_invokers"); - - luabridge::setGlobal(dm->_luaState, dm->_callbacks->getName(), "_name"); - luabridge::setGlobal(dm->_luaState, dm->_callbacks->getSessionId(), "_sessionid"); + luabridge::setGlobal(this->_luaState, invTable, "_invokers"); - return dm; -} - -LuaDataModel::~LuaDataModel() { - if (_luaState != NULL) - lua_close(_luaState); + luabridge::setGlobal(this->_luaState, this->_callbacks->getName(), "_name"); + luabridge::setGlobal(this->_luaState, this->_callbacks->getSessionId(), "_sessionid"); } void LuaDataModel::addExtension(DataModelExtension* ext) { @@ -484,6 +489,7 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s // JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(location.c_str()), getNodeAsValue(data.node), 0, &exception); } else { +#if 0 // trigger error.execution for undefined locations, test286 test311 int retVals = luaEval(_luaState, location + " = " + location); lua_pop(_luaState, retVals); @@ -504,9 +510,14 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s if (idPath.size() == 0) return; +#endif luabridge::LuaRef lua = getDataAsLua(_luaState, data); + luabridge::setGlobal(_luaState, lua, "__tmpAssign"); + evalAsScript(location + "= __tmpAssign"); + +#if 0 if (idPath.size() == 1) { // trivial case where we reference a simple toplevel identifier luabridge::setGlobal(_luaState, lua, location.c_str()); @@ -559,7 +570,7 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s } } - +#endif // std::cout << Data::toJSON(evalAsData(location)) << std::endl; } } diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index a71a734..4912868 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -91,6 +91,8 @@ protected: static int luaInFunction(lua_State * l); lua_State* _luaState; + + void doCreate(DataModelCallbacks* callbacks); }; #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/util/Convenience.h b/src/uscxml/util/Convenience.h index 98c4220..dec027f 100644 --- a/src/uscxml/util/Convenience.h +++ b/src/uscxml/util/Convenience.h @@ -29,14 +29,16 @@ namespace uscxml { inline bool isnan(double x); // see http://stackoverflow.com/questions/228005/alternative-to-itoa-for-converting-integer-to-string-c -template std::string USCXML_API toStr(T tmp) { +// error C2491 !!! template std::string USCXML_API toStr(T tmp) { +template std::string toStr(T tmp) { std::ostringstream outSS; outSS.precision(std::numeric_limits::digits10 + 1); outSS << tmp; return outSS.str(); } -template T USCXML_API strTo(std::string tmp) { +// error C2491 !!! template T USCXML_API strTo(std::string tmp) { +template T strTo(std::string tmp) { T output; std::istringstream in(tmp); in >> output; -- cgit v0.12 From 3b94ebf0420f4845054e8b1ae447f894e2c2325f Mon Sep 17 00:00:00 2001 From: alexzhornyak Date: Sun, 14 May 2017 01:19:47 +0300 Subject: Final corrections for eval function --- src/uscxml/interpreter/BasicContentExecutor.cpp | 2 +- src/uscxml/interpreter/ContentExecutorImpl.h | 2 +- src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 145 +++++----------------- 3 files changed, 35 insertions(+), 114 deletions(-) diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 932d579..61277bd 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -291,7 +291,7 @@ void BasicContentExecutor::processLog(XERCESC_NS::DOMElement* content) { void BasicContentExecutor::processScript(XERCESC_NS::DOMElement* content) { // download as necessary std::string scriptContent(X(content->getTextContent())); - _callbacks->evalAsData(scriptContent); + _callbacks->eval(scriptContent); } diff --git a/src/uscxml/interpreter/ContentExecutorImpl.h b/src/uscxml/interpreter/ContentExecutorImpl.h index fd6be89..82acc1c 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.h +++ b/src/uscxml/interpreter/ContentExecutorImpl.h @@ -59,7 +59,7 @@ public: uint32_t iteration) = 0; virtual Data evalAsData(const std::string& expr) = 0; - virtual void eval(const std::string& content) { evalAsData(expr); } + virtual void eval(const std::string& expr) { evalAsData(expr); } virtual Data getAsData(const std::string& expr) = 0; virtual void assign(const std::string& location, const Data& data, const std::map& attrs) = 0; diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index ea90e8c..8f50729 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -211,24 +211,17 @@ int LuaDataModel::luaInFunction(lua_State * l) { std::shared_ptr LuaDataModel::create(DataModelCallbacks* callbacks) { std::shared_ptr dm(new LuaDataModel()); - - dm->doCreate(callbacks); - + dm->_callbacks = callbacks; + dm->setup(); return dm; } -LuaDataModel::~LuaDataModel() { - if (_luaState != NULL) - lua_close(_luaState); -} - -void LuaDataModel::doCreate(DataModelCallbacks* callbacks) { - this->_callbacks = callbacks; - this->_luaState = luaL_newstate(); - luaL_openlibs(this->_luaState); +void LuaDataModel::setup() { + _luaState = luaL_newstate(); + luaL_openlibs(_luaState); try { - const luabridge::LuaRef& requireFunc = luabridge::getGlobal(this->_luaState, "require"); + const luabridge::LuaRef& requireFunc = luabridge::getGlobal(_luaState, "require"); if (requireFunc.isFunction()) { const luabridge::LuaRef& resultLxp = requireFunc("lxp"); const luabridge::LuaRef& resultLxpLOM = requireFunc("lxp.lom"); @@ -236,42 +229,47 @@ void LuaDataModel::doCreate(DataModelCallbacks* callbacks) { // MSVC compiler bug with implicit cast operators, see comments in LuaRef class if ((bool)resultLxp && (bool)resultLxpLOM) { _luaHasXMLParser = true; - luabridge::setGlobal(this->_luaState, resultLxp, "lxp"); - luabridge::setGlobal(this->_luaState, resultLxpLOM, "lxp.lom"); + luabridge::setGlobal(_luaState, resultLxp, "lxp"); + luabridge::setGlobal(_luaState, resultLxpLOM, "lxp.lom"); } } - } - catch (luabridge::LuaException e) { - LOG(this->_callbacks->getLogger(), USCXML_INFO) << e.what() << std::endl; + } catch (luabridge::LuaException e) { + LOG(_callbacks->getLogger(), USCXML_INFO) << e.what() << std::endl; } - luabridge::getGlobalNamespace(this->_luaState).beginClass("DataModel").endClass(); - luabridge::setGlobal(this->_luaState, this, "__datamodel"); + luabridge::getGlobalNamespace(_luaState).beginClass("DataModel").endClass(); + luabridge::setGlobal(_luaState, this, "__datamodel"); - luabridge::getGlobalNamespace(this->_luaState).addCFunction("In", luaInFunction); + luabridge::getGlobalNamespace(_luaState).addCFunction("In", luaInFunction); - luabridge::LuaRef ioProcTable = luabridge::newTable(this->_luaState); - std::map ioProcs = this->_callbacks->getIOProcessors(); + luabridge::LuaRef ioProcTable = luabridge::newTable(_luaState); + std::map ioProcs = _callbacks->getIOProcessors(); std::map::const_iterator ioProcIter = ioProcs.begin(); - while (ioProcIter != ioProcs.end()) { + while(ioProcIter != ioProcs.end()) { Data ioProcData = ioProcIter->second.getDataModelVariables(); - ioProcTable[ioProcIter->first] = getDataAsLua(this->_luaState, ioProcData); + ioProcTable[ioProcIter->first] = getDataAsLua(_luaState, ioProcData); ioProcIter++; } - luabridge::setGlobal(this->_luaState, ioProcTable, "_ioprocessors"); + luabridge::setGlobal(_luaState, ioProcTable, "_ioprocessors"); - luabridge::LuaRef invTable = luabridge::newTable(this->_luaState); - std::map invokers = this->_callbacks->getInvokers(); + luabridge::LuaRef invTable = luabridge::newTable(_luaState); + std::map invokers = _callbacks->getInvokers(); std::map::const_iterator invIter = invokers.begin(); - while (invIter != invokers.end()) { + while(invIter != invokers.end()) { Data invData = invIter->second.getDataModelVariables(); - invTable[invIter->first] = getDataAsLua(this->_luaState, invData); + invTable[invIter->first] = getDataAsLua(_luaState, invData); invIter++; } - luabridge::setGlobal(this->_luaState, invTable, "_invokers"); + luabridge::setGlobal(_luaState, invTable, "_invokers"); + + luabridge::setGlobal(_luaState, _callbacks->getName(), "_name"); + luabridge::setGlobal(_luaState, _callbacks->getSessionId(), "_sessionid"); - luabridge::setGlobal(this->_luaState, this->_callbacks->getName(), "_name"); - luabridge::setGlobal(this->_luaState, this->_callbacks->getSessionId(), "_sessionid"); +} + +LuaDataModel::~LuaDataModel() { + if (_luaState != NULL) + lua_close(_luaState); } void LuaDataModel::addExtension(DataModelExtension* ext) { @@ -369,9 +367,7 @@ Data LuaDataModel::evalAsData(const std::string& content) { return data; } -void LuaDataModel::evalAsScript(const std::string& content) { - Data data; - +void LuaDataModel::eval(const std::string& content) { std::string trimmedExpr = boost::trim_copy(content); int retVals = luaEval(_luaState, trimmedExpr); @@ -489,88 +485,13 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s // JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(location.c_str()), getNodeAsValue(data.node), 0, &exception); } else { -#if 0 - // trigger error.execution for undefined locations, test286 test311 - int retVals = luaEval(_luaState, location + " = " + location); - lua_pop(_luaState, retVals); - - std::list > idPath; - size_t start = 0; - for (size_t i = 0; i < location.size(); i++) { - if (location[i] == '.' || location[i] == '[') { - idPath.push_back(std::make_pair(location.substr(start, i - start), false)); - start = i + 1; - } else if (location[i] == ']') { - idPath.push_back(std::make_pair(location.substr(start, i - start), true)); - start = i + 1; - } - } - if (start < location.size()) - idPath.push_back(std::make_pair(location.substr(start, location.size() - start), false)); - - if (idPath.size() == 0) - return; -#endif luabridge::LuaRef lua = getDataAsLua(_luaState, data); luabridge::setGlobal(_luaState, lua, "__tmpAssign"); - evalAsScript(location + "= __tmpAssign"); - -#if 0 - if (idPath.size() == 1) { - // trivial case where we reference a simple toplevel identifier - luabridge::setGlobal(_luaState, lua, location.c_str()); - - } else { - auto globalId = idPath.front(); - idPath.pop_front(); - - auto field = idPath.back(); - idPath.pop_back(); - - luabridge::LuaRef topValue = luabridge::getGlobal(_luaState, globalId.first.c_str()); - luabridge::LuaRef value = topValue; - - for (auto ident : idPath) { - if (!value.isTable()) - value = luabridge::newTable(_luaState); - - if (ident.second) { - luabridge::LuaRef tmp = value[strTo(ident.first)]; - } else { - luabridge::LuaRef tmp = value[ident]; - value = tmp; - } - } - if (field.second) { - if (field.first.length() == 0) { - ERROR_EXECUTION_THROW("Subscript operator is empty"); - } + eval(location + "= __tmpAssign"); - if (!isNumeric(field.first.c_str(), 10) && field.first[0] != '"' && field.first[0] != '\'') { - // evaluate subscript as variable - Data subscript = evalAsData(field.first); - if (subscript.atom.length() > 0) { - field.first = subscript.atom; - } else { - ERROR_EXECUTION_THROW("Evaluated subscript operator '" + subscript.asJSON() + "' is invalid"); - } - } - - if (isNumeric(field.first.c_str(), 10)) { - // numeric array subscript - value[strTo(field.first)] = lua; - } else { - // string array subscript - value[field.first] = lua; - } - } else { - value[field.first] = lua; - } - } -#endif // std::cout << Data::toJSON(evalAsData(location)) << std::endl; } } -- cgit v0.12 From 673701710475dd1b9b4d06b8d5db99fa656306e8 Mon Sep 17 00:00:00 2001 From: alexzhornyak Date: Sun, 14 May 2017 01:29:21 +0300 Subject: Deleted extra info --- test/w3c/lua/test562.scxml | 153 +-------------------------------------------- 1 file changed, 1 insertion(+), 152 deletions(-) diff --git a/test/w3c/lua/test562.scxml b/test/w3c/lua/test562.scxml index 3be5072..fc73973 100644 --- a/test/w3c/lua/test562.scxml +++ b/test/w3c/lua/test562.scxml @@ -22,155 +22,4 @@ string - \ No newline at end of file + \ No newline at end of file -- cgit v0.12