# [solved] luabind 'self' is not defined

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

## 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)
//             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 on other sites
Wait...what are you even trying to do there? o.O

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

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 on other sites
Quote:
 Original post by phantomWait...what are you even trying to do there? o.O

Quote:
 Originally by luabind DocumentationTo bind operators you have to include .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") .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 phantomWait...what are you even trying to do there? o.O

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])

• 11
• 19
• 12
• 34
• 9
• ### Forum Statistics

• Total Topics
631398
• Total Posts
2999838
×