mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-09 07:05:43 +01:00
allow to compare C class instances from lua
This commit is contained in:
parent
afca178e45
commit
204c8016c7
3 changed files with 31 additions and 0 deletions
|
|
@ -366,6 +366,19 @@ struct CFunc
|
|||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct ClassEqualCheck
|
||||
{
|
||||
static int f (lua_State* L)
|
||||
{
|
||||
T const* const t0 = Userdata::get <T> (L, 1, true);
|
||||
T const* const t1 = Userdata::get <T> (L, 2, true);
|
||||
Stack <bool>::push (L, t0 == t1);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct PtrNullCheck
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1039,6 +1039,15 @@ private:
|
|||
return addConstructor <void (*) ()> ();
|
||||
}
|
||||
|
||||
Class <T>& addEqualCheck ()
|
||||
{
|
||||
PRINTDOC("Member Function", _name << "sameinstance", std::string("bool"), std::string("void (*)(" + type_name <T>() + ")"))
|
||||
assert (lua_istable (L, -1));
|
||||
lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
|
||||
rawsetfield (L, -3, "sameinstance");
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** C Array to/from table */
|
||||
|
|
@ -1060,6 +1069,8 @@ private:
|
|||
std::string(""), "int (*)(lua_State*)")
|
||||
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 <T>() + "*)"))
|
||||
|
||||
m_stackSize = parent->m_stackSize + 3;
|
||||
parent->m_stackSize = 0;
|
||||
|
|
@ -1117,6 +1128,10 @@ private:
|
|||
|
||||
lua_pushcclosure (L, &CFunc::setTable <T>, 0);
|
||||
rawsetfield (L, -3, "set_table"); // class table
|
||||
|
||||
lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
|
||||
rawsetfield (L, -3, "sameinstance");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue