Re: How to bind a static member variable

Ryan Pavlik <[email protected]> Mon, 8 Apr 2013 13:45:25 -0500
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <CABMFTE_=LUL2tLAT92EqOXQPZC4QGH3kdwjA4G68enyd9T+t8g@mail.gmail.com>
--===============0170852763754413019==
Content-Type: multipart/alternative; boundary=047d7bdca0ba03942a04d9ddd712

--047d7bdca0ba03942a04d9ddd712
Content-Type: text/plain; charset=ISO-8859-1

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

--047d7bdca0ba03942a04d9ddd712
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Mon, Apr 8, 2013 at 6:33 AM, Lorenzo Pistone <span dir=3D"ltr">&lt;<a hr=
ef=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
om</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><tt>=A0=A0=A0 #include &lt;luabind/luabind.hpp&gt;<br>
      </tt><tt>=A0=A0=A0 struct A{</tt><tt><br>
      </tt><tt>=A0=A0=A0 =A0=A0=A0 static const A a;</tt><tt><br>
      </tt><tt>=A0=A0=A0 };</tt><tt><br>
      </tt><tt>=A0=A0=A0 const A A::a;</tt><tt><br>
        =A0=A0=A0 int main(){<br>
        =A0=A0=A0 =A0=A0=A0 luabind::scope sc =3D luabind::class_&lt;A&gt;(=
&quot;A&quot;)<br>
        =A0=A0=A0 =A0=A0=A0 .scope[luabind::def_readonly(&quot;a&quot;, &am=
p;A::a)];<br>
        =A0=A0=A0 }</tt></blockquote></div><br>It seems as though while fun=
ctions can be registered &quot;globally&quot; (in a namespace rather than a=
 class member), no such provision was made for variables/data. =A0I&#39;ve =
added a test here:=A0<a href=3D"https://github.com/rpavlik/luabind/blob/sta=
tic-members/test/test_static_member.cpp">https://github.com/rpavlik/luabind=
/blob/static-members/test/test_static_member.cpp</a>=A0 - the version commi=
tted succeeds but uncommenting the data members causes a compile failure ju=
st as you had noticed. (There is a luabind::def function that mimics the .d=
ef member of luabind::class_, but no such luabind::def_readonly...) =A0I&#3=
9;m not sure if a workaround of setting the variable would work - I&#39;ve =
had a tough time trying to figure out how to bind references to values/data=
 to Lua with LuaBind.</div>
<div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">Ryan<br><br=
 clear=3D"all"><div><br></div>-- <br>Ryan Pavlik<br>HCI Graduate Student<br=
>Virtual Reality Applications Center<br>Iowa State University<br><br><a hre=
f=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a><=
br>
<a href=3D"http://academic.cleardefinition.com" target=3D"_blank">http://ac=
ademic.cleardefinition.com</a>
</div></div>

--047d7bdca0ba03942a04d9ddd712--


--===============0170852763754413019==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
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
--===============0170852763754413019==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user

--===============0170852763754413019==--