mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-25 06:19:02 -06:00
Centralize the extraction of Lua values and fix bug when trying to extract the first parameter of a Lua parameter pack
This commit is contained in:
@@ -41,8 +41,6 @@ public:
|
||||
using TemplateProperty<std::vector<double>>::operator=;
|
||||
|
||||
protected:
|
||||
std::vector<double> fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
void toLuaConversion(lua_State* state) const override;
|
||||
std::string toStringConversion() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@ public:
|
||||
using TemplateProperty<std::vector<int>>::operator=;
|
||||
|
||||
protected:
|
||||
std::vector<int> fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
void toLuaConversion(lua_State* state) const override;
|
||||
std::string toStringConversion() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -42,9 +42,6 @@ public:
|
||||
using TemplateProperty<std::vector<std::string>>::operator=;
|
||||
|
||||
protected:
|
||||
std::vector<std::string> fromLuaConversion(lua_State* state,
|
||||
bool& success) const override;
|
||||
void toLuaConversion(lua_State* state) const override;
|
||||
std::string toStringConversion() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ public:
|
||||
ListProperty(Property::PropertyInfo info, std::vector<T> values);
|
||||
|
||||
virtual ~ListProperty() override = 0;
|
||||
|
||||
protected:
|
||||
std::vector<T> fromLuaConversion(lua_State* state) const override;
|
||||
void toLuaConversion(lua_State* state) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -32,5 +32,15 @@ ListProperty<T>::ListProperty(Property::PropertyInfo info, std::vector<T> values
|
||||
template <typename T>
|
||||
ListProperty<T>::~ListProperty() {}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> ListProperty<T>::fromLuaConversion(lua_State* state) const {
|
||||
return ghoul::lua::value<std::vector<T>>(state);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ListProperty<T>::toLuaConversion(lua_State* state) const {
|
||||
ghoul::lua::push(state, TemplateProperty<std::vector<T>>::_value);
|
||||
}
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::dmat2x2>::operator=;
|
||||
|
||||
protected:
|
||||
glm::dmat2x2 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::dmat3x3>::operator=;
|
||||
|
||||
protected:
|
||||
glm::dmat3x3 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::dmat4x4>::operator=;
|
||||
|
||||
protected:
|
||||
glm::dmat4x4 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::mat2x2>::operator=;
|
||||
|
||||
protected:
|
||||
glm::mat2x2 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::mat3x3>::operator=;
|
||||
|
||||
protected:
|
||||
glm::mat3x3 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::mat4x4>::operator=;
|
||||
|
||||
protected:
|
||||
glm::mat4x4 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -66,7 +66,7 @@ protected:
|
||||
static const std::string SteppingValueKey;
|
||||
static const std::string ExponentValueKey;
|
||||
|
||||
virtual T fromLuaConversion(lua_State* state, bool& success) const override = 0;
|
||||
T fromLuaConversion(lua_State* state) const override;
|
||||
virtual void toLuaConversion(lua_State* state) const override;
|
||||
virtual std::string toStringConversion() const override;
|
||||
|
||||
|
||||
@@ -166,12 +166,9 @@ void NumericalProperty<T>::setInterpolationTarget(std::any value) {
|
||||
|
||||
template <typename T>
|
||||
void NumericalProperty<T>::setLuaInterpolationTarget(lua_State* state) {
|
||||
bool success = false;
|
||||
T targetValue = fromLuaConversion(state, success);
|
||||
if (success) {
|
||||
_interpolationStart = TemplateProperty<T>::_value;
|
||||
_interpolationEnd = std::move(targetValue);
|
||||
}
|
||||
T targetValue = fromLuaConversion(state);
|
||||
_interpolationStart = TemplateProperty<T>::_value;
|
||||
_interpolationEnd = std::move(targetValue);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -191,6 +188,11 @@ void NumericalProperty<T>::toLuaConversion(lua_State* state) const {
|
||||
ghoul::lua::push(state, TemplateProperty<T>::_value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NumericalProperty<T>::fromLuaConversion(lua_State* state) const {
|
||||
return ghoul::lua::value<T>(state);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string NumericalProperty<T>::toStringConversion() const {
|
||||
return formatJson(TemplateProperty<T>::_value);
|
||||
|
||||
@@ -43,8 +43,6 @@ public:
|
||||
using TemplateProperty<bool>::operator=;
|
||||
|
||||
protected:
|
||||
bool fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
void toLuaConversion(lua_State* state) const override;
|
||||
std::string toStringConversion() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,9 +44,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<double>::operator=;
|
||||
|
||||
protected:
|
||||
double fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -44,9 +44,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<float>::operator=;
|
||||
|
||||
protected:
|
||||
float fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -44,9 +44,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<int>::operator=;
|
||||
|
||||
protected:
|
||||
int fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<long>::operator=;
|
||||
|
||||
protected:
|
||||
long fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -58,9 +58,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<short>::operator=;
|
||||
|
||||
protected:
|
||||
short fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<unsigned int>::operator=;
|
||||
|
||||
protected:
|
||||
unsigned int fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<unsigned long>::operator=;
|
||||
|
||||
protected:
|
||||
unsigned long fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -45,9 +45,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<unsigned short>::operator=;
|
||||
|
||||
protected:
|
||||
unsigned short fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -114,8 +114,7 @@ public:
|
||||
using TemplateProperty<std::set<std::string>>::operator=;
|
||||
|
||||
protected:
|
||||
std::set<std::string> fromLuaConversion(lua_State* state,
|
||||
bool& success) const override;
|
||||
std::set<std::string> fromLuaConversion(lua_State* state) const override;
|
||||
|
||||
void toLuaConversion(lua_State* state) const override;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
operator std::string_view() const;
|
||||
|
||||
protected:
|
||||
std::string fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
std::string fromLuaConversion(lua_State* state) const override;
|
||||
void toLuaConversion(lua_State* state) const override;
|
||||
std::string toStringConversion() const override;
|
||||
};
|
||||
|
||||
@@ -188,10 +188,9 @@ protected:
|
||||
* and returns it. This method has to be specialized for each new type.
|
||||
*
|
||||
* \param state The Lua state from which the value will be decoded
|
||||
* \param success Set to true `true` if the decoding succeeded; `false` otherwise
|
||||
* \return the decoded value
|
||||
*/
|
||||
virtual T fromLuaConversion(lua_State* state, bool& success) const = 0;
|
||||
virtual T fromLuaConversion(lua_State* state) const = 0;
|
||||
|
||||
/**
|
||||
* Encodes the stored value into a Lua object and pushes that object onto
|
||||
|
||||
@@ -87,11 +87,7 @@ bool TemplateProperty<T>::getLuaValue(lua_State* state) const {
|
||||
template <typename T>
|
||||
bool TemplateProperty<T>::setLuaValue(lua_State* state) {
|
||||
try {
|
||||
bool success;
|
||||
T thisValue = fromLuaConversion(state, success);
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
T thisValue = fromLuaConversion(state);
|
||||
set(std::any(thisValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::dvec2>::operator=;
|
||||
|
||||
protected:
|
||||
glm::dvec2 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::dvec3>::operator=;
|
||||
|
||||
protected:
|
||||
glm::dvec3 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::dvec4>::operator=;
|
||||
|
||||
protected:
|
||||
glm::dvec4 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::ivec2>::operator=;
|
||||
|
||||
protected:
|
||||
glm::ivec2 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::ivec3>::operator=;
|
||||
|
||||
protected:
|
||||
glm::ivec3 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::ivec4>::operator=;
|
||||
|
||||
protected:
|
||||
glm::ivec4 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::uvec2>::operator=;
|
||||
|
||||
protected:
|
||||
glm::uvec2 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::uvec3>::operator=;
|
||||
|
||||
protected:
|
||||
glm::uvec3 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::uvec4>::operator=;
|
||||
|
||||
protected:
|
||||
glm::uvec4 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::vec2>::operator=;
|
||||
|
||||
protected:
|
||||
glm::vec2 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::vec3>::operator=;
|
||||
|
||||
protected:
|
||||
glm::vec3 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -43,9 +43,6 @@ public:
|
||||
int typeLua() const override;
|
||||
|
||||
using TemplateProperty<glm::vec4>::operator=;
|
||||
|
||||
protected:
|
||||
glm::vec4 fromLuaConversion(lua_State* state, bool& success) const override;
|
||||
};
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
Reference in New Issue
Block a user