lua-users home
lua-l archive

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

I don't think you should, unless you are writing code in the Lua standard library itself.

AFAIK those defines are not supposed to be used outside of the Lua code base. Use your own define instead.

Pierre Chapuis

On Wed, Jul 18, 2018, at 10:07, 云风 Cloud Wu wrote:
You should add a line

#define LUA_LIB

at beginning of the source file.

<>于2018年7月18日周三 下午3:25写道:


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.c`

../lua-5.4/build/bin/lua -i -e  "t=require'foo'"
../lua-5.4/build/bin/lua: error loading module 'foo' from file './':
        ./ 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,