Wednesday, February 8, 2017

Luabind class demonstration

Consider this code that exposes a C++ class to Lua:

When run:

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