Skip to content

Commit

Permalink
Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnae committed Nov 15, 2016
1 parent 2f0774f commit cc65145
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ timer 5.0, (t) ->
t\again! -- this is (currently) how a recurring timer is defined - just rearm it using the again method
```

For reading from stdin, this is what you do:

```moonscript
on_stdin (receiver, data) ->
print "Incoming: #{data}"
```

And signal handlers are defined like this:

```moonscript
Expand All @@ -246,15 +239,21 @@ on_signal "int", (receiver) ->
Finally, reading from something else (like a socket) - please see the specs here [spec/event_loop_spec.moon](spec/event_loop_spec.moon). From the spookfile you'd do something like:

```moonscript
on_read some_fd, (data) ->
Types = require("syscall").t
stdin = Types.fd(0) -- MUST wrap this (or it gets GC:ed and strange things happen)
on_read stdin, (reader, fd) ->
data = fd\read!
print "Got some data: #{data}"
```

So, obviously it's very much up to you to get that FD from somewhere. These functions, eg. on_read, on_signal etc are actually methods on the global spook object. So, if you want to use them from a file you require you can do so like this instead:

```moonscript
Types = require("syscall").t
stdin = Types.fd(0) -- MUST wrap this (or it gets GC:ed and strange things happen)
-- it's really _G.spook
spook\on_read some_fd, (data) ->
spook\on_read stdin, (reader, fd) ->
data = fd\read!
print "Got some data: #{data}"
```

Expand Down

0 comments on commit cc65145

Please sign in to comment.