{"action":"created","issue":{"url":"https://api.github.com/repos/manastech/crystal/issues/2029","labels_url":"https://api.github.com/repos/manastech/crystal/issues/2029/labels{/name}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/2029/comments","events_url":"https://api.github.com/repos/manastech/crystal/issues/2029/events","html_url":"https://github.com/manastech/crystal/issues/2029","id":127475030,"number":2029,"title":"How to bind a crystal closure to c library","user":{"login":"raydf","id":15605488,"avatar_url":"https://avatars.githubusercontent.com/u/15605488?v=3","gravatar_id":"","url":"https://api.github.com/users/raydf","html_url":"https://github.com/raydf","followers_url":"https://api.github.com/users/raydf/followers","following_url":"https://api.github.com/users/raydf/following{/other_user}","gists_url":"https://api.github.com/users/raydf/gists{/gist_id}","starred_url":"https://api.github.com/users/raydf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raydf/subscriptions","organizations_url":"https://api.github.com/users/raydf/orgs","repos_url":"https://api.github.com/users/raydf/repos","events_url":"https://api.github.com/users/raydf/events{/privacy}","received_events_url":"https://api.github.com/users/raydf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-19T15:47:59Z","updated_at":"2016-01-19T17:57:50Z","closed_at":null,"body":"Hello:\r\n\r\nUsing DukTape (Javascript embedded engine):\r\n\r\n```\r\ndependencies:\r\n  duktape:\r\n    github: jessedoyle/duktape.cr\r\n    version: ~> 0.7.0\r\n```\r\nI tested this code:\r\n\r\n```crystal\r\n  sbx = Duktape::Sandbox.new\r\n\r\n  sbx.push_global_object\r\n\r\n  test = 10\r\n  sbx.push_proc(2) do |ptr| # 2 stack arguments\r\n    env = Duktape::Sandbox.new ptr\r\n    a = env.get_number 0\r\n    test = env.get_number 1\r\n    env.push_number a + test\r\n    env.return 1 # return success\r\n  end\r\n\r\n  sbx.put_prop_string -2, \"adder\"\r\n  sbx.eval! \"print(adder(2, 3));\" # => 5\r\n```\r\n\r\nthis returns\r\n\r\n```\r\npassing a closure to C is not allowed\r\n```\r\n\r\nAny help on how can i achieve the closures usage i a c binding?"},"comment":{"url":"https://api.github.com/repos/manastech/crystal/issues/comments/172933917","html_url":"https://github.com/manastech/crystal/issues/2029#issuecomment-172933917","issue_url":"https://api.github.com/repos/manastech/crystal/issues/2029","id":172933917,"user":{"login":"raydf","id":15605488,"avatar_url":"https://avatars.githubusercontent.com/u/15605488?v=3","gravatar_id":"","url":"https://api.github.com/users/raydf","html_url":"https://github.com/raydf","followers_url":"https://api.github.com/users/raydf/followers","following_url":"https://api.github.com/users/raydf/following{/other_user}","gists_url":"https://api.github.com/users/raydf/gists{/gist_id}","starred_url":"https://api.github.com/users/raydf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raydf/subscriptions","organizations_url":"https://api.github.com/users/raydf/orgs","repos_url":"https://api.github.com/users/raydf/repos","events_url":"https://api.github.com/users/raydf/events{/privacy}","received_events_url":"https://api.github.com/users/raydf/received_events","type":"User","site_admin":false},"created_at":"2016-01-19T17:57:50Z","updated_at":"2016-01-19T17:57:50Z","body":"Thanks, waj. I'm closing the issue. \r\nI'll love to see an example with this kind of behavior (decomposing proc and reconstructing it), for replicating it in the duktape shard. Maybe there's some code already doing this in the standard library?"}}