warning using luaL_newlib

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

warning using luaL_newlib

Deepak Jois
I have a line of code in my Lua module source which looks like this:

 luaL_newlib(L, functions);

'functions' is of type 'const luaL_Reg *'

The module compiles fine, but issues a warning:

‘implicit conversion from 'unsigned long' to 'int' changes value from
18446744073709551615 to -1’.

It doesnt appear to be happening anywhere in my code. How do I make
this go away?

Full output is below:

src/luaharfbuzz/class_utils.c:12:3: warning: implicit conversion from
'unsigned long' to
      'int' changes value from 18446744073709551615 to -1
[-Wconstant-conversion]
  luaL_newlib(L, functions);
  ^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/deepak/.lua/include/lauxlib.h:112:26: note: expanded from macro
'luaL_newlib'
  (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
                         ^~~~~~~~~~~~~~~~~~~~~
/Users/deepak/.lua/include/lauxlib.h:109:50: note: expanded from macro
      'luaL_newlibtable'
  lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
  ~~~~~~~~~~~~~~~       ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
1 warning generated.

Reply | Threaded
Open this post in threaded view
|

Re: warning using luaL_newlib

Roberto Ierusalimschy
> I have a line of code in my Lua module source which looks like this:
>
>  luaL_newlib(L, functions);
>
> 'functions' is of type 'const luaL_Reg *'
>
> The module compiles fine, but issues a warning:
>
> ‘implicit conversion from 'unsigned long' to 'int' changes value from
> 18446744073709551615 to -1’.
>
> It doesnt appear to be happening anywhere in my code. How do I make
> this go away?
>
> Full output is below:
>
> src/luaharfbuzz/class_utils.c:12:3: warning: implicit conversion from
> 'unsigned long' to
>       'int' changes value from 18446744073709551615 to -1
> [-Wconstant-conversion]
>   luaL_newlib(L, functions);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~
> /Users/deepak/.lua/include/lauxlib.h:112:26: note: expanded from macro
> 'luaL_newlib'
>   (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
>                          ^~~~~~~~~~~~~~~~~~~~~
> /Users/deepak/.lua/include/lauxlib.h:109:50: note: expanded from macro
>       'luaL_newlibtable'
>   lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
>   ~~~~~~~~~~~~~~~       ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
> 1 warning generated.

Exactly how 'functions' is defined?

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: warning using luaL_newlib

Deepak Jois
On Wed, Jan 11, 2017 at 8:54 PM, Roberto Ierusalimschy
<[hidden email]> wrote:
> Exactly how 'functions' is defined?

functions is a const luaL_Reg *functions

==
static const struct luaL_Reg buffer_functions[] = {
  { "new", buffer_new },
  { NULL, NULL }
};

register_class(L, "harfbuzz.Buffer", buffer_methods, buffer_functions);
==

and register class is defined as:

==
int register_class(lua_State *L, const char *name, const luaL_Reg *
methods, const luaL_Reg *functions) {


 luaL_newlib(L, functions);
}
==

I hope that is clear. The original code is located here:
https://github.com/deepakjois/luaharfbuzz/blob/master/src/luaharfbuzz/class_utils.c#L4

Reply | Threaded
Open this post in threaded view
|

Re: warning using luaL_newlib

Roberto Ierusalimschy
> int register_class(lua_State *L, const char *name, const luaL_Reg *
> methods, const luaL_Reg *functions) {
> …
> …
>  luaL_newlib(L, functions);
> }

The manual says this about luaL_newlib:

  | The array l must be the actual array, not a pointer to it.

(It uses sizeof to compute the array size.) So, your use is incorrect.
You have to break it into more primitive calls:

-  luaL_newlib(L, functions);
+  lua_newtable(L);
+  luaL_setfuncs(L, functions, 0);

-- Roberto