2013-01-02

using luabind

here is just a quick rundown of what i did to get the hello world example here for luabind to work.

here is the example code in c++:

#include <iostream>
#include <luabind/luabind.hpp>

void greet()
{
        std::cout << "hello world\n";
}

extern "c" int init(lua_state* l)
{
        using namespace luabind;

        open(l);

        module(l)
        [
                def("greet", &greet)
        ];

        return 0;
}

then i compiled it into a shared library using the following commands:

g++ -i/usr/include/lua5.1 -fpic -c hello.cpp
g++ -shared -o hello.so hello.o -lluabind

note: luabind has to be linked in the second step, not in the first.

then from lua i ran the following commands:

> init = loadlib("./hello.so", "init")
> init()
> greet()
hello world
Standard

Leave a comment