cffi-lua icon indicating copy to clipboard operation
cffi-lua copied to clipboard

How much compatibility is wanted?

Open MockbaTheBorg opened this issue 5 years ago • 4 comments

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.

MockbaTheBorg avatar Nov 05 '20 22:11 MockbaTheBorg

__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

q66 avatar Nov 05 '20 22:11 q66

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

MockbaTheBorg avatar Nov 05 '20 22:11 MockbaTheBorg

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!!!

MockbaTheBorg avatar Nov 06 '20 02:11 MockbaTheBorg

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

q66 avatar Nov 06 '20 03:11 q66