summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp22
-rw-r--r--test/issues/test-issue109.scxml16
2 files changed, 29 insertions, 9 deletions
diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
index 890b8cf..33255db 100644
--- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
@@ -554,7 +554,27 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s
}
}
if (field.second) {
- value[strTo<long>(field.first)] = lua;
+ if (field.first.length() == 0) {
+ ERROR_EXECUTION_THROW("Subscript operator is empty");
+ }
+
+ 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<long>(field.first)] = lua;
+ } else {
+ // string array subscript
+ value[field.first] = lua;
+ }
} else {
value[field.first] = lua;
}
diff --git a/test/issues/test-issue109.scxml b/test/issues/test-issue109.scxml
index bb366dd..4e6373d 100644
--- a/test/issues/test-issue109.scxml
+++ b/test/issues/test-issue109.scxml
@@ -1,17 +1,17 @@
-<scxml datamodel="lua" initial="StateShape1" name="ScxmlShape1" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">
+<scxml datamodel="lua" initial="s0" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">
<datamodel>
<data id="VarArray">{ 0, 0, 0 }</data>
<data expr="1" id="Var1"/>
</datamodel>
- <state id="StateShape1">
+ <state id="s0">
<onentry>
<assign expr="555" location="VarArray[Var1]"/>
</onentry>
- <transition cond="VarArray[1]~=0" target="Pass"/>
- <transition event="error.*" target="Fail"/>
- <transition cond="VarArray[1]==0" target="Unknown"/>
+ <transition cond="VarArray[1]~=0" target="pass"/>
+ <transition target="fail">
+ <log expr="VarArray[1]" />
+ </transition>
</state>
- <final id="Pass"/>
- <final id="Fail"/>
- <final id="Unknown"/>
+ <final id="pass"/>
+ <final id="fail"/>
</scxml>