#ifndef PORYGONLANG_USERDATAFUNCTION_HPP #define PORYGONLANG_USERDATAFUNCTION_HPP #include #include "../Evaluator/EvalValues/ScriptFunctionEvalValue.hpp" namespace Porygon::UserData{ class UserDataFunction : public Evaluation::GenericFunctionEvalValue { Evaluation::EvalValue* (*_call)(void* obj, EvalValue* parameters[], int parameterCount); void *_obj; UserDataFunction(Evaluation::EvalValue* (*call)(void* obj, EvalValue* parameters[], int parameterCount), void* obj, shared_ptr type, size_t hash) : GenericFunctionEvalValue(std::move(type), hash){ _call = call; _obj = obj; } public: UserDataFunction(Evaluation::EvalValue* (*call)(void* obj, EvalValue* parameters[], int parameterCount), void* obj, shared_ptr type) : GenericFunctionEvalValue(std::move(type), rand()){ _call = call; _obj = obj; } EvalValue* Call(EvalValue* parameters[], int parameterCount){ return _call(_obj, parameters, parameterCount); } const shared_ptr Clone() const final { // We don't run make_shared here as it can't call private constructors return shared_ptr(new UserDataFunction(_call, _obj, _type, _hash)); } }; } #endif //PORYGONLANG_USERDATAFUNCTION_HPP