[Help] c binding of function that takes callback

After some help from @bew in chat, and some digging, I ended up with this:

require "socket"

  @[Link("wiringPi")]
  lib LibWiringPi
    fun Setup = wiringPiSetupSys : LibC::Int
    fun ISR = wiringPiISR(pin : LibC::Int, edgeType : LibC::Int, fn : ->) : LibC::Int
  end

  fun my_interrupt_handler
    UNIXSocket.open("/tmp/gpio_detector.sock") do |sock|
      sock.puts "Event"
    end
  end

class Detector
  property server

  def initialize(config)

    LibWiringPi.Setup()
    LibWiringPi.ISR(config["gpioPinNumber"].as_i, 1, ->my_interrupt_handler)

    socket_file = "/tmp/gpio_detector.sock"
    if File.exists?(socket_file)
      puts "socket found"
      File.delete(socket_file)
    end
    @server = UNIXServer.new(socket_file)
  end
end

On the other end of this, I just open the same socket and continously read it. Due to the IO nature of this, it does not waste cpu by polling, but waits when nothing is available to read.

This seems to work fine for my purposes and hopefully has little impact on the smooth running of the rest of the program.

Thanks again to all replies :)