Re: Luabind: C++ referenced variables;

Daniel Wallin <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
hymedia wrote:
> I might have overlooked this  but I can’t find anything replicating this
> within the examples so far,
> 
> I m not crazy about using the properties. I d like to keep a C++
> structur as much as possible. So here is what I do:
> 
> .cpp
> 
> typedef unsigned int UInt;
> 
> class Test
> {
>       public:
>             Test(): val(0) {}
>             ~Test() {}
> 
>             UInt &Get() {return val;}
>             void Set(UInt in_val) {val = in_val;}
>       protected:
>             UInt val;
> };
> 
> Luabind
> 
>       module(in_lua)
>       [
>             class_<Test>("Test")
>             .def(constructor<>())
>             .def("Get", &Test::Get)
>             .def("Set", &Test::Set)
>       ];
>  
> .lua
> 
> myTest = Test();
> myTest:Set(1);
> myVal = myTest:Get();
> 
> Result:
> 
> myTest:Get(); assert: you are trying to use an unregistered type!
> 
> I know for sure the typedef is not an issue here, could have been a int,
> I have no doubts this have been addressed in the pass, but I could
> definitely use a hint.

The problem is that you are returning a reference to a builtin type.
There's no reasonable way to represent this reference in Lua, so luabind
doesn't accept it. I thought using the copy-policy: "copy(result)" would
work here, but it turns out that only works on class types.

If you can't change your function signature, your best bet is using
"tag_function<>" to bypass luabind signature deduction. Something like:

  def("Get", tag_function<UInt(Test const&)>(&Test::get))

-- 
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.