{"action":"created","issue":{"url":"https://api.github.com/repos/ghcjs/ghcjs/issues/302","labels_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/302/labels{/name}","comments_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/302/comments","events_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/302/events","html_url":"https://github.com/ghcjs/ghcjs/issues/302","id":56426268,"number":302,"title":"Loading \"Hello world\" into Atom throws EBADF","user":{"login":"edsko","id":935288,"avatar_url":"https://avatars.githubusercontent.com/u/935288?v=3","gravatar_id":"","url":"https://api.github.com/users/edsko","html_url":"https://github.com/edsko","followers_url":"https://api.github.com/users/edsko/followers","following_url":"https://api.github.com/users/edsko/following{/other_user}","gists_url":"https://api.github.com/users/edsko/gists{/gist_id}","starred_url":"https://api.github.com/users/edsko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edsko/subscriptions","organizations_url":"https://api.github.com/users/edsko/orgs","repos_url":"https://api.github.com/users/edsko/repos","events_url":"https://api.github.com/users/edsko/events{/privacy}","received_events_url":"https://api.github.com/users/edsko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-03T19:43:36Z","updated_at":"2015-02-07T11:05:19Z","closed_at":null,"body":"I'm trying to experiment with `ghcjs` and seeing if it would be possible to use Haskell to write plugins for [Atom](http://atom.io), an editor based on `node.js`. The first problem is that this means that the generated code somehow needs to be available as a `node.js` module. I tried writing a small wrapper around the generated code, but since `eval` is not available and the generated code does not work when loaded using node's `vm` module, that doesn't seem possible. However, it's easy enough to change the last line of `all.js` to\r\n\r\n```\r\nexports.main = function() { h$main(h$mainZCMainzimain); }\r\n```\r\n\r\nAt this point this works when calling `node.js` from the command line:\r\n\r\n```\r\nhsHello = require('./hs/Hello.js');\r\nhsHello.main();\r\n```\r\n\r\nwhich dutifully prints `\"Hello world\"`. However, when I try do the same within `atom` (started in `dev` mode) this throws an exception:\r\n\r\n```\r\n[23753:0203/193534:INFO:CONSOLE(7506)] \"Uncaught setErrno not yet implemented: Error: EBADF, write\", source: .../hs/Hello.js (7506)\r\n```\r\n\r\n(when starting atom normally this crashes the editor completely); this exception is thrown from `h$setErrno`. (I realize that this may not be a `ghcjs` problem per se -- but perhaps the generated code is making some assumptions that are not always true? I have no idea.)"},"comment":{"url":"https://api.github.com/repos/ghcjs/ghcjs/issues/comments/73359886","html_url":"https://github.com/ghcjs/ghcjs/issues/302#issuecomment-73359886","issue_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/302","id":73359886,"user":{"login":"edsko","id":935288,"avatar_url":"https://avatars.githubusercontent.com/u/935288?v=3","gravatar_id":"","url":"https://api.github.com/users/edsko","html_url":"https://github.com/edsko","followers_url":"https://api.github.com/users/edsko/followers","following_url":"https://api.github.com/users/edsko/following{/other_user}","gists_url":"https://api.github.com/users/edsko/gists{/gist_id}","starred_url":"https://api.github.com/users/edsko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edsko/subscriptions","organizations_url":"https://api.github.com/users/edsko/orgs","repos_url":"https://api.github.com/users/edsko/repos","events_url":"https://api.github.com/users/edsko/events{/privacy}","received_events_url":"https://api.github.com/users/edsko/received_events","type":"User","site_admin":false},"created_at":"2015-02-07T11:05:19Z","updated_at":"2015-02-07T11:05:19Z","body":"Great! I don't know how far you'll get though without any stack trace or any other info about what's going wrong.. But if you wanted to try, it's easy: start `atom` using `atom -d -f` on the command line (that leaves in the foreground and enables dev mode), open the dev console (View, Developer, Toggle Developer Tools), and then just try to execute the generated Haskell code from the dev console:\r\n\r\n```\r\nhsHello = require('/Users/dev/wt/util/atom/jstest/hs/Hello.js');\r\nhsHello.runMainAction();\r\n```\r\n\r\nYou will see (or at least, I see, on OSX) Hello being printed to the terminal (though not, somewhat oddly, to the chromium dev console), and then the editor will crash immediately after."}}