• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    C
  • Created over 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An async framework for Lua/Torch.

ASyNC

An async framework for Lua/Torch, based on LibUV (using Tim Caswell's luv library).

This lib is heavily inspired on the Node.js architecture. It's fun, elegant, and should be extremely efficient (a lot of testing is required).

The examples in tests/ should provide enough documentation on the API.

License

MIT License

Examples

Starting the event loop. At the end of any program, the event loop must be started. Nothing will be interpreted after this call, as it takes control of the runtime.

async.go()

It's useful to have a REPL (interpreter) running asynchronously, for debugging and live control of your programs:

async.repl()  -- fires up an asyncronous repl
async.repl.listen({host='0.0.0.0', port=8080})   -- fires up an async repl through a TCP server
async.repl.connect({host='0.0.0.0', port=8080})  -- connects to a remote repl through a TCP client

Common JS like timer controls:

async.setInterval(millis, function()
   print('printed every N millis')
end)
async.setTimeout(millis, function()
   print('printed once in N millis')
end)

CPU Info. Useful to know how many processors are available. This is a synchronous call.

print(async.cpuInfo())

A TCP server:

async.tcp.listen({host='0.0.0.0', port=8080}, function(client)
   -- Receive:
   client.ondata(function(chunk)
      -- Data:
      print('received: ' .. chunk)

      -- Reply:
      client.write('thanks!')
   end)

   -- Done:
   client.onend(function()
      print('client gone...')
   end)
end)

A TCP client:

async.tcp.connect({host='127.0.0.1', port=8080}, function(client)
   -- Write something
   client.write('something .. ' .. i)

   -- Callbacks
   client.ondata(function(chunk)
      print('received: ' .. chunk)
      client.close()
   end)

   -- Done:
   client.onend(function()
      print('connection closed...')
   end)
end)

File I/O. The low level interface is not complete yet, but the high-level one is final:

async.fs.readFile('LICENSE', function(content)
   print(content)
   async.fs.writeFile('LICENSE.copy', content, function(status, err)
      print('==> wrote file: ' .. (status or err))
   end)
end)

A lower-level interface is also available, for C-level performance. The upside: no copy is done, the user callback gets the raw pointer to the network buffer (read) and writes tap directly into the raw buffer, provided by the user. The downside: the buffer returned by the "ondata" callback lives only for the scope of that callback, and must be copied by the user...

-- assuming a client handle:

local b = require 'buffer'

client.onrawdata(function(chunk)
   -- chunk is a Buffer object (https://github.com/clementfarabet/buffer)
   print(chunk)

   -- chunk will not be valid past this point, so its content must be copied,
   -- not just referenced...
   local safe = chunk:clone()
   -- safe can be past around...

   -- the most common use is to copy that chunk into an existing storage,
   -- for instance a tensor:
   -- (assuming tensor is a torch.Tensor)
   local dst = b(tensor)  -- creates a destination buffer on the tensor (a view, no copy)
   dst:copy(src)
end)

-- write() also accepts buffers:
client.write( b'this is a string saved in a buffer object' )

-- last, the sync() interface can be set up in raw mode:
client.syncraw()
local buffer = client.read()
-- ...

We also provide a simple async interface to CURL.

Provides two functions: get and post.

get:

-- simple URL:
async.curl.get('http://www.google.com', function(res)
    print(res)
end)

-- complete API:
async.curl.get({
    host = 'http://blogname.blogspot.com',
    path = '/feeds/posts/default',
    query = {
        alt = 'json'
    },
    format = 'json' -- parses the output: json -> Lua table
}, function(res)
   print(res)
end)

-- Getting an image, and decoding it:
curl.get('http://www.webstandards.org/files/acid2/reference.png', function(res)
  local decoded = require('graphicsmagick').Image():fromString(res)
end)

post:

-- post has the same API, with a form parameter (instead of query):
async.curl.post({
    host = 'http://myserver.com',
    path = '/',
    form = {
        username = 'bob',
        password = 'key',
        somefiletoupload = '@/local/path/to/file.jpg'
    }
}, function(res)
   print(res)
end)

-- or a simple file upload:
async.curl.post({
    host = 'http://myserver.com',
    path = '/',
    file = '@/path/to/file.png',
}, function(res)
   print(res)
end)

More Repositories

1

torch-ios

Torch7 for iOS.
C
196
star
2

manifold

A package to manipulate manifolds.
Lua
141
star
3

ipam-tutorials

IPAM Tutorials on Theano/Torch
Lua
129
star
4

gfx.js

A graphics backend for the browser (with a Torch7 client).
JavaScript
126
star
5

graphicsmagick

A simple Lua wrapper to graphicsmagick.
Lua
126
star
6

lua---nnx

An extension to Torch7's nn package.
Lua
97
star
7

lua---parallel

A (simple) parallel computing framework for Lua
Lua
92
star
8

lua---csv

A package to read and write CSV. Provides high-level database-like handlers.
Lua
47
star
9

lua---camera

A very simple camera interface (frame grabber) for Torch7.
C
34
star
10

lua---mattorch

An interface between Torch and Matlab
C
31
star
11

neuflow

Compiler toolkit for neuFlow.
Lua
26
star
12

lua---imgraph

A package to deal with graphs built on images.
C
22
star
13

lua---ffmpeg

An interface between ffmpeg and Lua/Torch
Lua
21
star
14

xLearn

A Lua-based framework for vision.
C
20
star
15

gm

GM package (for tutorial compat)
Lua
17
star
16

buffer

A buffer object for LuaJIT
Lua
15
star
17

lua---liuflow

Dense optical flow toolbox (from C.Liu)
C++
15
star
18

lua---json

A package to read/write JSON
Lua
10
star
19

thwebterm

Torch Web Terminal
JavaScript
10
star
20

videograph

This package extends imgraph, for videos...
C
9
star
21

nnop

Parameter-free Neural Network primitives for torch/nn.
Lua
9
star
22

lua---opengm

An OpenGM wrapper for Lua.
C++
8
star
23

lua---image

An image toolBox for Torch7.
Lua
7
star
24

persist

Persist: a simple persisting table for Torch (uses Redis as a data store).
Lua
5
star
25

torchinstall

A one-line install script for Torch
Shell
5
star
26

restclient

A simple Lua client for REST APIs.
Lua
5
star
27

lua---nng

A graph extension to Torch7's nn package.
Lua
4
star
28

thmap

Trivial distributed computing for Torch.
Lua
4
star
29

lua---inline-C

An Inline C package for Lua
Lua
4
star
30

operator-library

A library of fast customizable operators, in Verilog.
3
star
31

xrocks

A simple container for all our Lua rocks.
Shell
3
star
32

lua-fs-0.3

lua FS library, with torch-pkg build
C
3
star
33

lua---bitop

LuaBitOp -- from Mike Pall (repackaged for Torch7)
Lua
3
star
34

luasql

LuaSQL, fork from https://github.com/keplerproject/luasql, adapted to Torch.
C
3
star
35

lua---python

Python in Lua.
C
3
star
36

lua---sys

A sys/unix utility package for Lua
Lua
2
star
37

nnfunc

Functional API for nn.
Lua
2
star
38

lbfgs

LibLBFGS (C Lib) wrapper.
Lua
2
star
39

luaforever

LuaForever: run a script forever.
JavaScript
2
star
40

selflua

self contained lib for lua
C
1
star
41

THC

This is the raw C api from Torch7.
C
1
star
42

lua---xml

XML Interface.
C
1
star
43

rawptr

just a raw ptr (2-way) interface to share Storages in Lua
C
1
star
44

lua---debugger

Debugger for Lua
Lua
1
star
45

lua---xlua

A few functions to make life better from the Lua prompt (lua -lxlua).
Lua
1
star
46

lua---lushmat

A simple package to load lush matrices as torch Tensors.
C
1
star
47

nn2

A next version of nn.
Lua
1
star