diff options
author | Robin Gareus <robin@gareus.org> | 2019-12-01 21:32:10 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-12-01 21:32:10 +0100 |
commit | 5e1a73a28c07ba8c9c80b27abdacdc6da5f080bd (patch) | |
tree | 521f7ea21b12348bb102639b5137b1ad0981603a /libs/lua | |
parent | 5fb83da69cd22cdb8f925f00c550b854153b84f4 (diff) |
Add Lua typecast from C++ vector to C-Array
This is useful for MIDI bytes amongst other things
Diffstat (limited to 'libs/lua')
-rw-r--r-- | libs/lua/LuaBridge/detail/CFunctions.h | 11 | ||||
-rw-r--r-- | libs/lua/LuaBridge/detail/Namespace.h | 4 |
2 files changed, 13 insertions, 2 deletions
diff --git a/libs/lua/LuaBridge/detail/CFunctions.h b/libs/lua/LuaBridge/detail/CFunctions.h index 22dc115a6a..88c30fc4ad 100644 --- a/libs/lua/LuaBridge/detail/CFunctions.h +++ b/libs/lua/LuaBridge/detail/CFunctions.h @@ -1148,6 +1148,17 @@ struct CFunc if (!t) { return luaL_error (L, "cannot derefencee shared_ptr"); } return tableToListHelper<T, C> (L, t->get()); } + //-------------------------------------------------------------------------- + + + template <class T, class C> + static int vectorToArray (lua_State *L) + { + C * const t = Userdata::get<C> (L, 1, false); + T * a = &((*t)[0]); + Stack <T*>::push (L, a); + return 1; + } //-------------------------------------------------------------------------- template <class T, class C> diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h index 0ea453e932..46fdaa5252 100644 --- a/libs/lua/LuaBridge/detail/Namespace.h +++ b/libs/lua/LuaBridge/detail/Namespace.h @@ -1938,11 +1938,11 @@ public: return beginConstStdVector<T> (name) .addVoidConstructor () .addFunction ("push_back", (void (LT::*)(const T&))<::push_back) + .addFunction ("clear", (void (LT::*)())<::clear) + .addExtCFunction ("to_array", &CFunc::vectorToArray<T, LT>) .addExtCFunction ("add", &CFunc::tableToList<T, LT>); } - - //---------------------------------------------------------------------------- template <class T> |