API Reference › Program structure › extern
keyword

extern

extern function name(a: T) -> R = "symbol"

An extern function declares a function whose body lives outside Ludic and binds it to a native symbol resolved at link time. It is the seam through which Ludic reaches anything with a native interface — a system library, a math routine, or even another .ludic file compiled as a module. You write the Ludic signature you want to call and give the real symbol name after =; the linker connects them (pass -L/-l to ludicc to point at the library). Types must match the foreign ABI, so map each parameter and the return to the right Ludic type (int, fixed, pointer, …).

Parameters

aa typed argument passed straight through to the foreign symbol

Example

program Physics {
  extern function c_hypot(a: fixed, b: fixed) -> fixed = "hypot_fx"

  property Velocity { delta_x: int = 0, delta_y: int = 0 }
  model Projectile { Velocity }

  handler MeasureSpeed phase Update {
    for (velocity) in query [Velocity, {Projectile}] {
      let speed = c_hypot(a: fixed(velocity.delta_x), b: fixed(velocity.delta_y))
      Screen.status(string(floor(speed)))
    }
  }
}
← All symbols