Convert Figma logo to code with AI

luvit logoluvit

Lua + libUV + jIT = pure awesomesauce

3,883
377
3,883
89

Top Related Projects

24,692

Cross-platform asynchronous I/O

110,238

Node.js JavaScript runtime ✨🐢🚀✨

Get your data in RAM. Get compute close to data. Enjoy the performance.

9,031

http://torch.ch

4,950

Mirror of the LuaJIT git repository

Quick Overview

Luvit is an open-source, asynchronous I/O platform built on LuaJIT and LibUV. It combines the simplicity and performance of Lua with the powerful asynchronous I/O capabilities of Node.js, making it ideal for building scalable network applications and services.

Pros

  • High performance due to LuaJIT's fast execution and LibUV's efficient I/O operations
  • Lightweight and easy to embed in other applications
  • Cross-platform support (Windows, macOS, Linux)
  • Familiar syntax for developers with Lua or JavaScript experience

Cons

  • Smaller ecosystem compared to Node.js or Python
  • Less extensive documentation and community support
  • Limited third-party libraries and modules
  • Steeper learning curve for developers unfamiliar with Lua

Code Examples

  1. Hello World HTTP Server:
local http = require('http')

http.createServer(function (req, res)
  res:writeHead(200, {["Content-Type"] = "text/plain"})
  res:finish("Hello World\n")
end):listen(8080)

print("Server running at http://localhost:8080/")
  1. Reading a file asynchronously:
local fs = require('fs')

fs.readFile('example.txt', function(err, data)
  if err then
    print("Error reading file:", err)
  else
    print("File contents:", data)
  end
end)
  1. Creating a TCP server:
local net = require('net')

net.createServer(function(client)
  client:on('data', function(chunk)
    client:write("Echo: " .. chunk)
  end)
end):listen(1337, "127.0.0.1")

print("TCP server listening on port 1337")

Getting Started

  1. Install Luvit:

    • On macOS/Linux: curl -L https://github.com/luvit/lit/raw/master/get-lit.sh | sh
    • On Windows: Download and run lit.exe from the releases page
  2. Create a new file app.lua:

local http = require('http')

http.createServer(function (req, res)
  res:writeHead(200, {["Content-Type"] = "text/plain"})
  res:finish("Hello from Luvit!\n")
end):listen(3000)

print("Server running at http://localhost:3000/")
  1. Run the application:

    luvit app.lua
    
  2. Open a web browser and navigate to http://localhost:3000 to see your Luvit application in action.

Competitor Comparisons

24,692

Cross-platform asynchronous I/O

Pros of libuv

  • Lower-level C library, offering more fine-grained control and potential performance benefits
  • Wider adoption and use in various projects, including Node.js
  • More extensive documentation and community support

Cons of libuv

  • Steeper learning curve due to its C-based API
  • Requires more boilerplate code for basic operations
  • Less abstraction, which can lead to more complex code for high-level tasks

Code Comparison

libuv example:

#include <uv.h>

int main() {
    uv_loop_t *loop = malloc(sizeof(uv_loop_t));
    uv_loop_init(loop);
    // ... more initialization code
    return uv_run(loop, UV_RUN_DEFAULT);
}

luvit example:

local uv = require('uv')

-- Event loop is automatically created and managed
uv.run()

Additional Notes

luvit is built on top of libuv, providing a Lua-based interface to the underlying libuv functionality. This offers a more user-friendly API for developers familiar with Lua, while still leveraging the power of libuv. luvit aims to simplify asynchronous programming by combining Lua's simplicity with libuv's performance.

While libuv provides a robust foundation for asynchronous I/O operations, luvit adds an extra layer of abstraction, making it easier to write high-level, event-driven applications. The choice between the two depends on the specific project requirements, desired level of control, and the developer's familiarity with C or Lua.

110,238

Node.js JavaScript runtime ✨🐢🚀✨

Pros of Node.js

  • Larger ecosystem with more packages and community support
  • Better documentation and learning resources
  • More mature and stable, with longer track record in production

Cons of Node.js

  • Larger footprint and slower startup time
  • Less efficient for certain I/O-bound tasks
  • More complex to embed in other applications

Code Comparison

Node.js:

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World\n');
});

server.listen(8000);

Luvit:

local http = require('http')

http.createServer(function (req, res)
  res:writeHead(200, {["Content-Type"] = "text/plain"})
  res:finish("Hello World\n")
end):listen(8000)

Both examples create a simple HTTP server that responds with "Hello World". Node.js uses JavaScript, while Luvit uses Lua. Luvit's syntax is more concise, but Node.js's JavaScript may be more familiar to many developers. Luvit aims to provide a Node.js-like environment with Lua, offering potential performance benefits for certain use cases, especially in embedded systems or where a smaller footprint is required. However, Node.js remains the more popular and widely-supported option for server-side JavaScript development.

Get your data in RAM. Get compute close to data. Enjoy the performance.

Pros of Tarantool

  • High-performance in-memory database and application server
  • Built-in support for data replication and sharding
  • Versatile, supporting multiple programming paradigms (procedural, functional, object-oriented)

