From 50d6f146f4cd24b7ea4532ec70fae348056acc32 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 21 May 2016 15:43:19 +0200 Subject: allow lua to access array at an offset --- libs/lua/LuaBridge/detail/CFunctions.h | 8 ++++++++ libs/lua/LuaBridge/detail/Namespace.h | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'libs/lua') diff --git a/libs/lua/LuaBridge/detail/CFunctions.h b/libs/lua/LuaBridge/detail/CFunctions.h index 6f43919216..15bc7022b3 100644 --- a/libs/lua/LuaBridge/detail/CFunctions.h +++ b/libs/lua/LuaBridge/detail/CFunctions.h @@ -969,6 +969,14 @@ struct CFunc return 0; } + // return same array at an offset + template + static int offsetArray (lua_State* L) { + T *v = luabridge::Stack::get (L, 1); + const unsigned int i = luabridge::Stack::get (L, 2); + Stack ::push (L, &v[i]); + return 1; + } //-------------------------------------------------------------------------- /** diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h index c859d8d151..590f25be4a 100644 --- a/libs/lua/LuaBridge/detail/Namespace.h +++ b/libs/lua/LuaBridge/detail/Namespace.h @@ -1070,7 +1070,9 @@ private: PRINTDOC ("Ext C Function", _name << "set_table", std::string(""), "int (*)(lua_State*)") PRINTDOC("Member Function", _name << "sameinstance", - std::string("bool"), std::string("void (*)(" + type_name () + "*)")) + std::string("bool"), std::string("bool (*)(" + type_name () + "*)")) + PRINTDOC("Member Function", _name << "offset", + std::string(type_name () + "*"), std::string(type_name () + "* (*)(unsigned int)")) m_stackSize = parent->m_stackSize + 3; parent->m_stackSize = 0; @@ -1132,6 +1134,9 @@ private: lua_pushcclosure (L, &CFunc::ClassEqualCheck ::f, 0); rawsetfield (L, -3, "sameinstance"); + lua_pushcclosure (L, &CFunc::offsetArray , 0); + rawsetfield (L, -3, "offset"); // class table + } else { -- cgit v1.2.3