Lua + libUV + jIT = pure awesomesauce

Overview

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.

Comments
  • Use recent libuv and c-ares & more loop control

    Use recent libuv and c-ares & more loop control

    API Changes

    loop:run method now takes an optional param mode, which defauls to RUN_DEFAULT and can be:

    • RUN_ONCE
    • RUN_DEFAULT
    • RUN_NOWAIT

    Implementation

    • Use recent libuv and c-ares as external submodule.
    • Signal handling changed to new uv_signal_ API.

    Issues

    This is no new issue, but the Signals registered are never unregistered. Thus there is a memory leek. Since the ev_signals are now part of uv_signal_, they are automatically registered. For the moment they are uv_unref ed to let the loop exit.

    opened by lipp 32
  • Luvit 3.0

    Luvit 3.0

    The idea of releasing a new major version of luvit with breaking changes to fix outstanding issues or to address some of its shortcomings comes up occasionally. We recently chatted again about this in Discord. I think it would be good to have a place here for people to share any thoughts on the subject.

    I will share my ideas in an independent post below this one. Please do not hesitate to share your own. Thanks.

    opened by SinisterRectus 31
  • JSON.stringify({}) returns an empty array

    JSON.stringify({}) returns an empty array

    json.stringify({}) return an empty array instead of an emtpy table:

    test-json.lua:

    local JSON = require ("json")
    print(JSON.stringify({}))
    

    Output:

    $ luvit test-json.lua
    []
    

    Node.js returns an empty array for:

    console.log(JSON.stringify({}))
    

    Output:

    $ node test-json.js
    {}
    

    Looking at json.lua https://github.com/luvit/luvit/blob/master/deps/json.lua#L308 sets isa as true and n as 0. The test in the next line fails, because valmeta = getmetable({}) is false.

    What can we do about it?

    opened by joerg-krause 28
  • thread.start should allow arguments to be passed to function

    thread.start should allow arguments to be passed to function

    I noticed in the documentation it shows that threads accept a second argument. I looked at the source and noticed it has no limit on arguments.

    The second argument should also be allowed to pass arguments to the function, to allow something like this:

    local function test(arg1,arg2)
        return arg`1 + arg2
    end
    
    thread.start(function_name, arg1, arg2)
    

    Of course the first portion of this issue is a must for me as I require that arguments be passed to the function. Either arguments, a table with arguments, or a metatable to allow for custom environments for the function in the thread to allow further customization would be amazing.

    Also a great possibility is that the thread, if taking too long or stalls completely, gives the ability to be terminated. This is especially great for what I plan on using luvit for.

    opened by mrparkerlol 27
  • Issues with Luvi > 2.9.1

    Issues with Luvi > 2.9.1

    Building Luvit with the latest released version of Luvi (2.9.1) has some issues that need to be resolved. This is not a complete list, just some things I'm aware of:

    • [x] test-crypto.lua:42: bad argument #1 to 'export' (only accept 'pem','der' or none). Seems to be related to lua-openssl binding/updated openssl version.
    • [x] [Windows only?] test-process.lua: Missing 1 expected call for both child process no stdin and child process (no stdin, no stderr, stdout) with close
    • [x] https://github.com/luvit/luvit/pull/944#issuecomment-469864902 and subsequent comments
    • [x] (perhaps related to above) [Linux only?] test-process.lua: 1 unclosed handle in invalid command and Missing 1 expected call in invalid command verify exit callback
    • [x] [Windows only?] test-tls-remote.lua:33: assertion failed! (err = ssl); err comes from local ret, err = self.ssl:handshake() in tls/common.lua:364. Similar failures in other tls tests
    • [x] test-process-exec.lua from #1075

    All the broken stuff seems to be related to either libuv spawn or openssl.


    Changes between Luvi 2.7.6 and 2.9.1:

    • luvi: https://github.com/luvit/luvi/compare/v2.7.6...v2.9.1
    • luv v1.9.1-1 -> v1.25.0-0: https://github.com/luvit/luv/compare/1.9.1-1...1.25.0-0
    • openssl 1.0.2h -> 1.1.0i
    • lua-openssl 6e96296 -> 0.7.4: https://github.com/zhaozg/lua-openssl/compare/6e96296ba41f893a3821528cc46d0c406374df51...0.7.4
    tests 
    opened by squeek502 18
  • Question: Is there any WebSocket server as https://github.com/websockets/ws

    Question: Is there any WebSocket server as https://github.com/websockets/ws

    https://github.com/websockets/ws is a WebSocket client and server for Node.js

    const WebSocket = require('ws');
    
    const wss = new WebSocket.Server({ port: 8080 });
    
    wss.on('connection', function connection(ws) {
      ws.on('message', function incoming(message) {
        console.log('received: %s', message);
      });
    
      ws.send('something');
    });
    

    Broadcast example

    const WebSocket = require('ws');
    
    const wss = new WebSocket.Server({ port: 8080 });
    
    // Broadcast to all.
    wss.broadcast = function broadcast(data) {
      wss.clients.forEach(function each(client) {
        if (client.readyState === WebSocket.OPEN) {
          client.send(data);
        }
      });
    };
    
    wss.on('connection', function connection(ws) {
      ws.on('message', function incoming(data) {
        // Broadcast to everyone else.
        wss.clients.forEach(function each(client) {
          if (client !== ws && client.readyState === WebSocket.OPEN) {
            client.send(data);
          }
        });
      });
    });
    
    opened by ghost 18
  • problems with uv.try_write and signals

    problems with uv.try_write and signals

    Since commit 7cab2d9a6d673915a3d4ff0b4956d05fa8c75b5c the test signal usr1,usr2,hup fails on my Arch Linux system:

    # Starting Test: signal usr1,usr2,hup
      /home/joerg/Development/git/luvit/tests/libs/tap.lua:83: Missing 3 expected calls
      stack traceback:
      	[C]: in function 'error'
      	/home/joerg/Development/git/luvit/tests/libs/tap.lua:83: in function </home/joerg/Development/git/luvit/tests/libs/tap.lua:64>
      	[C]: in function 'xpcall'
      	/home/joerg/Development/git/luvit/tests/libs/tap.lua:64: in function 'run'
      	/home/joerg/Development/git/luvit/tests/libs/tap.lua:165: in function </home/joerg/Development/git/luvit/tests/libs/tap.lua:142>
      	/home/joerg/Development/git/luvit/tests/test-process.lua:6: in function 'fn'
      	[string "bundle:deps/require.lua"]:310: in function 'require'
      	/home/joerg/Development/git/luvit/main.lua:118: in function 'main'
      	/home/joerg/Development/git/luvit/init.lua:49: in function </home/joerg/Development/git/luvit/init.lua:47>
      	[C]: in function 'xpcall'
      	/home/joerg/Development/git/luvit/init.lua:47: in function 'fn'
      	[string "bundle:deps/require.lua"]:310: in function <[string "bundle:deps/require.lua"]:266>
    not ok 3 signal usr1,usr2,hup
    

    Edit: Tested with lates luvi:

    $ luvi --version
    luvi v2.11.0
    rex: 8.37 2015-04-28
    libuv: 1.34.2
    ssl: OpenSSL 1.1.1d  10 Sep 2019, lua-openssl 0.7.7
    
    $ cd luvit
    $ luvi . -- tests/test-process.lua
    
    tests 
    opened by joerg-krause 17
  • Issues with code  stuck

    Issues with code stuck

    There's the test code

    local Emitter = require('core').Emitter
    local i= 0
    local Client = Emitter:extend()
    function Client:initialize()
      self:on('Method1', function ()
                print('Method1 -- '..i)
                i = i + 1
      end)
    end
    function Client:start()
    while true do
      self:emit('Method1')
    end -- END while
    end
    local x = Client:new()
    x:start()
    

    and output stucked like this:

    Method1 -- 0
    Method1 -- 1
    Method1 -- 2
    Method1 -- 3
    ...
    Method1 -- 954
    Method1 -- 955
    Method1 -- 956
    Metho
    

    It's stuck the last line. I test this because my server been stucked when I want print some log .

    Is someone can help?

    bug 
    opened by giepher 17
  • Peer Aborted the SSL Handshake

    Peer Aborted the SSL Handshake

    Hello, I'm here today to report an issue that has been happening to a lot of users so many times and I don't find a solution to it.

    Using coro-http module, depends on what sites (all of them are HTTPS) we receive that error above, "Peer Aborted the SSL Handshake". As it is obvious, we switched to https module to see if this could fix it, but sadly, it didn't.

    I don't bring any actual code example because it is just a simple GET request. This is the url i've been having problems with:

    https://elosuite.com/loader_files/db.php

    Seems like a luvit problem.

    opened by Xh4H 16
  • How to make sure the main thread waits for the called function to complete.

    How to make sure the main thread waits for the called function to complete.

    Hi, I am new to lua & luvit. Please help with the below issue. The main execution sequence does not wait for getVersion() to complete.

    --global variable. version = nil print('Before fn call') getVersion() if(version == '1.2') then --do something else -- do something else end print('version=' .. version) print('Done')

    local function getVersion() print('Inside getVersion') .... .... local req = http.request(options, function (res) print("Inside request") res:on('data', function (data) ---get the version and assign to global variable version. print('version:' .. version) end) print('After the execution') end) req:done() end


    Below is the console output when I run the same.

    Before fn call Inside getVersion version=nil Done Inside request version:1.2 After the execution

    I want to make sure the getVersion fn is completed before continuing with the main thread. I tried a method fiber.wait(fn()), but did not workout. Is this the right method, or do we have any other way to get it done.

    Any help regarding the same is much appreciated.

    Thanks & regards, Joe

    question 
    opened by JoeBmc 16
  • Move http.headerMeta to its own package and add util functions

    Move http.headerMeta to its own package and add util functions

    Adds luvit/http-header package containing:

    • headerMeta (moved from http)
    • newHeaders() (returns a new table with headerMeta as its metatable)
    • toHeaders(tbl) (converts a table of header values into a table with headerMeta as its metatable)
    • combineHeaders(...) (converts and combines tables into a single table with headerMeta as its metatable)
    • getHeaders(tbl) (extracts headers from the array-like portion of tbl into a new table with headerMeta as its metatable)

    See the comments in http-header.lua for slightly more info on each function.

    Rationale:

    http.headerMeta can be useful outside of the Luvit http package. For example, it (along with the added utility functions) could be used with coro-http like so:

    local http = require('coro-http')
    local httpHeader = require('http-header')
    
    local headers = httpHeader.newHeaders()
    headers['accept'] = 'application/json'
    
    local res, body = http.request('GET', 'https://lit.luvit.io', headers)
    
    local resHeaders = httpHeader.getHeaders(res)
    assert(resHeaders['content-type'] == 'application/json')
    

    Notes

    • Let me know if you'd like any changes to the name of the package, the names of the functions, and/or any of the comments--I definitely think they can be improved.
    opened by squeek502 16
  • fs module does not propagate errors properly

    fs module does not propagate errors properly

    Some synchronous functions in fs do not check for errors properly, e.g consider this portion of fs.readdirSync

    function fs.readdirSync(path)
      local req = uv.fs_scandir(path)
      local files = {}
      local i = 1
      while true do
        local ent = uv.fs_scandir_next(req)
    

    It did not consider the possibility of uv.fs_scandir returning a nil, err and ends up passing nil to the next uv call instead of propagating the error to the user.

    This leads to confusing errors like the following when a filepath does not exist:

    > fs.readdirSync("aksnsjwjsjs")
    [string "bundle:/deps/fs.lua"]:205: bad argument #1 to 'fs_scandir_next' (uv_req expected, got nil)
    stack traceback:
            [C]: in function 'fs_scandir_next'
            [string "bundle:/deps/fs.lua"]:205: in function <[string "bundle:/deps/fs.lua"]:200>
            [C]: in function 'xpcall'
            [string "bundle:/deps/repl.lua"]:97: in function 'evaluateLine'
            [string "bundle:/deps/repl.lua"]:189: in function <[string "bundle:/deps/repl.lua"]:187>
    >
    

    It should instead report the error as an ENOENT from our side instead of a stacktrace coming from luvit's source.

    opened by ravener 0
  • Apple M1 Mac, get error

    Apple M1 Mac, get error "curl: (22) The requested URL returned error: 404"

    Okay, so, on the website's "install" page, it states that to download luvit, you run: curl -L https://github.com/luvit/lit/raw/master/get-lit.sh | sh upon doing this, it does its thing for a moment, and then i get hit with "curl: (22) The requested URL returned error: 404". I am a command line newbie, so go easy on me.

    also, i tried to install luvit via homebrew - idk if that's recommended or not - but it returned a whole buncha errors.

    opened by ACAT-0 1
  • Unix domain sockets

    Unix domain sockets

    I'm curious if there's any interest in supporting unix domain sockets as well as network sockets. It could look something like

    http.createServer(function(req, res)
    ...
    end):listen("/tmp/luvit.socket")
    

    There's an advantage in being easier to use with a server like nginx to forward requests, is less likely to conflict, can't be accessed on a network, which has fewer security problems and quirks, and is more descriptive and memorable than a random TCP socket number. On unix-like systems TCP/domain sockets just end up as file descriptors with all the standard system calls, so theoretically it should be really easy to implement, and it's standard lib stuff so no bloat

    This is supported by Node and Express already in this exact same way

    Starts a UNIX socket and listens for connections on the given path. This method is identical to Node’s http.Server.listen().

    var express = require('express')
    var app = express()
    app.listen('/tmp/sock')
    
    opened by Trendyne 2
  • require module with non-existant modulepath results in infinite loop

    require module with non-existant modulepath results in infinite loop

    When using a structure as following: src/ main.lua

    Then running luvit on src/main.lua where we create a module for "Test" using the generator, any following require just causes an infinite loop to occur.
    Example main.lua:

    local generator = require('require')   
    local myRequire, myModule = generator("Test")   
    myRequire("file1")
    

    Looking into it, it seems that require.lua:190 tries to step up one level in the directory-hierarchy, while base path is an empty string, which results in the same empty path string.

    -- Otherwise, keep going higher   
    base = pathJoin(base, "..")
    

    I guess this case should be accounted for explicitly

    opened by PatrickDahlin 1
  • Version history table

    Version history table

    I'm opening this issue as a reminder to myself to write some sort of table or list that shows past luvit versions and their corresponding luvi/luv/luajit versions. Just as a matter of record keeping. I don't know where to put it. I guess a simple markdown file would do. Maybe it can be put somewhere on the website later.

    opened by SinisterRectus 0
Releases(2.18.1)
  • 2.18.1(Nov 19, 2021)

  • 2.18.0(Nov 19, 2021)

    • luvi: bump to v2.12.0 [Tim Caswell]
    • lit: update to 3.8.5 [Tim Caswell]
    • luvit: add the changelog [Tim Caswell]
    • Wrap main in a coroutine [@truemedian]
    Source code(tar.gz)
    Source code(zip)
  • 2.17.0(Mar 10, 2020)

    • luvi: bump to v2.10.1
    • core: fix Emitter:removeAllListeners (#1088) [Timothy Van Wonterghem]
    • stream: remove extra argument to doWrite call in stream_writable (#1093) [David Newman]
    • fix abort when redirecting stdout/stderr to file (#1095) [Ryan Liptak]
    • process: fix process.stdin abort when stdin is redirected from a file (#1096) [Ryan Liptak]
    • pretty-print: use try_write for tty stderr/stdout (#1097) [George Zhao]
    • lit: bump to v3.8.1
    Source code(tar.gz)
    Source code(zip)
Owner
Luvit Community
Luvit Community
Common Lisp and CXX interoperation with JIT

CL-CXX-JIT - Common Lisp C++ JIT for exposing C++ functions This library provides an interface to C++ from lisp. It compiles C++ code, then loads it i

Islam Omar 39 Dec 19, 2022
Mirror of MRuby JIT

What is mruby mruby is the lightweight implementation of the Ruby language complying to (part of) the ISO standard. Its syntax is Ruby 1.9 compatible.

The Ruby Compiler Survey 2 Nov 18, 2021
Simple, fast, JIT-compiled scripting language for game engines.

Aftel Aftel (acronym for «A Far Too Easy Language») is a programming language, primarily intended to serve as an embeddable scripting language for gam

Rosie 17 May 20, 2022
A C++ expression -> x64 JIT

NativeJIT NativeJIT is an open-source cross-platform library for high-performance just-in-time compilation of expressions involving C data structures.

null 1.1k Dec 8, 2022
The Lua development repository, as seen by the Lua team. Mirrored irregularly

The Lua development repository, as seen by the Lua team. Mirrored irregularly

Lua 6.4k Jan 5, 2023
A dependency free, embeddable debugger for Lua in a single file (.lua or .c)

debugger.lua A simple, embedabble debugger for Lua 5.x, and LuaJIT 2.x. debugger.lua is a simple, single file, pure Lua debugger that is easy to integ

Scott Lembcke 600 Dec 31, 2022
It is a basic calculator created by me in Pure C++

Basic-Calculator It is a basic calculator created by me in C++ If you find any bug then let me know How to use: 1. Enter first value it ask 2. Enter s

ryan 2 Dec 21, 2021
Pure Data patch export to lv2 plugin using heavy compiler + dpf example

Pure Data patch export to lv2 plugin using heavy compiler + dpf example Work in progress - Takes an audio input and writes to a 0.5 seconds buffers. 4

Qwrtst 3 Dec 27, 2022
The Rumor is pure, nasty growling bass fuzz pedal, with bold out-front presence, and cutting articulation.

Rumor.lv2 The Rumor is pure, nasty growling bass fuzz pedal, with bold out-front presence, and cutting articulation. Features Nasty FUZZ simulation. D

Hermann 12 Feb 28, 2022
Microshell - a lightweight pure C implementation of shell emulator dedicated for embedded bare-metal systems.

MicroShell Lightweight pure C implementation of virtual shell, compatible with VT100 terminal. Support root tree, run-time mounting paths, global comm

Marcin Borowicz 110 Jan 5, 2023
Dynamic 3D cellular automata engine with lua scripting support

Cell3D Cell3D is a dynamic 3D cellular automata engine with lua scripting support Installation Dependencies: Lua 5.3 Raylib Simplest possible build co

null 2 Oct 7, 2022
A programming environment for Lua for the Raspberry Pi Pico microcontroller

picolua A programming environment for Lua for the Raspberry Pi Pico microcontroller. Version 0.3, April 2021 What is this? picolua is a proof-of-conce

Kevin Boone 65 Jan 8, 2023
Hobbyist Operating System targeting x86_64 systems. Includes userspace, Virtual File System, An InitFS (tarfs), Lua port, easy porting, a decent LibC and LibM, and a shell that supports: piping, file redirection, and more.

SynnixOS Epic Hobby OS targeting x86_64 CPUs, it includes some hacked together functionality for most essential OSs although, with interactivity via Q

RaidTheWeb 42 Oct 28, 2022
Plua is a superset of Lua for classic PalmOS devices with added support for graphics, UI, networking, events and sound.

Plua2c Plua is a superset of Lua for classic PalmOS devices with added support for graphics, UI, networking, events and sound. This is the source code

Cameron Kaiser 9 Jan 5, 2023
rlua -- High level bindings between Rust and Lua

rlua -- High level bindings between Rust and Lua

Amethyst Foundation 1.4k Jan 2, 2023
Modified version of srlua for MSVC using version 5.4 of Lua

Modified version of srlua for MSVC using version 5.4 of Lua. Quote from the original README: This is a self-running Lua interpreter. It is meant to be

Augusto Goulart 4 Jan 4, 2023
format lua code

EmmyLuaCodeStyle 项目介绍 该项目是基于C++的lua代码格式化算法库 经过长期实践,发现人们对格式化算法的预期是尽可能少的改动代码的行布局,而列布局符合基本审美就可以了。 基于这样的想法我设计并实现了lua格式化算法 格式化行为介绍 基本语句 该算法的主要特点是分析并对当前代码做出

null 58 Jan 8, 2023
Poly2tri lua wrapper

Poly2tri lua wrapper This is a Lua wrapper around poly2tri. It provides fast, stable Constrained Delauney Triangulation of convex or concave polygons

Dima 9 Nov 25, 2021
FFF is a decentralized blockchain based on IPFS/RIPPLE, which integrates lua virtual machine-based smart contracts.

FFF is a decentralized blockchain based on IPFS/RIPPLE, which integrates lua virtual machine-based smart contracts. It is also a software platform designed to help coordinate voluntary free market operations amongst a set of social actors.

gen2600 6 Oct 24, 2022