Cons of Tarantool

  • Steeper learning curve due to its complex feature set
  • Less widespread adoption compared to Luvit
  • More resource-intensive, requiring more system resources

Code Comparison

Tarantool (Lua):

box.cfg{listen = 3301}
box.schema.space.create('users')
box.space.users:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}})
box.space.users:insert{1, 'Alice', 25}

Luvit (Lua):

local http = require('http')
http.createServer(function (req, res)
  res:writeHead(200, {["Content-Type"] = "text/plain"})
  res:finish("Hello World\n")
end):listen(8080)
print("Server running at http://localhost:8080/")

Tarantool focuses on database operations and application server functionality, while Luvit is primarily used for building network applications and services. Tarantool offers more built-in features for data management, while Luvit provides a simpler, more lightweight environment for asynchronous I/O operations.

9,031

http://torch.ch

Pros of Torch7

  • Powerful machine learning and scientific computing framework
  • Extensive support for neural networks and deep learning
  • Large ecosystem of libraries and tools for AI/ML tasks

Cons of Torch7

  • Steeper learning curve for beginners
  • Less active development and community support in recent years
  • Limited support for general-purpose programming tasks

Code Comparison

Torch7 (Neural Network Example):

require 'nn'
model = nn.Sequential()
model:add(nn.Linear(10, 5))
model:add(nn.ReLU())
model:add(nn.Linear(5, 1))

Luvit (HTTP Server Example):

local http = require('http')
http.createServer(function (req, res)
  res:writeHead(200, {["Content-Type"] = "text/plain"})
  res:finish("Hello World\n")
end):listen(8080)
print("Server running at http://localhost:8080/")

Key Differences

  • Torch7 focuses on scientific computing and machine learning, while Luvit is a general-purpose asynchronous I/O framework
  • Torch7 uses LuaJIT for high-performance computing, whereas Luvit leverages libuv for asynchronous operations
  • Luvit provides a more Node.js-like experience for Lua developers, while Torch7 caters to data scientists and AI researchers
4,950

Mirror of the LuaJIT git repository

Pros of LuaJIT

  • Higher performance with Just-In-Time compilation
  • Closer to standard Lua implementation
  • More mature and widely used in production environments

Cons of LuaJIT

  • Lacks built-in asynchronous I/O capabilities
  • Not designed specifically for server-side development
  • Limited ecosystem for web and network programming

Code Comparison

LuaJIT:

local ffi = require("ffi")
ffi.cdef[[
    int printf(const char *fmt, ...);
]]
ffi.C.printf("Hello %s\n", "world")

Luvit:

local uv = require('uv')
uv.run(function()
  print("Hello world")
  uv.timer(1000):start(function()
    print("Timed event after 1 second")
  end)
end)

LuaJIT focuses on high-performance Lua execution with FFI capabilities, while Luvit builds upon LuaJIT to provide an asynchronous I/O framework similar to Node.js. Luvit offers a more comprehensive solution for server-side and network programming, including built-in modules for HTTP, filesystem operations, and event-driven programming. However, LuaJIT provides a more flexible foundation for various types of applications, especially those requiring high performance and low-level system interactions.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Luvit 2.0 - Node.JS for the Lua Inventor

Linux Build Status Windows Build status Coverage Status

Welcome to the source code for Luvit 2.0. This repo contains the luvit/luvit metapackage and all luvit/* packages as published to lit.

This collection of packages and modules implements a node.js style API for the luvi/lit runtime. It can be used as both a library or a standalone executable.

See the main project webpage for more details. https://luvit.io/

Need Help?

Ask questions here through issues, on Discord or the mailing list.

Binary Modules

Luvit supports FFI and Lua based binary modules. There is a wiki entry explaining how to manage and include a binary module within a bundled application. Publishing Compiled Code

Hacking on Luvit Core

First you need to clone and build luvit, this is easy and works cross-platform thanks to Makefile and make.bat.

git clone https://github.com/luvit/luvit.git
cd luvit
make

If you want to test luvit without constantly building, use luvi.

luvi . 

Always make sure to run make test before submitting a PR.

Notes to Maintainers

  • Use luvi /path/to/luvit to test changes without rebuilding the binary.
  • To run the test suite, run make test to build a luvit and use that.
  • If you want to test a custom built luvi, run luvi . -- tests/run.lua
  • If you want to run a specific test file with a custom built luvi, run luvi . -- tests/test-<name-of-test>.lua (e.g. luvi . -- tests/test-http.lua)
  • There is a wiki page on making new luvit releases at https://github.com/luvit/luvit/wiki/Making-a-luvit-release.

The packages in deps live primarily in this repo, but some are duplicated in luvit/lit to ease lit bootstrapping. Updates can be pushed from either repo to lit, just make sure to keep them in sync. One way to do this is to rm -rf deps && lit install. This will install the latest version of all the packages from lit. Check the diff carefully to make sure you're not undoing any work. There might have been unpublished changes locally in luvit that aren't in the lit central database yet.