mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 23:35:03 +01:00
add lua/C++ dynamic_cast<>
This commit is contained in:
parent
79245a296b
commit
67083d65e4
3 changed files with 40 additions and 0 deletions
|
|
@ -379,6 +379,29 @@ struct CFunc
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <class T, class R>
|
||||||
|
struct CastClass
|
||||||
|
{
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
T * const t = Userdata::get <T> (L, 1, false );
|
||||||
|
Stack <R*>::push (L, dynamic_cast<R*>(t));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class R>
|
||||||
|
struct CastConstClass
|
||||||
|
{
|
||||||
|
static int f (lua_State* L)
|
||||||
|
{
|
||||||
|
T const* const t = Userdata::get <T> (L, 1, true);
|
||||||
|
Stack <R const*>::push (L, dynamic_cast<R const*>(t));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct PtrNullCheck
|
struct PtrNullCheck
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1048,6 +1048,22 @@ private:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
Class <T>& addCast (char const* name)
|
||||||
|
{
|
||||||
|
PRINTDOC("Cast", _name << name,
|
||||||
|
type_name< U >(),
|
||||||
|
type_name< U >() << " (" << type_name< T >() << "::*)()")
|
||||||
|
|
||||||
|
assert (lua_istable (L, -1));
|
||||||
|
lua_pushcclosure (L, &CFunc::CastClass <T, U>::f, 0);
|
||||||
|
rawsetfield (L, -3, name); // class table
|
||||||
|
|
||||||
|
lua_pushcclosure (L, &CFunc::CastConstClass <T, U>::f, 0);
|
||||||
|
rawsetfield (L, -4, name); // const table
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** C Array to/from table */
|
/** C Array to/from table */
|
||||||
|
|
|
||||||
|
|
@ -384,6 +384,7 @@ foreach ($doc as $b) {
|
||||||
'cand' => canonical_decl ($b)
|
'cand' => canonical_decl ($b)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case "Cast":
|
||||||
case "Weak/Shared Pointer Cast":
|
case "Weak/Shared Pointer Cast":
|
||||||
checkclass ($b);
|
checkclass ($b);
|
||||||
$classlist[luafn2class ($b['lua'])]['cast'][] = array (
|
$classlist[luafn2class ($b['lua'])]['cast'][] = array (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue