[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: array access "A[i]" and luabind
- From: Sebastian Wolff <sw@...>
- Date: Mon, 23 Nov 2009 09:49:39 +0100
Hello list,
I am evaluating a switch from SWIG to luabind for binding our C++
classes to Lua. So far, luabind looks great in a variety of features,
but I did not figure out how to handle certain metamethods that were no
problem to SWIG at all:
(1) Following the luabind docs it seems that it only binds the subset
of operators which is common to C++ and Lua? So far I could not figure
out how to wrap the __pow operator.
(2) The same goes to __index and __newindex metamethods (As you can
imagine I am working on a linear algebra library).
I can try to set it explicitely, i.e.:
luabind::class_<MyNumber>("MyNumber")
.def(luabind::constructor<const double &>())
.def("__index", &MyNumber::getIndex, luabind::raw(_2))
.def("__newindex", &MyNumber::setIndex, luabind::raw(_2))
.def("__pow", &MyNumber::pow)
In that case I can make the call
A = MyNumber(3.0)
A:__index( ...arguments... )
A:__newindex( ...arguments... )
B = A:__pow(4.0)
But what I expected to enable was
A = MyNumber(3.0)
b = A[ ...argument... ]
A[... argument...] = 2.0
B = A^4.0
Any ideas how one could add this syntax to a userdata type that was
created by Luabind?
Thanks
Sebastian