Cleaner way to define userdata templates
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
eda15e501d
commit
ecfc1ae3b7
|
@ -5,7 +5,8 @@
|
|||
\brief Begins creating an invokable function. Make sure to call PORYGON_USERDATA_END after this.
|
||||
\returns The start of an invokable function with the name __createUserData. This can be called to return a userdata object.
|
||||
*/
|
||||
#define PORYGON_USERDATA_START() \
|
||||
#define PORYGON_USERDATA_START(type) \
|
||||
using T_USERDATA = type; \
|
||||
static Porygon::UserData::UserData* __createUserData(){ \
|
||||
return new Porygon::UserData::UserData({ \
|
||||
|
||||
|
@ -19,8 +20,8 @@
|
|||
\param fields The fields of the object.
|
||||
\returns an invokable static function with the name __createUserData. This can be called to generate a userdata object.
|
||||
*/
|
||||
#define PORYGON_USERDATA(fields) \
|
||||
PORYGON_USERDATA_START() \
|
||||
#define PORYGON_USERDATA(type, fields) \
|
||||
PORYGON_USERDATA_START(type) \
|
||||
fields \
|
||||
PORYGON_USERDATA_END()
|
||||
|
||||
|
@ -28,16 +29,16 @@
|
|||
#define PORYGON_FLOAT_TYPE ((Porygon::ScriptType*)new Porygon::NumericScriptType(true, true))
|
||||
#define PORYGON_STRING_TYPE ((Porygon::ScriptType*)new Porygon::StringScriptType(false, 0))
|
||||
|
||||
#define PORYGON_FIELD(userDataTypeName, fieldName, fieldType, getterHelper, setterHelper) \
|
||||
#define PORYGON_FIELD(fieldName, fieldType, getterHelper, setterHelper) \
|
||||
{ \
|
||||
Porygon::Utilities::HashedString::ConstHash(#fieldName), \
|
||||
new Porygon::UserData::UserDataField(fieldType, \
|
||||
[](void* obj) -> Porygon::Evaluation::EvalValue* { return new getterHelper;}, \
|
||||
[](void* obj, Porygon::Evaluation::EvalValue* val) { ((userDataTypeName*)obj)->fieldName = setterHelper;} \
|
||||
[](void* obj, Porygon::Evaluation::EvalValue* val) { ((T_USERDATA*)obj)->fieldName = setterHelper;} \
|
||||
) \
|
||||
}, \
|
||||
|
||||
#define PORYGON_READONLY_FIELD(userDataTypeName, fieldName, fieldType, getterHelper) \
|
||||
#define PORYGON_READONLY_FIELD(fieldName, fieldType, getterHelper) \
|
||||
{ \
|
||||
Porygon::Utilities::HashedString::ConstHash(#fieldName), \
|
||||
new Porygon::UserData::UserDataField(fieldType, \
|
||||
|
@ -46,24 +47,24 @@
|
|||
) \
|
||||
}, \
|
||||
|
||||
#define PORYGON_INTEGER_FIELD(userDataTypeName, fieldName) \
|
||||
PORYGON_FIELD(userDataTypeName, fieldName, PORYGON_INTEGER_TYPE, \
|
||||
Porygon::Evaluation::IntegerEvalValue(((userDataTypeName*)obj)->fieldName), val->EvaluateInteger())
|
||||
#define PORYGON_INTEGER_FIELD(fieldName) \
|
||||
PORYGON_FIELD(fieldName, PORYGON_INTEGER_TYPE, \
|
||||
Porygon::Evaluation::IntegerEvalValue(((T_USERDATA*)obj)->fieldName), val->EvaluateInteger())
|
||||
|
||||
#define PORYGON_READONLY_INTEGER_FIELD(userDataTypeName, fieldName) \
|
||||
PORYGON_READONLY_FIELD(userDataTypeName, fieldName, PORYGON_INTEGER_TYPE, \
|
||||
Porygon::Evaluation::IntegerEvalValue(((userDataTypeName*)obj)->fieldName))
|
||||
#define PORYGON_READONLY_INTEGER_FIELD(fieldName) \
|
||||
PORYGON_READONLY_FIELD(fieldName, PORYGON_INTEGER_TYPE, \
|
||||
Porygon::Evaluation::IntegerEvalValue(((T_USERDATA*)obj)->fieldName))
|
||||
|
||||
#define PORYGON_FLOAT_FIELD(userDataTypeName, fieldName) \
|
||||
PORYGON_FIELD(userDataTypeName, fieldName, PORYGON_FLOAT_TYPE, \
|
||||
Porygon::EvaluationFloatEvalValue(((userDataTypeName*)obj)->fieldName), val->EvaluateFloat())
|
||||
#define PORYGON_FLOAT_FIELD(fieldName) \
|
||||
PORYGON_FIELD(fieldName, PORYGON_FLOAT_TYPE, \
|
||||
Porygon::EvaluationFloatEvalValue(((T_USERDATA*)obj)->fieldName), val->EvaluateFloat())
|
||||
|
||||
#define PORYGON_READONLY_FLOAT_FIELD(userDataTypeName, fieldName) \
|
||||
PORYGON_READONLY_FIELD(userDataTypeName, fieldName, PORYGON_FLOAT_TYPE, \
|
||||
Porygon::EvaluationFloatEvalValue(((userDataTypeName*)obj)->fieldName))
|
||||
#define PORYGON_READONLY_FLOAT_FIELD(fieldName) \
|
||||
PORYGON_READONLY_FIELD(fieldName, PORYGON_FLOAT_TYPE, \
|
||||
Porygon::EvaluationFloatEvalValue(((T_USERDATA*)obj)->fieldName))
|
||||
|
||||
|
||||
#define PORYGON_FUNCTION(userDataTypeName, fieldName, returnType, ...) \
|
||||
#define PORYGON_FUNCTION(fieldName, returnType, ...) \
|
||||
{ \
|
||||
Porygon::Utilities::HashedString::ConstHash(#fieldName), \
|
||||
new Porygon::UserData::UserDataField(Porygon::UserData::UserDataFunctionType::FromRawPointers(returnType, {__VA_ARGS__} ), \
|
||||
|
@ -72,14 +73,14 @@
|
|||
[](void* obj) -> Porygon::Evaluation::EvalValue* { \
|
||||
return new Porygon::UserData::UserDataFunction( \
|
||||
[](void* obj, Porygon::Evaluation::EvalValue* par[], int parameterCount) \
|
||||
-> Porygon::Evaluation::EvalValue*{return ((userDataTypeName*)obj)->invoke__##fieldName(obj, par, parameterCount);}, \
|
||||
-> Porygon::Evaluation::EvalValue*{return ((T_USERDATA*)obj)->invoke__##fieldName(obj, par, parameterCount);}, \
|
||||
obj);}, \
|
||||
nullptr) \
|
||||
},
|
||||
|
||||
|
||||
#define PORYGON_INTEGER_FUNCTION(userDataTypeName, fieldName, ...) \
|
||||
PORYGON_FUNCTION(userDataTypeName, fieldName, new Porygon::NumericScriptType(true, false), __VA_ARGS__ )
|
||||
#define PORYGON_INTEGER_FUNCTION(fieldName, ...) \
|
||||
PORYGON_FUNCTION(fieldName, new Porygon::NumericScriptType(true, false), __VA_ARGS__ )
|
||||
|
||||
|
||||
/*!
|
||||
|
|
|
@ -27,14 +27,13 @@ public:
|
|||
|
||||
// Declare script properties
|
||||
private:
|
||||
#define TYPE UserDataTestObject
|
||||
PORYGON_PREPARE_FUNCTION(TYPE, getFoo, IntegerEvalValue)
|
||||
PORYGON_PREPARE_FUNCTION(TYPE, Addition, IntegerEvalValue, (par[0] -> EvaluateInteger()), (par[1] -> EvaluateInteger()))
|
||||
PORYGON_PREPARE_FUNCTION(UserDataTestObject, getFoo, IntegerEvalValue)
|
||||
PORYGON_PREPARE_FUNCTION(UserDataTestObject, Addition, IntegerEvalValue, (par[0] -> EvaluateInteger()), (par[1] -> EvaluateInteger()))
|
||||
public:
|
||||
PORYGON_USERDATA(
|
||||
PORYGON_INTEGER_FIELD(TYPE, foo)
|
||||
PORYGON_INTEGER_FUNCTION(TYPE, getFoo)
|
||||
PORYGON_INTEGER_FUNCTION(TYPE, Addition, PORYGON_INTEGER_TYPE, PORYGON_INTEGER_TYPE)
|
||||
PORYGON_USERDATA(UserDataTestObject,
|
||||
PORYGON_INTEGER_FIELD(foo)
|
||||
PORYGON_INTEGER_FUNCTION(getFoo)
|
||||
PORYGON_INTEGER_FUNCTION(Addition, PORYGON_INTEGER_TYPE, PORYGON_INTEGER_TYPE)
|
||||
)
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue