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 overloaded_function | |
{ | |
public: | |
overloaded_function() {} | |
void print_string() { std::cout << __FUNCTION__ << std::endl; } | |
void print_string(int x) { std::cout << __FUNCTION__ << ": " << x << std::endl; } | |
}; | |
extern "C" int init(lua_State* L) | |
{ | |
using namespace luabind; | |
open(L); | |
module(L) | |
[ | |
class_<overloaded_function>("overloaded_function") | |
.def(constructor<>()) | |
.def("print_string", (void(overloaded_function::*)(int))&overloaded_function::print_string) | |
]; | |
return 0; | |
} |
When run:
kuyu@ub16:~/dkuyu/Dropbox/practice/lua/luabind/overloaded_function$ cat test.lua
package.loadlib('./overloaded_function.so', 'init')()
a = overloaded_function()
a:print_string(6)
kuyu@ub16:~/dkuyu/Dropbox/practice/lua/luabind/overloaded_function$ cat commands.bash
#!/bin/bash
g++ overloaded_function.cpp -I/usr/include/lua5.2/ -c -fPIC
g++ -shared -Wl,--whole-archive -o overloaded_function.so overloaded_function.o -lluabind -Wl,--no-whole-archive
lua test.lua
kuyu@ub16:~/dkuyu/Dropbox/practice/lua/luabind/overloaded_function$ ./commands.bash
print_string: 6
No comments:
Post a Comment