so after struggling bit, have decided give luabind try. i'm in process of figuring things out , currently, biggest problem returning userdata (class) created lua script. example i'm working with:
class testclass { public: testclass(const std::string& s) : m_string(s) {} void print_string() { std::cout << m_string << "\n"; } private: std::string m_string; }; this how register class in lua, using luabind:
module(l) [ class_<testclass>("testclass") .def(constructor<const std::string &>()) .def("print_string", &testclass::print_string) ]; and content of lua script:
a = testclass('class created lua') return calling print_string() on 'a' in lua works fine. however, afterwards, i'm @ loss when trying retrieve 'a' lua stack , utilize in c++ program. i'm trying is:
testclass * tmp = (testclass*)lua_touserdata(lua_state, -1); tmp->print_string(); apparently, print_string() being called, because newline in output, however, i'd tmp->print_string()'s output "class created lua". how correctly retrieve userdata (the class) being returned script?
Comments
Post a Comment