kassane / zFFI

CBindgen FFI test
The Unlicense
10 stars 2 forks source link

Enchanced cbindgen - zig #1

Closed kassane closed 2 years ago

kassane commented 2 years ago

This experiment refers to the development of the zig-bindgen branch. Below you will find errors during the translation that should be corrected.

Expected

generated/binding.zig: [ FFI Work]

const std = @import("std");

pub const Doggo = extern struct {
    age: i32,
    name: [*:0]const u8,
};

pub extern fn call_name(ptr: ?*Doggo, name: [*:0]const u8) anyopaque;
pub extern fn is_whitespace(byte: u8) bool;
pub extern fn mul(value1: usize, value2: usize) usize;
pub extern fn add(value1: usize, value2: usize) usize;

CBindgen

Generated:

const std = @import("std");

pub const Doggo = extern struct {
  age: i32,
   _name: ?fn, // type error
};

// missing pub keyword to public functions
extern fn call_name( _ptr: ?fn, const  constname: ?fn) anyopaque; // flags type error
extern fn is_whitespace(byte: u8) bool;
extern fn mul(value1: usize, value2: usize) usize;
extern fn add(value1: usize, value2: usize) usize;
kassane commented 2 years ago

Fixed!