From 26adb27bf5d9b0cf8a143abe72ec5ec8541b473e Mon Sep 17 00:00:00 2001 From: Katsuya100 Date: Sun, 12 Feb 2023 19:44:22 +0900 Subject: [PATCH 1/2] Enabling static access with the _get meta method. --- squirrel/sqclass.cpp | 9 +++++++++ squirrel/sqclass.h | 1 + squirrel/sqvm.cpp | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/squirrel/sqclass.cpp b/squirrel/sqclass.cpp index 53a29763..0bb56da3 100644 --- a/squirrel/sqclass.cpp +++ b/squirrel/sqclass.cpp @@ -146,6 +146,15 @@ bool SQClass::GetAttributes(const SQObjectPtr &key,SQObjectPtr &outval) return false; } +bool SQClass::GetMetaMethod(SQVM* SQ_UNUSED_ARG(v), SQMetaMethod mm, SQObjectPtr& res) +{ + if (sq_type(_metamethods[mm]) != OT_NULL) { + res = _metamethods[mm]; + return true; + } + return false; +} + /////////////////////////////////////////////////////////////////////// void SQInstance::Init(SQSharedState *ss) { diff --git a/squirrel/sqclass.h b/squirrel/sqclass.h index 60d3d21b..50c43be4 100644 --- a/squirrel/sqclass.h +++ b/squirrel/sqclass.h @@ -72,6 +72,7 @@ struct SQClass : public CHAINABLE_OBJ #endif SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval); SQInstance *CreateInstance(); + bool GetMetaMethod(SQVM* v, SQMetaMethod mm, SQObjectPtr& res); SQTable *_members; SQClass *_base; SQClassMemberVec _defaultvalues; diff --git a/squirrel/sqvm.cpp b/squirrel/sqvm.cpp index 051b94f9..1379227b 100644 --- a/squirrel/sqvm.cpp +++ b/squirrel/sqvm.cpp @@ -1361,6 +1361,24 @@ SQInteger SQVM::FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObj } } break; + case OT_CLASS: { + SQObjectPtr closure; + if (_class(self)->GetMetaMethod(this, MT_GET, closure)) { + Push(self); Push(key); + _nmetamethodscall++; + AutoDec ad(&_nmetamethodscall); + if (Call(closure, 2, _top - 2, dest, SQFalse)) { + Pop(2); + return FALLBACK_OK; + } + else { + Pop(2); + if (sq_type(_lasterror) != OT_NULL) { //NULL means "clean failure" (not found) + return FALLBACK_ERROR; + } + } + } + } default: break;//shutup GCC 4.x } // no metamethod or no fallback type From 1ae52f70377d511d4f2598912af17df731a50946 Mon Sep 17 00:00:00 2001 From: Katsuya100 Date: Tue, 14 Feb 2023 19:17:43 +0900 Subject: [PATCH 2/2] break --- squirrel/sqvm.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/squirrel/sqvm.cpp b/squirrel/sqvm.cpp index 1379227b..fdbb212d 100644 --- a/squirrel/sqvm.cpp +++ b/squirrel/sqvm.cpp @@ -1379,6 +1379,7 @@ SQInteger SQVM::FallBackGet(const SQObjectPtr &self,const SQObjectPtr &key,SQObj } } } + break; default: break;//shutup GCC 4.x } // no metamethod or no fallback type