Skip to content

Instantly share code, notes, and snippets.

@DougEverly
Created May 1, 2015 20:42
Show Gist options
  • Select an option

  • Save DougEverly/ebd52f2638a20482146b to your computer and use it in GitHub Desktop.

Select an option

Save DougEverly/ebd52f2638a20482146b to your computer and use it in GitHub Desktop.
Crystal calling libcurl
@[Link("curl")]
lib LibCurl
type CURL = Void*
type CURLoption = Int32
fun create = curl_easy_init(): CURL
fun set_opt = curl_easy_setopt(CURL, Int32, UInt8*)
fun get = curl_easy_perform(CURL)
fun cleanup = curl_easy_cleanup(CURL)
end
class Curl
def initialize
@curl = LibCurl.create
end
def get(url = "http://www.google.com")
if @curl
LibCurl.set_opt(@curl, 10002, url)
res = LibCurl.get(@curl)
end
end
def finalize
LibCurl.cleanup(@curl)
end
end
curl = Curl.new
curl.get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment