gig icon indicating copy to clipboard operation
gig copied to clipboard

Interact with custom Gleam types in gig

Open a-gonzalo opened this issue 2 months ago • 0 comments

Nowadays, if you want to interact with a type defined as this in Gleam (command gig src/ctypes.gleam with the following code):

pub type Char

@external(c, "gig_ctypes", "isAlphanumeric")
pub fn is_alphanumeric(c: Char) -> Bool

Gig produces the following code:


// This file is automatically generated.
// Please do not edit it.

#include "builtin.h"

Bool isAlphanumeric(ctypes_Char c);

So the ctypes_Char is not declared in the header. This is not "bad" at all, as Gleam/Gig doesn't know what we want to do with this type or how we want to declare it in C.

To solve this, we can use a workaround at this moment, including the definition at patch/builtin.h, but I wonder if this can be improved as probably the builtin.h header shouldn't be edited including custom type definitions.

A possible solve (including this code snippet at patch/builtin.h):

typedef struct ctypes_Char ctypes_Char;
struct ctypes_Char {
  char c;
};

I think this should be done in a different way, but I don't really know which approach would be more feasible to incorporate at gig and also feasible to the developer experience.

Thank you!

a-gonzalo avatar Sep 29 '25 21:09 a-gonzalo