diff options
-rw-r--r-- | src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 9 | ||||
-rw-r--r-- | test/issues/test-issue116.scxml | 43 |
2 files changed, 49 insertions, 3 deletions
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 @@ +<scxml datamodel="lua" initial="StateShape1" name="ScxmlShape1" version="1.0" xmlns="http://www.w3.org/2005/07/scxml"> + <datamodel> + <data id="varFunc1">function() + print("Hello from function") +end + </data> + <data id="varFunc2">function() + return 2 +end + </data> + <data expr="nil" id="varFunc3"/> + </datamodel> + <final id="Pass"> + <onentry> + <log expr=""Pass"" label="Outcome"/> + </onentry> + </final> + <final id="Fail"> + <onentry> + <log expr=""Fail"" label="Outcome"/> + </onentry> + </final> + <state id="StateShape1"> + <onentry> + <assign expr="varFunc2" location="varFunc3"/> + <assign expr="function() + return 4 +end" location="varFunc4"/> + <log expr="''" label="Test"/> + <script>print("this is from Script!") + +print(string.format("varFunc3()==%d",varFunc3())) +print(string.format("varFunc2()==%d",varFunc2())) + +varFunc1() + +print(string.format("varFunc4()==%d",varFunc4())) + </script> + </onentry> + <transition cond="varFunc4()==4 and varFunc3()==2" target="Pass"/> + <transition target="Fail"/> + </state> +</scxml>
\ No newline at end of file |