LUAMOD_API in 5.4 results in luaopen_blah nod found

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

LUAMOD_API in 5.4 results in luaopen_blah nod found

Tobias Kieslich

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


Reply | Threaded
Open this post in threaded view
|

Re: LUAMOD_API in 5.4 results in luaopen_blah nod found

云风 Cloud Wu
You should add a line

#define LUA_LIB

at beginning of the source file.


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

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


Reply | Threaded
Open this post in threaded view
|

Re: LUAMOD_API in 5.4 results in luaopen_blah nod found

Pierre Chapuis
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.


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

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



Reply | Threaded
Open this post in threaded view
|

Re: LUAMOD_API in 5.4 results in luaopen_blah nod found

Roberto Ierusalimschy
> 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.

Probably this is right, one should not use LUAMOD_API outside the Lua
code base. Anyway, that change was reverted.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: LUAMOD_API in 5.4 results in luaopen_blah nod found

Tobias Kieslich

Quoting Roberto Ierusalimschy <[hidden email]>:

>> 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.
>
> Probably this is right, one should not use LUAMOD_API outside the Lua
> code base. Anyway, that change was reverted.
>
> -- Roberto

If LUAMOD_API is not meant to be used outside the Lua code base itself
then it achieves exactly what it's supposed to do and hide the function
from the outside world. That means the change should not be reverted? Or
did it break something else? Just curious.

-tobbik


Reply | Threaded
Open this post in threaded view
|

Re: LUAMOD_API in 5.4 results in luaopen_blah nod found

Roberto Ierusalimschy
> If LUAMOD_API is not meant to be used outside the Lua code base itself
> then it achieves exactly what it's supposed to do and hide the function
> from the outside world. That means the change should not be reverted? Or
> did it break something else? Just curious.

It could break something else (e.g., your case). It is a minimal
incompatibility, but the "gains" seem minimal too.

-- Roberto