Adding an overload for the assignment operator in lua for luabind classes
Abhijit Nandy <[email protected]> Fri, 16 Oct 2015 14:24:25 +0530
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <CAJGw_m0Wk-w+X_T2PXAExpNZMxdnjSzQZ3qTxy67p6znmyA1mQ@mail.gmail.com> |
--===============2607249883421690300== Content-Type: multipart/alternative; boundary=94eb2c0874e649d620052234f11e --94eb2c0874e649d620052234f11e Content-Type: text/plain; charset=UTF-8 Hi, Lua does not allow the assignment operator to be overloaded and has no meta function for it. I have got around this by using the proxy pattern and the __index/__newindex meta methods. Now I have begun using classes defined via luabind's object oriented system thats exposed to Lua. I am wondering if the C++ code for Luabind can be changed to allow the assignment operator to be overloaded without changing the code for the Lua interpretor itself. Perhaps such a overload would call into a new meta-method name thats not used by Lua such as '__assign()' This would not conflict with any meta method that Lua already uses and would apply only to instances of luabind classes. I am guessing that the luabind::adl::object class needs to be changed, or perhaps index_proxy. But I am not sufficiently familiar with how luabind forwards calls to existing Lua meta-methods, to its objects. Has anyone explored the C++ code in luabind that supports operator overloading in Lua? Edit: I see some attempts to add a new operator here: https://github.com/decimad/luabind-deboostified/commit/55b1bd9217205253b41ab7d4746637ee5b0d276f If I try the above with the assignment operator though, I do no see it getting called in Lua. Are there any other changes needed in C++ for this? http://stackoverflow.com/questions/33141507/adding-an-overload-for-the-assignment-operator-in-lua-for-luabind-classes Thanks, Abhi --94eb2c0874e649d620052234f11e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;font= -size:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,= sans-serif;line-height:15.6px">Hi,</p><p style=3D"margin:0px 0px 1em;paddin= g:0px;border:0px;font-size:15px;clear:both;font-family:'Helvetica Neue&= #39;,Helvetica,Arial,sans-serif;line-height:15.6px">Lua does not allow the = assignment operator to be overloaded and has no meta function for it. I hav= e got around this by using the proxy pattern and the __index/__newindex met= a methods.</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-si= ze:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,san= s-serif;line-height:15.6px">Now I have begun using classes defined via luab= ind's object oriented system thats exposed to Lua.</p><p style=3D"margi= n:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;font-family:= 'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:15.6px">I a= m wondering if the C++ code for Luabind can be changed to allow the assignm= ent operator to be overloaded without changing the code for the Lua interpr= etor itself.</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-= size:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,s= ans-serif;line-height:15.6px">Perhaps such a overload would call into a new= meta-method name thats not used by Lua such as '__assign()'</p><p = style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:bot= h;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-heig= ht:15.6px">This would not conflict with any meta method that Lua already us= es and would apply only to instances of luabind classes.</p><p style=3D"mar= gin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;font-famil= y:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:15.6px">I= am guessing that the luabind::adl::object class needs to be changed, or pe= rhaps index_proxy. But I am not sufficiently familiar with how luabind forw= ards calls to existing Lua meta-methods, to its objects.</p><p style=3D"mar= gin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;font-famil= y:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:15.6px">H= as anyone explored the C++ code in luabind that supports operator overloadi= ng in Lua?</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-si= ze:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,san= s-serif;line-height:15.6px">Edit: I see some attempts to add a new operator= here:=C2=A0<a href=3D"https://github.com/decimad/luabind-deboostified/comm= it/55b1bd9217205253b41ab7d4746637ee5b0d276f" rel=3D"nofollow" style=3D"marg= in:0px;padding:0px;border:0px;text-decoration:none;color:rgb(12,101,165)">h= ttps://github.com/decimad/luabind-deboostified/commit/55b1bd9217205253b41ab= 7d4746637ee5b0d276f</a></p><p style=3D"margin:0px 0px 1em;padding:0px;borde= r:0px;font-size:15px;clear:both;font-family:'Helvetica Neue',Helvet= ica,Arial,sans-serif;line-height:15.6px">If I try the above with the assign= ment operator though, I do no see it getting called in Lua. Are there any o= ther changes needed in C++ for this?</p><p style=3D"margin:0px 0px 1em;padd= ing:0px;border:0px;clear:both"><font face=3D"Helvetica Neue, Helvetica, Ari= al, sans-serif"><span style=3D"font-size:15px;line-height:15.6px"><a href= =3D"http://stackoverflow.com/questions/33141507/adding-an-overload-for-the-= assignment-operator-in-lua-for-luabind-classes">http://stackoverflow.com/qu= estions/33141507/adding-an-overload-for-the-assignment-operator-in-lua-for-= luabind-classes</a></span></font><br></p><p style=3D"margin:0px 0px 1em;pad= ding:0px;border:0px;font-size:15px;clear:both;font-family:'Helvetica Ne= ue',Helvetica,Arial,sans-serif;line-height:15.6px">Thanks,</p><p style= =3D"margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;fon= t-family:'Helvetica Neue',Helvetica,Arial,sans-serif;line-height:15= .6px">Abhi</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-si= ze:15px;clear:both;font-family:'Helvetica Neue',Helvetica,Arial,san= s-serif;line-height:15.6px"><br></p><p style=3D"margin:0px 0px 1em;padding:= 0px;border:0px;font-size:15px;clear:both;font-family:'Helvetica Neue= 9;,Helvetica,Arial,sans-serif;line-height:15.6px"><br></p></div> --94eb2c0874e649d620052234f11e-- --===============2607249883421690300== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ --===============2607249883421690300== 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 --===============2607249883421690300==--