You should add a line
#define LUA_LIB
at beginning of the source file.
Hi,
it seems in Lua 5.4, writing a module like this:
file foo.c
#include "lua.h"
#include "lauxlib.h"
static int l_bar( lua_State *L ) {
lua_pushstring( L, "bar" );
return 1;
}
static const struct luaL_Reg foolib[ ] = {
{ "bar" , l_bar }
, { NULL , NULL }
};
LUAMOD_API int luaopen_foo( lua_State *L ) {
luaL_newlib( L, foolib );
return 1;
}
compiled `/usr/bin/gcc -O2 -I../lua-5.4/build/include -shared -o foo.so foo.c`
../lua-5.4/build/bin/lua -i -e "t=require'foo'"
../lua-5.4/build/bin/lua: error loading module 'foo' from file './foo.so':
./foo.so: undefined symbol: luaopen_foo
stack traceback:
[C]: in ?
[C]: in function 'require'
(command line):1: in main chunk
[C]: in ?
If I don't use LUAMOD_API it works just fine. It does work in 5.3. Did I miss
a changed behaviour?
Thank you,
-tobbik