Browse Source

reorganize docs

leaf corcoran 12 years ago
parent
commit
82cd1aed54
1 changed files with 72 additions and 40 deletions
  1. 72 40
      docs/index.md

+ 72 - 40
docs/index.md

@@ -19,9 +19,12 @@ Before installing **lua-enet**, you must make sure you have
 [ENet](http://enet.bespin.org/) installed. Consult your system's package
 management.
 
-If you've got [Lua Rocks](http://www.luarocks.org/) then installation is very easy:
+If you've got [Lua Rocks](http://www.luarocks.org/) then installation is very
+easy:
 
-    $ luarocks install enet
+```bash
+$ luarocks install enet
+```
 
 Otherwise you can download the source can from GitHub:
 <https://github.com/leafo/lua-enet>
@@ -48,16 +51,18 @@ plain Lua table. The `type` entry holds the kind of event as a string, and the
 Using this information, we can make a simple echo server:
 
 
-    -- server.lua
-    require "enet"
-    local host = enet.host_create"localhost:6789"
-    while true do
-        local event = host:service(100)
-        if event and event.type == "receive" then
-            print("Got message: ", event.data, event.peer)
-            event.peer:send(event.data)
-        end
-    end
+```lua
+-- server.lua
+require "enet"
+local host = enet.host_create"localhost:6789"
+while true do
+  local event = host:service(100)
+  if event and event.type == "receive" then
+    print("Got message: ", event.data, event.peer)
+    event.peer:send(event.data)
+  end
+end
+```
 
 
 Data, whether sent or received, is always a Lua string. Primitive types can be
@@ -66,27 +71,30 @@ serialization library.
 
 The client for our server can be written like so:
 
-    -- client.lua
-    require "enet"
-    local host = enet.host_create()
-    local server = host:connect("localhost:6789")
-
-    local done = false
-    while not done do
-        local event = host:service(100)
-        if event then
-            if event.type == "connect" then
-                print("Connected to", event.peer)
-                event.peer:send("hello world")
-            elseif event.type == "receive" then
-                print("Got message: ", event.data, event.peer)
-                done = true
-            end
-        end
+
+```lua
+-- client.lua
+require "enet"
+local host = enet.host_create()
+local server = host:connect("localhost:6789")
+
+local done = false
+while not done do
+  local event = host:service(100)
+  if event then
+    if event.type == "connect" then
+      print("Connected to", event.peer)
+      event.peer:send("hello world")
+    elseif event.type == "receive" then
+      print("Got message: ", event.data, event.peer)
+      done = true
     end
+  end
+end
+```
 
-    server:disconnect()
-    host:flush()
+server:disconnect()
+host:flush()
 
 Upon receiving the connect message we send `"hello world"` to the server, then
 wait for the response.
@@ -96,10 +104,10 @@ and then tell the host to flush (unless `host:service` will be called again)
 otherwise the server will have to wait for the client to disconnect from timeout.
 
 <a name="reference"></a>
-<div class="api">
 ## Reference
 
 ### `enet.host_create([bind_address, peer_count, channel_count, in_bandwidth, out_bandwidth])`
+
 Returns a new host. All arguments are optional.
 
 A `bind_address` of `nil` makes a host that can not be connected to (typically
@@ -118,6 +126,7 @@ Parameters:
    (unlimited)
 
 ### `host:connect(address [, channel_count, data])`
+
 Connects a host to a remote host. Returns peer object associated with remote
 host.  The actual connection will not take place until the next `host:service`
 is done, in which a `"connect"` event will be generated.
@@ -129,6 +138,7 @@ the channel count on the server. Defaults to `1`.
 Defaults to `0`.
 
 ### `host:service([timeout])`
+
 Wait for events, send and receive any ready packets. `timeout` is the max
 number of milliseconds to be waited for an event. By default `timeout` is `0`.
 Returns `nil` on timeout if no events occurred.
@@ -141,35 +151,44 @@ A `"receive"` event also has a `data` entry which is a Lua string containing the
 data received.
 
 ### `host:check_events()`
+
 Checks for any queued events and dispatches one if available. Returns the
 associated event if something was dispatched, otherwise `nil`.
 
 ### `host:compress_with_range_coder()`
+
 Enables an adaptive order-2 PPM range coder for the transmitted data of
 all pers.
 
 ### `host:flush()`
+
 Sends any queued packets. This is only required to send packets earlier than
 the next call to `host:service`, or if `host:service` will not be called again.
 
 ### `host:broadcast(data [, channel, flag])`
+
 Queues a packet to be sent to all connected peers. See
 [peer:send](#peersenddata__channel_flag) for arguments.
 
 ### `host:channel_limit(limit)`
+
 Sets the maximum number of channels allowed. If it is `0` then the system
 maximum allowable value is used.
 
 ### `host:bandwidth_limit(incoming, outgoing)`
+
 Sets the bandwidth limits of the host in bytes/sec. Set to `0` for unlimited.
 
 ### `host:total_sent_data()`
+
 Returns the number of bytes that were sent through the given host.
 
 ### `host:total_received_data()`
+
 Returns the number of bytes that were received by the given host. 
 
 ### `host:service_time()`
+
 Returns the timestamp of the last call to host:service() or host:flush().
 
 ### `host:peer_count()`
@@ -177,50 +196,60 @@ Returns the number of peers that are allocated for the given host. This
 represents the maximum number of possible connections.
 
 ### `host:get_peer(index)`
+
 Returns the connected peer at the specified index (starting at 1). ENet
 stores all peers in an array of the corresponding host and re-uses unused
 peers for new connections. You can query the state of a peer using 
 [peer:state](#peerstate).
 
 ### `peer:connect_id()`
+
 Returns the field ENetPeer::connectID that is assigned for each
 connection.
 
 ### `peer:disconnect([data])`
+
 Requests a disconnection from the peer. The message is sent on the next
 `host:service` or `host:flush`.
 
 `data` is optional integer value to be associated with the disconnect.
 
 ### `peer:disconnect_now([data])`
+
 Force immediate disconnection from peer. Foreign peer not guaranteed to receive
 disconnect notification.
 
 `data` is optional integer value to be associated with the disconnect.
 
 ### `peer:disconnect_later([data])`
+
 Request a disconnection from peer, but only after all queued outgoing packets
 are sent.
 
 `data` is optional integer value to be associated with the disconnect.
 
 ### `peer:index()`
+
 Returns the index of the peer. All peers of an ENet host are kept in an
 array. This function finds and returns the index of the peer of its host
 structure.
 
 ### `peer:ping()`
+
 Send a ping request to peer, updates `round_trip_time`. This is called
 automatically at regular intervals.
 
 ### `peer:ping_interval(interval)`
+
 Specifies the interval in milliseconds that pings are sent to the other
 end of the connection (defaults to 500).
 
 ### `peer:reset()`
+
 Forcefully disconnects peer. The peer is not notified of the disconnection.
 
 ### `peer:send(data [, channel, flag])`
+
 Queues a packet to be sent to peer. `data` is the contents of the packet, it
 must be a Lua string.
 
@@ -234,6 +263,7 @@ arrive. Defaults to reliable.
 
 <a name="peerstate"></a>
 ### `peer:state()`
+
 Returns the state of the peer as a string. This can be any of the
 following:
 
@@ -250,11 +280,13 @@ following:
  * "unknown"
 
 ### `peer:receive()`
+
 Attempts to dequeue an incoming packet for this peer.
 Returns `nil` if there are no packets waiting. Otherwise returns two values:
 the string representing the packet data, and the channel the packet came from.
 
 ### `peer:round_trip_time([value])`
+
 Returns or sets the current round trip time (i.e. ping). If value is nil
 the current value of the peer is returned. Otherwise the value roundTripTime
 is set to the specified value and returned.
@@ -263,6 +295,7 @@ Enet performs some filtering on the round trip times and it takes some time
 until the parameters are accurate.
 
 ### `peer:last_round_trip_time([value])`
+
 Returns or sets the round trip time of the previous round trip time
 computation. If value is nil the current value of the peer is returned.
 Otherwise the value lastRoundTripTime is set to the specified value and
@@ -284,6 +317,7 @@ Parameters:
    increases
 
 ### `(limit, minimum, maximum) peer:timeout(limit, minimum, maximum)`
+
 Returns or sets the parameters when a timeout is detected. This is happens
 either after a fixed timeout or a variable timeout of time that takes the
 round trip time into account. The former is specified with the `maximum`
@@ -291,15 +325,13 @@ parameter.
 
 Parameters:
 
-  * `limit` a factor that is multiplied with a value that based on the 
-	average round trip time to compute the timeout limit
-  * `minimum` timeout value in milliseconds that a reliable packet has to
-	be acknowledged if the variable timeout limit was exceeded
-  * `maximum` fixed timeout in milliseconds for which any packet has to be acknowledged
-
-See official enet documentation for detailed description.
+* `limit` a factor that is multiplied with a value that based on the 
+  average round trip time to compute the timeout limit
+* `minimum` timeout value in milliseconds that a reliable packet has to
+  be acknowledged if the variable timeout limit was exceeded
+* `maximum` fixed timeout in milliseconds for which any packet has to be acknowledged
 
-</div>
+See official ENet documentation for detailed description.
 
 <a name="license"></a>
 ## License (MIT)