From 5d4f920007b4202d497f4dc353907aab4162c5e8 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 11 Sep 2016 20:10:29 +0300 Subject: [PATCH] Implement another constructor for Sqrat's Object type to grab an object reference right from the stack. --- include/sqrat/sqratObject.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/sqrat/sqratObject.h b/include/sqrat/sqratObject.h index b87f9a27..b4c5a539 100644 --- a/include/sqrat/sqratObject.h +++ b/include/sqrat/sqratObject.h @@ -105,6 +105,21 @@ public: sq_addref(vm, &obj); } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Constructs an Object from a Squirrel object at a certain index on the stack + /// + /// \param i Index of the Squirrel object on stack + /// \param v VM that the object will exist in + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Object(SQInteger i, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) { + if (SQ_FAILED(sq_getstackobj(vm, i, &obj))) { + sq_resetobject(&obj); + } else { + sq_addref(vm, &obj); + } + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Constructs an Object from a C++ instance ///