2019-06-28 15:02:38 +00:00
|
|
|
#ifndef PORYGONLANG_USERDATATEMPLATES_HPP
|
|
|
|
#define PORYGONLANG_USERDATATEMPLATES_HPP
|
|
|
|
|
2019-06-28 15:53:37 +00:00
|
|
|
/*!
|
|
|
|
\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.
|
|
|
|
*/
|
2019-06-28 15:02:38 +00:00
|
|
|
#define PORYGON_USERDATA_START() \
|
|
|
|
static Porygon::UserData::UserData* __createUserData(){ \
|
|
|
|
return new Porygon::UserData::UserData({ \
|
|
|
|
|
2019-06-28 15:53:37 +00:00
|
|
|
/*!
|
|
|
|
\brief Ends creation of invokable function to create userdata.
|
|
|
|
*/
|
2019-06-28 15:02:38 +00:00
|
|
|
#define PORYGON_USERDATA_END() });};
|
|
|
|
|
2019-06-28 15:53:37 +00:00
|
|
|
/*!
|
|
|
|
\brief Creates an invokable static function with the name __createUserData. This can be called to generate a userdata object.
|
|
|
|
\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() \
|
|
|
|
fields \
|
|
|
|
PORYGON_USERDATA_END()
|
|
|
|
|
2019-06-28 15:02:38 +00:00
|
|
|
#define PORYGON_INTEGER_TYPE ((Porygon::ScriptType*)new Porygon::NumericScriptType(true, false))
|
|
|
|
#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) \
|
|
|
|
{ \
|
|
|
|
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;} \
|
|
|
|
) \
|
|
|
|
}, \
|
|
|
|
|
|
|
|
#define PORYGON_READONLY_FIELD(userDataTypeName, fieldName, fieldType, getterHelper) \
|
|
|
|
{ \
|
|
|
|
Porygon::Utilities::HashedString::ConstHash(#fieldName), \
|
|
|
|
new Porygon::UserData::UserDataField(fieldType, \
|
|
|
|
[](void* obj) -> Porygon::Evaluation::EvalValue* { return new getterHelper;}, \
|
|
|
|
nullptr \
|
|
|
|
) \
|
|
|
|
}, \
|
|
|
|
|
|
|
|
#define PORYGON_INTEGER_FIELD(userDataTypeName, fieldName) \
|
|
|
|
PORYGON_FIELD(userDataTypeName, fieldName, PORYGON_INTEGER_TYPE, \
|
|
|
|
Porygon::Evaluation::IntegerEvalValue(((userDataTypeName*)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_FLOAT_FIELD(userDataTypeName, fieldName) \
|
|
|
|
PORYGON_FIELD(userDataTypeName, fieldName, PORYGON_FLOAT_TYPE, \
|
|
|
|
Porygon::EvaluationFloatEvalValue(((userDataTypeName*)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_FUNCTION(userDataTypeName, fieldName, returnType, ...) \
|
|
|
|
{ \
|
|
|
|
Porygon::Utilities::HashedString::ConstHash(#fieldName), \
|
|
|
|
new Porygon::UserData::UserDataField(Porygon::UserData::UserDataFunctionType::FromRawPointers(returnType, {__VA_ARGS__} ), \
|
|
|
|
\
|
|
|
|
\
|
|
|
|
[](void* obj) -> Porygon::Evaluation::EvalValue* { \
|
|
|
|
return new Porygon::UserData::UserDataFunction( \
|
2019-06-28 15:53:37 +00:00
|
|
|
[](void* obj, Porygon::Evaluation::EvalValue* par[], int parameterCount) \
|
|
|
|
-> Porygon::Evaluation::EvalValue*{return ((userDataTypeName*)obj)->invoke__##fieldName(obj, par, parameterCount);}, \
|
2019-06-28 15:02:38 +00:00
|
|
|
obj);}, \
|
|
|
|
nullptr) \
|
|
|
|
},
|
|
|
|
|
2019-06-28 15:53:37 +00:00
|
|
|
|
2019-06-28 15:02:38 +00:00
|
|
|
#define PORYGON_INTEGER_FUNCTION(userDataTypeName, fieldName, ...) \
|
|
|
|
PORYGON_FUNCTION(userDataTypeName, fieldName, new Porygon::NumericScriptType(true, false), __VA_ARGS__ )
|
|
|
|
|
|
|
|
|
2019-06-28 15:53:37 +00:00
|
|
|
/*!
|
|
|
|
\brief Creates an invokable function that resolves EvalValues into actual parameters and vice versa for its return type.
|
|
|
|
\param userDataTypeName The type name of the UserData its created for.
|
|
|
|
\param fieldName The field name of the original function.
|
|
|
|
\param returnType The type for which the constructor gets called.
|
|
|
|
\param ... How to resolve the calling parameters into actual values.
|
|
|
|
\returns An invokable function.
|
|
|
|
*/
|
2019-06-28 15:02:38 +00:00
|
|
|
#define PORYGON_PREPARE_FUNCTION(userDataTypeName, fieldName, returnType, ...) \
|
2019-06-28 15:53:37 +00:00
|
|
|
static Porygon::Evaluation::EvalValue* invoke__##fieldName(void* obj, Porygon::Evaluation::EvalValue* par[], int parameterCount){ \
|
2019-06-28 16:31:24 +00:00
|
|
|
return Porygon::Evaluation::EvalValueHelper::Create(((userDataTypeName*)obj)->fieldName( \
|
2019-06-28 15:02:38 +00:00
|
|
|
__VA_ARGS__ \
|
|
|
|
));}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_USERDATATEMPLATES_HPP
|