Skip to content
rockofox edited this page Jan 11, 2024 · 1 revision
// example.c
void greet(char *name) {
  printf("Hello, %s!\n", name);
}

struct Point {
  float x;
  float y;
};

void printPoint(struct Point p) {
  printf("(%f, %f)\n", p.x, p.y);
}

void printNumbers(int *numbers, int count) {
  for (int i = 0; i < count; i++) {
    printf("%d\n", numbers[i]);
  }
}
gcc -dynamiclib example.c -o example.dylib
# example.in
external "sayhello" = do
    greet :: String -> IO
    printNumbers :: List{Int} -> Int -> IO
end
external "__default" = do
    puts :: List{Char} -> IO
end

let main = do
    puts ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\0']
    printNumbers [1, 2, 3, 4, 5], 5
    greet "Rocko"
end

Indigo can interact with dynamic libraries by declaring their function in an external block. The runtime will look for the specified library (+ the appropriate extension for dynamic libraries on your OS) in your OS's search path and ./

Clone this wiki locally