How to bind a static member variable

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How to bind a static member variable

Lorenzo Pistone
Hello,
I cannot find any reference on how to bind a static member variable, so
that I can access it from lua as myclass.staticmember.

Cheers.

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Iliya Trendafilov
Hi,

In the (rather old) docs, there's an example binding static function: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions
Binding static members should be obvious from there



On Sun, Apr 7, 2013 at 1:52 PM, Lorenzo Pistone <[hidden email]> wrote:
Hello,
I cannot find any reference on how to bind a static member variable, so
that I can access it from lua as myclass.staticmember.

Cheers.

------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Lorenzo Pistone
I've tried to do so, but I'm getting "def_readwrite is not a member of luabind". I have successfully bound a static member _function_ though (with .def).

On 04/08/2013 08:40 AM, Iliya Trendafilov wrote:
Hi,

In the (rather old) docs, there's an example binding static function: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions
Binding static members should be obvious from there



On Sun, Apr 7, 2013 at 1:52 PM, Lorenzo Pistone <[hidden email]> wrote:
Hello,
I cannot find any reference on how to bind a static member variable, so
that I can access it from lua as myclass.staticmember.

Cheers.

------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Tony Kostanjsek
In reply to this post by Lorenzo Pistone
If you don't mind creating a copy, you can simply put the value in a variable in the appropriate Lua namespace.

On 07.04.2013, at 12:52, Lorenzo Pistone <[hidden email]> wrote:

> Hello,
> I cannot find any reference on how to bind a static member variable, so
> that I can access it from lua as myclass.staticmember.
>
> Cheers.
>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Lorenzo Pistone
I don't know how to do that either. Also, it would not really be a
problem, but I'd like to master the API.

On 04/08/2013 12:42 PM, Tony Kostanjsek wrote:

> If you don't mind creating a copy, you can simply put the value in a variable in the appropriate Lua namespace.
>
> On 07.04.2013, at 12:52, Lorenzo Pistone <[hidden email]> wrote:
>
>> Hello,
>> I cannot find any reference on how to bind a static member variable, so
>> that I can access it from lua as myclass.staticmember.
>>
>> Cheers.
>>
>> ------------------------------------------------------------------------------
>> 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
>> [hidden email]
>> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Timo Boll
In reply to this post by Lorenzo Pistone
Did you try .def_readonly? Maybe the error is a result of trying to bind a const type with .def

Am 08.04.2013 um 12:32 schrieb Lorenzo Pistone:

I've tried to do so, but I'm getting "def_readwrite is not a member of luabind". I have successfully bound a static member _function_ though (with .def).

On 04/08/2013 08:40 AM, Iliya Trendafilov wrote:
Hi,

In the (rather old) docs, there's an example binding static function: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions
Binding static members should be obvious from there



On Sun, Apr 7, 2013 at 1:52 PM, Lorenzo Pistone <[hidden email]> wrote:
Hello,
I cannot find any reference on how to bind a static member variable, so
that I can access it from lua as myclass.staticmember.

Cheers.


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Lorenzo Pistone
still the same. This is a chopped down version of my code:

    #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)];
    }


On 04/08/2013 01:17 PM, Timo Boll wrote:
Did you try .def_readonly? Maybe the error is a result of trying to bind a const type with .def

Am 08.04.2013 um 12:32 schrieb Lorenzo Pistone:

I've tried to do so, but I'm getting "def_readwrite is not a member of luabind". I have successfully bound a static member _function_ though (with .def).

On 04/08/2013 08:40 AM, Iliya Trendafilov wrote:
Hi,

In the (rather old) docs, there's an example binding static function: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions
Binding static members should be obvious from there



On Sun, Apr 7, 2013 at 1:52 PM, Lorenzo Pistone <[hidden email]> wrote:
Hello,
I cannot find any reference on how to bind a static member variable, so
that I can access it from lua as myclass.staticmember.

Cheers.



------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Ryan Pavlik-4

On Mon, Apr 8, 2013 at 6:33 AM, Lorenzo Pistone <[hidden email]> 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

[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Lorenzo Pistone
So how does one bind instances of objects in globally, or in a namespace? Possibly avoiding that the lua part will ever override or unreference them.

On 04/08/2013 08:45 PM, Ryan Pavlik wrote:

On Mon, Apr 8, 2013 at 6:33 AM, Lorenzo Pistone <[hidden email]> 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

[hidden email]
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Tony Kostanjsek
In reply to this post by Ryan Pavlik-4
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 <[hidden email]> wrote:

>
> On Mon, Apr 8, 2013 at 6:33 AM, Lorenzo Pistone <[hidden email]> 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
>
> [hidden email]
> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Lorenzo Pistone
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 <[hidden email]> wrote:
>
>> On Mon, Apr 8, 2013 at 6:33 AM, Lorenzo Pistone <[hidden email]> 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
>>
>> [hidden email]
>> 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
>> [hidden email]
>> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: How to bind a static member variable

Tony Kostanjsek
yes. IIRC you can just bind your class "A", then treat _G.A as a table and just add stuff to it, like the static const value.

On 08.04.2013, at 21:21, Lorenzo Pistone <[hidden email]> wrote:

> 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 <[hidden email]> wrote:
>>
>>> On Mon, Apr 8, 2013 at 6:33 AM, Lorenzo Pistone <[hidden email]> 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
>>>
>>> [hidden email]
>>> 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
>>> [hidden email]
>>> 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
>> [hidden email]
>> 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
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user