summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2016-08-04 21:04:31 (GMT)
committerStefan Radomski <github@mintwerk.de>2016-08-04 21:04:31 (GMT)
commitad2653c30b78b2951eb79d303a9e3ab52f4a2def (patch)
tree7cab3b6a791bf7cb4462babc749d586c73a4df01 /src
parent398630710aef647a2d68705f46c4691994c0f5c9 (diff)
downloaduscxml-ad2653c30b78b2951eb79d303a9e3ab52f4a2def.zip
uscxml-ad2653c30b78b2951eb79d303a9e3ab52f4a2def.tar.gz
uscxml-ad2653c30b78b2951eb79d303a9e3ab52f4a2def.tar.bz2
Fixed issue 88
Diffstat (limited to 'src')
-rw-r--r--src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
index 225e34c..ca8cc60 100644
--- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp
@@ -470,21 +470,20 @@ void LuaDataModel::assign(const std::string& location, const Data& data) {
int retVals = luaEval(_luaState, location + " = " + location);
lua_pop(_luaState, retVals);
- // normalize location into dot notation
- // TODO: This is still wrong as it treads arrays as kvps!
- std::string normedLocation;
- normedLocation.resize(location.size());
- for (size_t i = 0, j = 0; i < location.size(); i++, j++) {
- if (location[i] == ']') {
- j++;
- } else if (location[i] == '[') {
- normedLocation[i] = '.';
- } else {
- normedLocation[i] = location[i];
+ std::list<std::pair<std::string, bool> > 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;
}
}
-
- std::list<std::string> idPath = tokenize(normedLocation, '.');
+ if (start < location.size())
+ idPath.push_back(std::make_pair(location.substr(start, location.size() - start), false));
+
if (idPath.size() == 0)
return;
@@ -495,23 +494,31 @@ void LuaDataModel::assign(const std::string& location, const Data& data) {
luabridge::setGlobal(_luaState, lua, location.c_str());
} else {
- std::string globalId = idPath.front();
+ auto globalId = idPath.front();
idPath.pop_front();
- std::string field = idPath.back();
+ auto field = idPath.back();
idPath.pop_back();
- luabridge::LuaRef topValue = luabridge::getGlobal(_luaState, globalId.c_str());
+ 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);
- luabridge::LuaRef tmp = value[ident];
- value = tmp;
+ if (ident.second) {
+ luabridge::LuaRef tmp = value[strTo<long>(ident.first)];
+ } else {
+ luabridge::LuaRef tmp = value[ident];
+ value = tmp;
+ }
+ }
+ if (field.second) {
+ value[strTo<long>(field.first)] = lua;
+ } else {
+ value[field.first] = lua;
}
- value[field] = lua;
}