Use composable Lua types in Property definitions. Allow OptionProperty to receive either indices or descriptions (#3524)

This commit is contained in:
Alexander Bock
2025-02-27 15:42:54 +01:00
committed by GitHub
parent eb3bd4395a
commit 9f77ca1daa
76 changed files with 151 additions and 125 deletions

View File

@@ -35,7 +35,7 @@ public:
std::vector<double> values = std::vector<double>());
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<std::vector<double>>::operator std::vector<double>;
using TemplateProperty<std::vector<double>>::operator=;

View File

@@ -35,7 +35,7 @@ public:
std::vector<int> values = std::vector<int>());
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<std::vector<int>>::operator std::vector<int>;
using TemplateProperty<std::vector<int>>::operator=;

View File

@@ -36,7 +36,7 @@ public:
std::vector<std::string> values = std::vector<std::string>());
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<std::vector<std::string>>::operator std::vector<std::string>;
using TemplateProperty<std::vector<std::string>>::operator=;

View File

@@ -42,7 +42,7 @@ public:
glm::dmat2x2 stepValue = ghoul::createFillMat2x2<double>(0.01));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::dmat2x2>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
glm::dmat3x3 stepValue = ghoul::createFillMat3x3<double>(0.01));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::dmat3x3>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
glm::dmat4x4 stepValue = ghoul::createFillMat4x4<double>(0.01));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::dmat4x4>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
glm::mat2x2 stepValue = ghoul::createFillMat2x2<float>(0.01f));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::mat2x2>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
glm::mat3x3 stepValue = ghoul::createFillMat3x3<float>(0.01f));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::mat3x3>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
glm::mat4x4 stepValue = ghoul::createFillMat4x4<float>(0.01f));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::mat4x4>::operator=;
};

View File

@@ -35,9 +35,6 @@ public:
NumericalProperty(Property::PropertyInfo info, T value, T minimumValue,
T maximumValue, T steppingValue, float exponent = 1.f);
virtual std::string_view className() const override = 0;
virtual int typeLua() const override = 0;
T minValue() const;
void setMinValue(T value);

View File

@@ -82,6 +82,8 @@ public:
* \return The name of this class for reflection purposes
*/
std::string_view className() const override;
ghoul::lua::LuaTypes typeLua() const override;
using IntProperty::operator=;
/**
@@ -160,6 +162,7 @@ public:
private:
static const std::string OptionsKey;
int fromLuaConversion(lua_State* state) const override;
std::string generateAdditionalJsonDescription() const override;
/// The list of options which have been registered with this OptionProperty

View File

@@ -27,6 +27,7 @@
#include <ghoul/misc/dictionary.h>
#include <ghoul/misc/easing.h>
#include <ghoul/lua/lua_types.h>
#include <functional>
#include <string>
#include <string_view>
@@ -195,15 +196,12 @@ public:
/**
* Returns the Lua type that will be put onto the stack in the Property::getLua method
* and which will be consumed by the Property::setLuaValue method. The returned value
* can belong to the set of Lua types: `LUA_TNONE`, `LUA_TNIL`, `LUA_TBOOLEAN`,
* `LUA_TLIGHTUSERDATA`, `LUA_TNUMBER`, `LUA_TSTRING`, `LUA_TTABLE`, `LUA_TFUNCTION`,
* `LUA_TUSERDATA`, or `LUA_TTHREAD`. The default implementation will return
* `LUA_TNONE`.
* can be a combination of any value contained in the `LuaTypes`.
*
* \return The Lua type that will be consumed or produced by the Property::getLuaValue
* and Property::setLuaValue methods.
*/
virtual int typeLua() const;
virtual ghoul::lua::LuaTypes typeLua() const = 0;
/**
* This method encodes the encapsulated \p value of this Property as a `std::string`.

View File

@@ -38,7 +38,7 @@ public:
BoolProperty(Property::PropertyInfo info, bool value = false);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<bool>::operator=;

View File

@@ -41,7 +41,7 @@ public:
double maxValue = std::numeric_limits<double>::max(), double stepValue = 0.01);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<double>::operator=;
};

View File

@@ -41,7 +41,7 @@ public:
float maxValue = std::numeric_limits<float>::max(), float stepValue = 0.01f);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<float>::operator=;
};

View File

@@ -41,7 +41,7 @@ public:
int maxValue = std::numeric_limits<int>::max(), int stepValue = 1);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<int>::operator=;

View File

@@ -42,7 +42,7 @@ public:
long stepValue = long(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<long>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
short stepValue = short(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<short>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
unsigned int stepValue = 1);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<unsigned int>::operator=;

View File

@@ -42,7 +42,7 @@ public:
unsigned long stepValue = 1ul);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<unsigned long>::operator=;
};

View File

@@ -42,7 +42,7 @@ public:
unsigned short stepValue = 1);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<unsigned short>::operator=;
};

View File

@@ -38,7 +38,7 @@ public:
SelectionProperty(Property::PropertyInfo info);
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
/**
* This method sets the stored value to the provided value `val`. If the value is

View File

@@ -34,7 +34,7 @@ public:
StringProperty(Property::PropertyInfo info, std::string value = "");
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<std::string>::operator=;

View File

@@ -66,14 +66,6 @@ public:
*/
TemplateProperty(Property::PropertyInfo info, T value);
/**
* Returns the class name for this TemplateProperty. This method has to be specialized
* for each new type.
*
* \return The class name for the TemplateProperty
*/
virtual std::string_view className() const override = 0;
/**
* Returns the `std::type_info` describing the template parameter `T`. It can be used
* to test against a ghoul::any value before trying to assign it.
@@ -100,9 +92,6 @@ public:
*/
virtual void setLuaValue(lua_State* state) override;
/// \see Property::typeLua
virtual int typeLua() const override = 0;
/**
* This method encodes the stored value into a std::string object. The resulting
* encoding must also be a valid JSON representation fo the property.

View File

@@ -61,6 +61,8 @@ public:
*/
void setLuaValue(lua_State* state) override;
ghoul::lua::LuaTypes typeLua() const;
/**
* Triggers this TriggerProperty.
*/

View File

@@ -40,7 +40,7 @@ public:
glm::dvec2 stepValue = glm::dvec2(0.01));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::dvec2>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::dvec3 stepValue = glm::dvec3(0.01));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::dvec3>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::dvec4 stepValue = glm::dvec4(0.01));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::dvec4>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::ivec2 stepValue = glm::ivec2(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::ivec2>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::ivec3 stepValue = glm::ivec3(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::ivec3>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::ivec4 stepValue = glm::ivec4(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::ivec4>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::uvec2 stepValue = glm::uvec2(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::uvec2>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::uvec3 stepValue = glm::uvec3(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::uvec3>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::uvec4 stepValue = glm::uvec4(1));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::uvec4>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::vec2 stepValue = glm::vec2(0.01f));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::vec2>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::vec3 stepValue = glm::vec3(0.01f));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::vec3>::operator=;
};

View File

@@ -40,7 +40,7 @@ public:
glm::vec4 stepValue = glm::vec4(0.01f));
std::string_view className() const override;
int typeLua() const override;
ghoul::lua::LuaTypes typeLua() const override;
using TemplateProperty<glm::vec4>::operator=;
};