Original Post
Hello. Followed a guide and compiled luabind. So, im able to use most of luabind, but unable to expose functions to lua. Heres the code:
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#include "lua.hpp"
#include "luabind.hpp"
#include <iostream>
using namespace std;
class NumberPrinter {
public:
NumberPrinter(int number) :
m_number(number) {}
void print() {
cout << m_number << endl;
}
int m_number;
};
int main()
{
lua_State *L = lua_open();
luaL_openlibs(L);
luabind::open(L);
luabind::module(L)
[
luabind::class_<NumberPrinter>("NumberPrinter")
.def(luabind::constructor<int>())
.def("print", &NumberPrinter::print) //this is not working, getting errors here
.def_readwrite("m_number", &NumberPrinter::m_number)
];
NumberPrinter no(0);
luabind::globals(L)["no"] = &no
luaL_dostring(L, "no.m_number = 23\nprint(no.m_number)");
lua_close(L);
return 0;
}
Here are the errors im getting, if i comment out the line .def("print", &NumberPrinter::print) im not getting errors and everything is compiling perfectly.
)]+0x220)||undefined reference to `luabind::detail::class_base::add_method(char const*, luabind::detail::overload_rep const&)'|
int)]+0x8a)||undefined reference to `luabind::detail::class_rep::convert_to(std::type_info const*, luabind::detail::object_rep const*, void*) const'|
||=== Build finished: 2 errors, 0 warnings ===|