mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Fixed handling of strings with quotes or brackets, and better table push
This commit is contained in:
@@ -263,8 +263,7 @@ private:
|
||||
* \param L the lua state to push value to
|
||||
* \param value string representation of the value with which to set property
|
||||
*/
|
||||
void propertyPushValueFromProfileToLuaState(ghoul::lua::LuaState& L,
|
||||
std::string& value);
|
||||
void propertyPushProfileValueToLua(ghoul::lua::LuaState& L, std::string& value);
|
||||
|
||||
/**
|
||||
* Accepts string version of a property value from a profile, and processes it
|
||||
@@ -277,8 +276,7 @@ private:
|
||||
* has already been pushed to the lua stack
|
||||
* \return The ProfilePropertyLua variant type translated from string representation
|
||||
*/
|
||||
ProfilePropertyLua propertyProcessValue(ghoul::lua::LuaState& L,
|
||||
std::string& value, bool& didPushToLua);
|
||||
ProfilePropertyLua propertyProcessValue(ghoul::lua::LuaState& L, std::string& value);
|
||||
|
||||
/**
|
||||
* Accepts string version of a property value from a profile, and returns the
|
||||
@@ -326,6 +324,7 @@ private:
|
||||
std::unique_ptr<SceneInitializer> _initializer;
|
||||
std::string _profilePropertyName;
|
||||
std::vector<InterestingTime> _interestingTimes;
|
||||
bool _valueIsTable = false;
|
||||
|
||||
std::mutex _programUpdateLock;
|
||||
std::set<ghoul::opengl::ProgramObject*> _programsToUpdate;
|
||||
|
||||
@@ -623,7 +623,7 @@ void Scene::setPropertiesFromProfile(const Profile& p) {
|
||||
std::string workingValue = prop.value;
|
||||
trimSurroundingCharacters(workingValue, ' ');
|
||||
// Later functions expect the value to be at the last position on the stack
|
||||
propertyPushValueFromProfileToLuaState(L, workingValue);
|
||||
propertyPushProfileValueToLua(L, workingValue);
|
||||
|
||||
applyRegularExpression(
|
||||
L,
|
||||
@@ -638,12 +638,11 @@ void Scene::setPropertiesFromProfile(const Profile& p) {
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::propertyPushValueFromProfileToLuaState(ghoul::lua::LuaState& L,
|
||||
std::string& value)
|
||||
void Scene::propertyPushProfileValueToLua(ghoul::lua::LuaState& L, std::string& value)
|
||||
{
|
||||
bool alreadyPushedToLua = false;
|
||||
ProfilePropertyLua elem = propertyProcessValue(L, value, alreadyPushedToLua);
|
||||
if (!alreadyPushedToLua) {
|
||||
_valueIsTable = false;
|
||||
ProfilePropertyLua elem = propertyProcessValue(L, value);
|
||||
if (!_valueIsTable) {
|
||||
std::visit(overloaded{
|
||||
[&L](const bool& value) {
|
||||
ghoul::lua::push(L, value);
|
||||
@@ -657,15 +656,15 @@ void Scene::propertyPushValueFromProfileToLuaState(ghoul::lua::LuaState& L,
|
||||
[&L](const ghoul::lua::nil_t& nilValue) {
|
||||
ghoul::lua::push(L, nilValue);
|
||||
}
|
||||
}, elem);
|
||||
}, elem);
|
||||
}
|
||||
}
|
||||
|
||||
ProfilePropertyLua Scene::propertyProcessValue(ghoul::lua::LuaState& L,std::string& value,
|
||||
bool& didPushToLua)
|
||||
ProfilePropertyLua Scene::propertyProcessValue(ghoul::lua::LuaState& L,std::string& value)
|
||||
{
|
||||
ProfilePropertyLua result;
|
||||
PropertyValueType pType = getPropertyValueType(value);
|
||||
|
||||
switch (pType) {
|
||||
case PropertyValueType::Boolean:
|
||||
result = (value == "true") ? true : false;
|
||||
@@ -684,15 +683,15 @@ ProfilePropertyLua Scene::propertyProcessValue(ghoul::lua::LuaState& L,std::stri
|
||||
trimSurroundingCharacters(value, '{');
|
||||
trimSurroundingCharacters(value, '}');
|
||||
handlePropertyLuaTableEntry(L, value);
|
||||
didPushToLua = true;
|
||||
_valueIsTable = true;
|
||||
break;
|
||||
|
||||
case PropertyValueType::String:
|
||||
default:
|
||||
std::string newValue = value;
|
||||
newValue.insert(0, "[[");
|
||||
newValue.append("]]");
|
||||
result = newValue;
|
||||
trimSurroundingCharacters(value, '\"');
|
||||
trimSurroundingCharacters(value, '[');
|
||||
trimSurroundingCharacters(value, ']');
|
||||
result = value;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
@@ -761,9 +760,7 @@ void Scene::processPropertyValueTableEntries(ghoul::lua::LuaState& L, std::strin
|
||||
nextValue = value.substr(prevPos);
|
||||
}
|
||||
trimSurroundingCharacters(nextValue, ' ');
|
||||
bool alreadyPushedToLua = false;
|
||||
ProfilePropertyLua tableElement = propertyProcessValue(L, nextValue,
|
||||
alreadyPushedToLua);
|
||||
ProfilePropertyLua tableElement = propertyProcessValue(L, nextValue);
|
||||
try {
|
||||
table.push_back(std::get<T>(tableElement));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user