lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi guys,

I'm having some trouble loading a c++ library with loadlib. Suppose I
have a file lfoo.cc:

extern "C"
{
    #include <lua.h>
    #include <lauxlib.h>
    #include <lualib.h>
}
#include <iostream>

static int foo(lua_State *L)
{
    std::cout << "ok!" << std::endl;
    lua_pushnumber(L, 1);
    return 1;
}

static const luaL_reg foolib[] = {
    {"foo", foo},
    {NULL, NULL}
};

LUALIB_API int foo_open_lib (lua_State *L)
{
	luaL_openlib(L, "Foo", foolib, 0);
	return 1;
}

This compiles with no errors nor warnings under:
g++ -W -Wall -fPIC -c lfoo.cc -o lfoo.o
g++ -W -Wall -shared -ldl -llua -llualib -o lfoo.so lfoo.o

But loadlib(path .. '/lfoo.so', 'foo_open_lib') returns nil.
Is there anything wrong?

Thanks,
Luis.
			

-- 
Mathematicians practice absolute freedom.
                -- Henry Adams

-- 
Luis Carvalho
Applied Math PhD Student
Brown University
carvalho at dam dot brown dot edu

PGP Key: E820854A <carvalho@dam.brown.edu>
Available at: http://www.dam.brown.edu/people/carvalho/pgp-key
Fingerprint: 1339 9E5D DB0B 01B9 624D  AFF8 D738 BFA6 E820 854A