我在尝试导出向量类
.beginClass<Vector>("Vector")
.addConstructor<void(*)()>()
.addConstructor<void(*)(float, float, float)>()
.addFunction("__eq", &Vector::operator==)
.addFunction("__add", &Vector::operator+)
.addData("x", &Vector::x)
.addData("y", &Vector::y)
.addData("z", &Vector::z)
.addFunction("Length", &Vector::Length)
.addFunction("Angle", &Vector::Angle)
.addFunction("Distance", &Vector::DistTo)
.endClass()但当我尝试做其他3个操作符,我有多个超载为他们。我如何指定我想使用哪一个,这甚至可能吗?
发布于 2015-12-14 09:01:11
所以我做了一个加/减/乘/除函数,然后调用它。我猜操作人员只是不想遵守。
发布于 2015-12-14 00:39:04
如果您有一个函数重载int MyClass::Func(int)和MyClass* MyClass::Func(MyClass),那么您可以按以下方式定义要使用的重载。在本例中,我选择使用MyClass* MyClass::Func(MyClass)作为重载。
.addFunction("Func", (MyClass*(MyClass::*)(MyClass)) &MyClass::Func)所以这里发生的是,函数签名提供了指向函数的指针。
发布于 2017-04-14 03:35:33
如果您定义了一个类A,则可以通过这种方式来实现这一点。
.addFunction("__eq", &A::equal )“平等”应声明如下:
bool A::equal( const A & )然后:
if obj1 == obj2 then
end“平等”就行了!
但是如果您实现了A类B的子类:公共A
威尔花了你很多时间!
首先,必须对模板类或模板方法进行专门化
luabridge::UserdataValue
luabridge::UserdataPtr::push(lua_State* const L, T* const p)指定您需要对对象或指针进行重新排序的类的(Meta)表
您应该阅读luabrid的源代码来完成这一任务!
然后!
你应该把这个功能再一次归给B!
.addFunction("__eq", &B::equal )lua代码:
local inst_a = app.new_class_A();
local inst_b = app.new_class_B();
-- this will call the '__eq' in B's metatable
if( inst_b == inst_a )then
end
-- this will call the '__eq' in A's metatable
if( inst_a == inst_b )then
end在调用__eq时,luabrid将不会搜索该类的父级元数据表,因此您应该再次对A的子类进行重新排序!
希望它能帮到你!为我糟糕的英语道歉!
https://stackoverflow.com/questions/34257926
复制相似问题