37 lines
1.4 KiB
C++
37 lines
1.4 KiB
C++
|
#ifndef PORYGONLANG_USERDATAFUNCTION_HPP
|
||
|
#define PORYGONLANG_USERDATAFUNCTION_HPP
|
||
|
|
||
|
#include <utility>
|
||
|
#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<GenericFunctionScriptType> 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<GenericFunctionScriptType> type) : GenericFunctionEvalValue(std::move(type), rand()){
|
||
|
_call = call;
|
||
|
_obj = obj;
|
||
|
}
|
||
|
|
||
|
EvalValue* Call(EvalValue* parameters[], int parameterCount){
|
||
|
return _call(_obj, parameters, parameterCount);
|
||
|
}
|
||
|
|
||
|
const shared_ptr<EvalValue> Clone() const final {
|
||
|
// We don't run make_shared here as it can't call private constructors
|
||
|
return shared_ptr<UserDataFunction>(new UserDataFunction(_call, _obj, _type, _hash));
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
|
||
|
#endif //PORYGONLANG_USERDATAFUNCTION_HPP
|