Skip to content

Instantly share code, notes, and snippets.

@cseeger
Created September 8, 2016 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cseeger/65daa8a9427e58527f0759726580c7bb to your computer and use it in GitHub Desktop.
Save cseeger/65daa8a9427e58527f0759726580c7bb to your computer and use it in GitHub Desktop.
Example C-lib binding in Crystal
module Radians
class Triangle
lib C
# In C: double cos(double x)
fun cos(value : Float64) : Float64
end
def cos(value : Float64)
C.cos(value)
end
end
end
tri = Radians::Triangle.new
puts tri.cos(0.0)
puts tri.cos(3.1415926535)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment