Jump to content
  • Advertisement
Sign in to follow this  
nullsquared

[solved] luabind 'self' is not defined

This topic is 3698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was playing with lua previously, and recently stumbled upon luabind, and was like ... wow. How did I not hear of it earlier than manually typing up every single lua function and class? [lol] Anyways, all is well, until I use luabind::self
        using namespace luabind;
        module(state)
        [
            class_<vec2>("vec2")
                .def(constructor<float, float>())
                .def("norm", &vec2::norm)
                .def("len", &vec2::len)
                .def("dot", &vec2::dot)
                .def("print", &vec2::print)
                .def_readwrite("x", &vec2::x)
                .def_readwrite("y", &vec2::y)
//             ERRORS |||
//                    VVV
//                .def(self + vec2())
//                .def(self - vec2())
//                .def(self * vec2())
//                .def(self / vec2())
//                .def(self * float())
//                .def(self / float())
        ];

// D:\Programming\test_lua\main.cpp:100: error: `self' was not declared in this scope

// the rest of the functions/properties work 100%, like
// v = vec2(3, 5)
// print(v:len()) -- prints 5
Obviously, it can't find luabind::self. Even if I just go:
::luabind::self;
It gives the same error. Here are my includes:
extern "C"
{
    #include <lua.h>
    #include <lualib.h>
    #include <lauxlib.h>
}
#include <luabind/luabind.hpp>
#include <luabind/class.hpp>
#include <luabind/function.hpp>
#include <luabind/object.hpp>
I must be missing something stupid, because I just can't find where luabind::self is defined. I built luabind 0.7 with lua 5.0.3 and boost 1.35 using mingw (Code::Blocks on windows). Ideas? [smile] [Edited by - agi_shi on July 2, 2008 11:43:56 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by phantom
Wait...what are you even trying to do there? o.O


He's trying to map operator overloading from C++ to Lua.

agi_shi, read this. It says you need luabind/operator.hpp, do you have that? Also, I'm unsure whether you need vec2() or other<vec2>...

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
Wait...what are you even trying to do there? o.O


Quote:
Originally by luabind Documentation
To bind operators you have to include <luabind/operator.hpp>.

The mechanism for registering operators on your class is pretty simple. You use a global name luabind::self to refer to the class itself and then you just write the operator expression inside the def() call. This class:

struct vec
{
vec operator+(int s);
};


Is registered like this:

module(L)
[
class_<vec>("vec")
.def(self + int())
];


This will work regardless if your plus operator is defined inside your class or as a free function.


Mega-thanks there, by asking me to copy & paste some of the documentation, you indirectly led me to the solution: include <luabind/operator.hpp> [grin]

Thanks [smile]

Edit:
Quote:
Original post by mikeman
Quote:
Original post by phantom
Wait...what are you even trying to do there? o.O


He's trying to map operator overloading from C++ to Lua.

agi_shi, read this. It says you need luabind/operator.hpp, do you have that? Also, I'm unsure whether you need vec2() or other<vec2>...


More directly leading me to the solution there, so thanks to you, too [smile]

rating++ to both of you (if it manages to change anything [lol])

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!