mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
Add Lua typecast from C++ vector to C-Array
This is useful for MIDI bytes amongst other things
This commit is contained in:
parent
5fb83da69c
commit
5e1a73a28c
3 changed files with 20 additions and 14 deletions
|
|
@ -352,32 +352,27 @@ LuaBindings::stddef (lua_State* L)
|
||||||
.beginStdList <std::string> ("StringList")
|
.beginStdList <std::string> ("StringList")
|
||||||
.endClass ()
|
.endClass ()
|
||||||
|
|
||||||
// std::vector<std::string>
|
|
||||||
.beginStdVector <std::string> ("StringVector")
|
.beginStdVector <std::string> ("StringVector")
|
||||||
.endClass ()
|
.endClass ()
|
||||||
|
|
||||||
// std::vector<float>
|
|
||||||
.beginStdVector <float> ("FloatVector")
|
.beginStdVector <float> ("FloatVector")
|
||||||
.endClass ()
|
.endClass ()
|
||||||
|
|
||||||
// register float array (uint8_t*)
|
.beginStdVector <uint8_t> ("ByteVector")
|
||||||
.registerArray <uint8_t> ("ByteArray")
|
.endClass ()
|
||||||
|
|
||||||
// register float array (float*)
|
|
||||||
.registerArray <float> ("FloatArray")
|
|
||||||
|
|
||||||
// register float array (int32_t*)
|
|
||||||
.registerArray <int32_t> ("IntArray")
|
|
||||||
|
|
||||||
// std::vector<float*>
|
|
||||||
.beginStdVector <float*> ("FloatArrayVector")
|
.beginStdVector <float*> ("FloatArrayVector")
|
||||||
.endClass ()
|
.endClass ()
|
||||||
|
|
||||||
|
.registerArray <uint8_t> ("ByteArray")
|
||||||
|
.registerArray <float> ("FloatArray")
|
||||||
|
.registerArray <int32_t> ("IntArray")
|
||||||
|
|
||||||
// samplepos_t, sampleoffset_t lists e.g. AnalysisFeatureList
|
// samplepos_t, sampleoffset_t lists e.g. AnalysisFeatureList
|
||||||
.beginStdList <int64_t> ("Int64List")
|
.beginStdList <int64_t> ("Int64List")
|
||||||
.endClass ()
|
.endClass ()
|
||||||
|
|
||||||
// TODO std::set
|
// TODO std::set
|
||||||
.endNamespace ();
|
.endNamespace ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1148,6 +1148,17 @@ struct CFunc
|
||||||
if (!t) { return luaL_error (L, "cannot derefencee shared_ptr"); }
|
if (!t) { return luaL_error (L, "cannot derefencee shared_ptr"); }
|
||||||
return tableToListHelper<T, C> (L, t->get());
|
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>
|
template <class T, class C>
|
||||||
|
|
|
||||||
|
|
@ -1938,11 +1938,11 @@ public:
|
||||||
return beginConstStdVector<T> (name)
|
return beginConstStdVector<T> (name)
|
||||||
.addVoidConstructor ()
|
.addVoidConstructor ()
|
||||||
.addFunction ("push_back", (void (LT::*)(const T&))<::push_back)
|
.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>);
|
.addExtCFunction ("add", &CFunc::tableToList<T, LT>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue