Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struct isn't working with FFI #42

Open
grumpOldman opened this issue Aug 5, 2024 · 1 comment
Open

Struct isn't working with FFI #42

grumpOldman opened this issue Aug 5, 2024 · 1 comment
Labels
invalid This doesn't seem right

Comments

@grumpOldman
Copy link

Struct isn't working with FFI

I'm trying to create a SDL2 package, but Structs I generated from SDL_Events are not working with Window Events.

They worked with byte-type version 0.1.7 looking at divy/deno_sdl2. I even tested updating divy/deno_sdl2 to the lastest version 0.4.0 and still not spitting out SDL_WindowEvents.

It might be an issue switching from UnsafePointerView to DataView

@MierenManz
Copy link
Collaborator

I'm not 100% sure what you are requesting?

Do you want a Ptr<T> class which is a sugarcoat around reading pointers in byte type?

const ptrAB = Deno.UnsafePointerView.getArrayBuffer(ptr, size, offset);
const dt = new DataView(ptrAB);

return UnsizedType.read(dt);

Or do you want help with how to create a DataView from PointerValue / PointerObject?

Example of how you can do it

const lib = Deno.dlopen("./libree.so", {
    ret_ptr: {
        parameters: ["u8", "u32"],
        result: "pointer",
    },
    // Essentially the same as above
    ret_buff: {
        name: "ret_ptr",
        parameters: ["u8", "u32"],
        result: "buffer",
    },
});

const ptr = lib.symbols.ret_ptr(8, 32);

// Assume ptr is not null
const ptrArrayBuff = Deno.UnsafePointerView.getArrayBuffer(ptr!, size, offset);
const ptrDataview = new DataView(ptrArrayBuff);

Or directly from a result that is a struct

const lib = Deno.dlopen("./libree.so", {
    ret_struct: {
        parameters: ["u8", "u32"],
        result: { struct: ["u8", "u32"] },
    },
});

const struct = lib.symbols.ret_struct(8, 32);
const structDataview = new DataView(struct.buffer);

@eliassjogreen eliassjogreen added the invalid This doesn't seem right label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants