Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hellobind.cpp:
- 1 extern "C"
- 2 {
- 3 #include <lua5.1/lua.h>
- 4 }
- 5 #include <iostream>
- 6 #include <luabind/lua_include.hpp>
- 7 #include <luabind/luabind.hpp>
- 8
- 9 void greet()
- 10 {
- 11 std::cout << "hello world!\n";
- 12 }
- 13
- 14 extern "C" int init(lua_State* L)
- 15 {
- 16 using namespace luabind;
- 17
- 18 open(L);
- 19
- 20 module(L)
- 21 [
- 22 def("greet", &greet)
- 23 ];
- 24
- 25 return 0;
- 26 }
- building:
- $ g++ hellobind.cpp -llua5.1 -lluabind -I/usr/include/lua5.1/ -c -fPIC
- $ g++ -shared -Wl,-soname,libhellobind.so.0 -o libhellobind.so.0.0 hellobind.o
- test.lua:
- 1 local path = "libhellobind.so.0.0"
- 2 local f = package.loadlib(path, "init")
- 3 greet()
- output:
- $ lua test.lua
- lua: test.lua:3: attempt to call global 'greet' (a nil value)
- stack traceback:
- test.lua:3: in main chunk
- [C]: ?
- other info:
- $ uname -a
- Linux gmans-magicbox 3.5.3-custom #2 SMP Sun Aug 26 09:02:47 CEST 2012 x86_64 GNU/Linux
- $ gcc --version
- gcc (Debian 4.7.1-7) 4.7.1
- $ lua -v
- Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement