This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <luabind/luabind.hpp> | |
class testclass | |
{ | |
public: | |
testclass(const std::string& s): m_string(s) {} | |
void print_string() { std::cout << m_string << "\n"; } | |
private: | |
std::string m_string; | |
}; | |
extern "C" int init(lua_State* L) | |
{ | |
using namespace luabind; | |
open(L); | |
module(L) | |
[ | |
class_<testclass>("testclass") | |
.def(constructor<const std::string&>()) | |
.def("print_string", &testclass::print_string) | |
]; | |
return 0; | |
} |
kuyu@ub16:~/dkuyu/Dropbox/practice/lua/luabind/testclass$ cat test.lua
package.loadlib('./testclass.so', 'init')()
a = testclass('a string')
a:print_string()
kuyu@ub16:~/dkuyu/Dropbox/practice/lua/luabind/testclass$ cat commands.bash
#!/bin/bash
g++ testclass.cpp -I/usr/include/lua5.2/ -c -fPIC
g++ -shared -Wl,--whole-archive -o testclass.so testclass.o -lluabind -Wl,--no-whole-archive
lua test.lua
kuyu@ub16:~/dkuyu/Dropbox/practice/lua/luabind/testclass$ ./commands.bash
a string
No comments:
Post a Comment