q66 / cffi-lua

A portable C FFI for Lua 5.1+
MIT License
176 stars 24 forks source link

How much compatibility is wanted? #24

Open MockbaTheBorg opened 3 years ago

MockbaTheBorg commented 3 years ago

Hi there q66,

Sorry its me again. I do not know how compatible you want to be with the luajit ffi, but here's a test code which gave me issues:

local cffi = require("cffi")
cffi.cdef[[

typedef uint8_t Uint8;
typedef uint32_t Uint32;

typedef struct Device
{
    int needed;
    Uint8 *buf;
    Uint32 len;
} __attribute__((packed)) Device;

enum
{
    SDL_PIXELFORMAT_YV12 =
        ((((Uint32)(((Uint8)(('Y'))))) << 0) | (((Uint32)(((Uint8)(('V'))))) << 8) | (((Uint32)(((Uint8)(('1'))))) << 16) | (((Uint32)(((Uint8)(('2'))))) << 24)),
    SDL_PIXELFORMAT_IYUV =
        ((((Uint32)(((Uint8)(('I'))))) << 0) | (((Uint32)(((Uint8)(('Y'))))) << 8) | (((Uint32)(((Uint8)(('U'))))) << 16) | (((Uint32)(((Uint8)(('V'))))) << 24)),
    SDL_PIXELFORMAT_YUY2 =
        ((((Uint32)(((Uint8)(('Y'))))) << 0) | (((Uint32)(((Uint8)(('U'))))) << 8) | (((Uint32)(((Uint8)(('Y'))))) << 16) | (((Uint32)(((Uint8)(('2'))))) << 24)),
    SDL_PIXELFORMAT_UYVY =
        ((((Uint32)(((Uint8)(('U'))))) << 0) | (((Uint32)(((Uint8)(('Y'))))) << 8) | (((Uint32)(((Uint8)(('V'))))) << 16) | (((Uint32)(((Uint8)(('Y'))))) << 24)),
    SDL_PIXELFORMAT_YVYU =
        ((((Uint32)(((Uint8)(('Y'))))) << 0) | (((Uint32)(((Uint8)(('V'))))) << 8) | (((Uint32)(((Uint8)(('Y'))))) << 16) | (((Uint32)(((Uint8)(('U'))))) << 24))
};

int printf(const char *fmt, ...);
]]
cffi.C.printf("Hello %s!\n", "world")

This code, ported from a luajit ffi code, gives me errors on lines 10 and 17. I can probably fix that manually, just wanted to know if this is something you expect to happen or if it is really bugs you want reported.

Thanks, Marcelo.

q66 commented 3 years ago

__attribute__((packed)) is not supported right now, as there is no direct way in libffi to represent packed structures (see STATUS.md)

advanced expression syntax is not (yet) implemented, it probably will eventually but i won't give any estimates

MockbaTheBorg commented 3 years ago

No worries ... just checking. Thanks a lot again.

MockbaTheBorg commented 3 years ago

Hi q66,

I also got an error on the following:

enum
{
    SDLK_UNKNOWN = 0,
    SDLK_RETURN = '\r',  <---- unexpected symbol near '<char>'
    SDLK_ESCAPE = '\033',
    SDLK_BACKSPACE = '\b',
    SDLK_TAB = '\t',
    SDLK_SPACE = ' ',
};

By checking on the status it was not clear to me if this was expected. So I am not sure if this is an issue either, just reporting.

Thanks, Marcelo.

PS: other than these minor things, everything else is working fine. Awesome work!!!

q66 commented 3 years ago

character literals were just an oversight, that should be fixed now