diff --git a/src/obj.h b/src/obj.h index 114f1707..5ad48eb1 100644 --- a/src/obj.h +++ b/src/obj.h @@ -13,16 +13,17 @@ class VM; typedef PyObject* (*NativeFuncC)(VM*, ArgsView); typedef std::function NativeFuncCpp; -using NativeFuncRaw = std::variant; typedef shared_ptr CodeObject_; struct NativeFunc { - NativeFuncRaw f; + NativeFuncC f; + NativeFuncCpp f_cpp; int argc; // DONOT include self bool method; - NativeFunc(NativeFuncRaw f, int argc, bool method) : f(f), argc(argc), method(method) {} + NativeFunc(NativeFuncC f, int argc, bool method) : f(f), argc(argc), method(method) {} + NativeFunc(NativeFuncCpp f, int argc, bool method) : f(nullptr), f_cpp(f), argc(argc), method(method) {} PyObject* operator()(VM* vm, ArgsView args) const; }; diff --git a/src/vm.h b/src/vm.h index 074e6bb5..fc861b42 100644 --- a/src/vm.h +++ b/src/vm.h @@ -395,11 +395,8 @@ inline PyObject* NativeFunc::operator()(VM* vm, ArgsView args) const{ if(argc != -1 && args_size != argc) { vm->TypeError(fmt("expected ", argc, " arguments, but got ", args_size)); } - if(std::holds_alternative(f)){ - return std::get(f)(vm, args); - }else{ - return std::get(f)(vm, args); - } + if(f != nullptr) return f(vm, args); + return f_cpp(vm, args); } inline void CodeObject::optimize(VM* vm){