Re: How to bind a static member variable

Lorenzo Pistone <[email protected]> Mon, 08 Apr 2013 21:21:40 +0200
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
The real code does bind other things rather than only a static member. 
So I guess I have to "reuse"the table that the class definition creates 
(is it a table that it is being created?). So... do I just fetch that 
with the method you proposed, and add my static member?

On 04/08/2013 09:18 PM, Tony Kostanjsek wrote:
> if A::a is a static const, you don't really need a reference to that exact instance, but rather only the value in the correct namespace in Lua. I haven't touched luabind in a while, so treat the following more like pseudo code:
>
> lua_State* L = ...
> luabind::object _G = luabind::globals(L);
> _G["A"] = luabind::newTable();
> _G["A"]["a"] = luabind::object();
> _G["A"]["a"] = A::a;
>
> I must admit I forgot how to correctly implement that last assignment. Again, it's been a while.
> Basically, what you should try is to write the luabind C++ equivalent of the following lua code:
>
> _G.A = {}
> _G.A.a = <your value>
>
> hth,
> Tony
>
>
> On 08.04.2013, at 20:45, Ryan Pavlik <[email protected]> wrote:
>
>> On Mon, Apr 8, 2013 at 6:33 AM, Lorenzo Pistone <[email protected]> wrote:
>>      #include <luabind/luabind.hpp>
>>      struct A{
>>          static const A a;
>>      };
>>      const A A::a;
>>      int main(){
>>          luabind::scope sc = luabind::class_<A>("A")
>>          .scope[luabind::def_readonly("a", &A::a)];
>>      }
>>
>> It seems as though while functions can be registered "globally" (in a namespace rather than a class member), no such provision was made for variables/data.  I've added a test here: https://github.com/rpavlik/luabind/blob/static-members/test/test_static_member.cpp  - the version committed succeeds but uncommenting the data members causes a compile failure just as you had noticed. (There is a luabind::def function that mimics the .def member of luabind::class_, but no such luabind::def_readonly...)  I'm not sure if a workaround of setting the variable would work - I've had a tough time trying to figure out how to bind references to values/data to Lua with LuaBind.
>>
>> Ryan
>>
>>
>> -- 
>> Ryan Pavlik
>> HCI Graduate Student
>> Virtual Reality Applications Center
>> Iowa State University
>>
>> [email protected]
>> http://academic.cleardefinition.com
>> ------------------------------------------------------------------------------
>> Minimize network downtime and maximize team effectiveness.
>> Reduce network management and security costs.Learn how to hire
>> the most talented Cisco Certified professionals. Visit the
>> Employer Resources Portal
>> http://www.cisco.com/web/learning/employer_resources/index.html_______________________________________________
>> luabind-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
> ------------------------------------------------------------------------------
> Minimize network downtime and maximize team effectiveness.
> Reduce network management and security costs.Learn how to hire
> the most talented Cisco Certified professionals. Visit the
> Employer Resources Portal
> http://www.cisco.com/web/learning/employer_resources/index.html
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html