Code Monkey home page Code Monkey logo

luajit-libuv's Introduction

luajit-libuv build status

This project provides a LuaJIT FFI binding to libuv, the async I/O library powering Node.js. It uses Lua coroutines to provide non-blocking I/O with synchronous syntax.

For example, you can build a web server that performs I/O (like reading a file or talking to a database) while generating each response, and it will process multiple requests simultaneously.

local http = require 'uv.http'
local fs = require 'uv.fs'

http.listen('127.0.0.1', 8080, function(request)
  return { status = 200, body = fs.readfile('README.md') }
end)

Or you can perform multiple HTTP requests simultaneously.

local http = require 'uv.http'
local parallel = require 'uv.parallel'

local requests = {
  { url = 'http://www.google.com/' },
  { url = 'http://www.bing.com/' },
  { url = 'http://www.amazon.com/' },
}

local responses = parallel.map(requests, http.request)

Status

Not production ready. Under active development. The API is unstable.

Requirements

  • LuaJIT. Regular Lua won't run it. That said, you probably want LuaJIT anyway.

  • Standard build tools.

  • libuv and http-parser are bundled and do not need to be installed separately.

Installation

git clone https://github.com/pguillory/luajit-libuv.git
cd luajit-libuv
make
make install

API Reference

Functions are divided into submodules. Each submodule can either be required directly or accessed indirectly through the uv module:

local fs = require 'uv.fs'

local uv = require 'uv'
local fs = uv.fs

Contributing

Your contributions are welcome! Please verify that make test succeeds and submit your changes as a pull request.

See Also

Other people have done things like this.

luajit-libuv's People

Contributors

pguillory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luajit-libuv's Issues

Libuv 1.0.2

I'm looking into upgrading this library to version 1 of libuv (1.0.2).
Looks like most things are working out of the box, but I'm struggling with scandir changes, specifically scandir_next.

Do you have plans to look at 1.0.2 yourself?
Do you have any tips on how to deal with scandir changes?

Building against libuv-0.11.27

Great job at getting libuv to work with a synchronous syntax! However libuv changed a lot since 0.10.21 and building it against 0.11.27 yields a lot of errors. Do you mind taking a look by installing libuv with the --devel option: brew install --devel libuv before building luajit-libuv? Thanks

attempt to index upvalue 'libuv2' (a boolean value)

I'm getting this error on make test:

make test
luajit: src/uv/uv_tcp_t.lua:57: attempt to index upvalue 'libuv2' (a boolean value)
stack traceback:
    src/uv/uv_tcp_t.lua: in function 'listen'
    test/uv_test.lua:12: in function <test/uv_test.lua:9>
stack traceback:
    [builtin#19]: at 0x0100036e30
    [C]: in function 'uv_run'
    src/uv/uv_loop_t.lua:22: in function 'run'
    test/uv_test.lua:9: in main chunk
    [C]: at 0x0100001f60
make: *** [run-tests] Error 1

I think it's related to this line in the Makefile:
gcc -dynamiclib src/uv/libuv2.c -o src/uv/lib/libuv2.dylib -luv -L src/uv/lib
where libuv2.dylib seems to be referencing /usr/local/lib/libuv.11.dylib instead of src/uv/lib/
I was not able to track it further. Thanks

How can I help?

There is no contact information for the maintainer, so I am posting here. Sorry.

This is awesome!

The project is still under active development, but is there any way I can help?

Regards, @jtarchie

Hitting LuaJIT "too many callbacks" wall

It seems the FFI approach with callbacks ends up hitting the callbacks limit wall (see http://luajit.org/ext_ffi_semantics.html#callback):

Callback resource handling
Callbacks take up resources โ€” you can only have a limited number of them at the same time (500 - 1000, depending on the architecture). The associated Lua functions are anchored to prevent garbage collection, too.

A far-fetched example that demos the "too many callbacks" error:

for i=1, 1000 do
  uv.run(function()
    print(i)
  end)
end

Any workarounds?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.