From 925679a040432fdc29a68182afd57c41b4468874 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 13 Jun 2023 20:18:43 +0800 Subject: [PATCH] ... --- src/obj.h | 14 +++++++++----- src/vm.h | 10 +++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/obj.h b/src/obj.h index f187fb8e..c089c4db 100644 --- a/src/obj.h +++ b/src/obj.h @@ -21,12 +21,9 @@ typedef int (*LuaStyleFuncC)(VM*); struct NativeFunc { NativeFuncC f; - int argc; // DONOT include self - bool method; + int argc; // this is designed for lua style C bindings - // access it via `_CAST(NativeFunc&, args[-2])._lua_f` - // (-2) or (-1) depends on the calling convention LuaStyleFuncC _lua_f; using UserData = char[32]; @@ -52,7 +49,14 @@ struct NativeFunc { return reinterpret_cast(_userdata); } - NativeFunc(NativeFuncC f, int argc, bool method) : f(f), argc(argc), method(method), _has_userdata(false) {} + NativeFunc(NativeFuncC f, int argc, bool method){ + this->f = f; + this->argc = argc; + if(argc != -1) this->argc += (int)method; + _lua_f = nullptr; + _has_userdata = false; + } + PyObject* operator()(VM* vm, ArgsView args) const; }; diff --git a/src/vm.h b/src/vm.h index dba98671..5e700f4a 100644 --- a/src/vm.h +++ b/src/vm.h @@ -665,9 +665,8 @@ public: }; inline PyObject* NativeFunc::operator()(VM* vm, ArgsView args) const{ - int args_size = args.size() - (int)method; // remove self - if(args_size != argc && argc != -1) { - vm->TypeError(fmt("expected ", argc, " arguments, but got ", args_size)); + if(args.size() != argc && argc != -1) { + vm->TypeError(fmt("expected ", argc, " arguments, but got ", args.size())); } #if DEBUG_EXTRA_CHECK if(f == nullptr) FATAL_ERROR(); @@ -1235,10 +1234,7 @@ inline PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){ if(args.size() < fn.argc){ vm->TypeError(fmt( - "expected ", - fn.argc - (int)method_call, - " positional arguments, but got ", - args.size() - (int)method_call, + "expected ", fn.argc, " positional arguments, but got ", args.size(), " (", fn.decl->code->name, ')' )); }