Re: How to bind a static member variable
Tony Kostanjsek <[email protected]> Mon, 8 Apr 2013 21:18:11 +0200
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
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