lua-users home
lua-l archive

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


Sylvain Fabre wrote:
> I try to send a 32 bits uint32_t value from LUA to C (ie in fact a
> 0xRRGGBBAA pattern) and i am facing the following issue :
> 
>    * If i do a 0xFF0000FF -> I get the value 0x80000000 with
>      luaL_checkinteger()
>    * If i do not set the MSB (ie 0x7F0000FF for example) -> I get the
>      correct value  with luaL_checkinteger()
> 
> I guess it has something to do with sign conversion, but i do not
> know if it is a bug or a normal behavior with luaJIT.

The same thing would happen with plain Lua on some platforms.
Either use (uint32_t)luaL_checknumber() or pass only signed
integers (convert with bit.tobit() if necessary).

But since you're already using LuaJIT, it's probably easier to
call your C function via the FFI. Simply declare your function as
taking an uint32_t and the appropriate conversions will happen
automatically. It's also much faster.

--Mike