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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s