npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

v8lua

v0.1.1

Published

Lua 5.1 interpreter running on V8 (Node.js), written in plain JavaScript

Readme

v8lua

A Lua 5.1 interpreter (plus goto/labels from 5.2) written in plain modern JavaScript, running on the V8 engine via Node.js. No dependencies.

Behavior is verified differentially against LuaJIT: every conformance test runs under both luajit and v8lua and the outputs must match byte-for-byte — including number formatting (%.14g), error messages with variable-name hints (attempt to index local 'x' (a nil value)), and coroutine semantics.

Usage

# run a script
./v8lua script.lua [args...]

# one-liner
./v8lua -e 'print("hello from lua on v8")'

# REPL
./v8lua

# piped stdin
echo 'print(2^10)' | ./v8lua

Embedding from JavaScript:

import { createInterp, runSource } from './src/index.js';

runSource('return 1 + 1');                  // -> [2]

const I = createInterp({ stdout: s => process.stdout.write(s) });
I.run('print("hi")');                        // globals persist across runs
I.run('x = 42');
I.run('print(x)');                           // -> 42

Tests

npm test                      # diff every tests/lua/*.lua against luajit
node tests/run.js --only 08   # filter by substring
node tests/run.js --update    # snapshot oracle output into tests/expected/

17 conformance programs cover literals, arithmetic/coercion, control flow, closures/varargs/multiple returns, proper tail calls (10^6 deep), tables and the table library, metatables (all metamethods), the string library, the full Lua pattern engine, string.format, coroutines (incl. nested), errors/pcall/ xpcall, goto/labels, scoping rules, load/loadstring, and a small stress program.

Architecture

| File | Role | |------|------| | src/lexer.js | tokenizer (all literal forms, long brackets, escapes) | | src/parser.js | recursive-descent + precedence-climbing parser → AST | | src/runtime.js | value model, LuaTable, metamethod-aware operations | | src/interp.js | generator-based tree-walking evaluator, call protocol | | src/lib/lpattern.js | Lua pattern matcher (port of lstrlib.c logic) | | src/lib/*.js | base / string / table / math / os / io / coroutine libs | | src/stdlib.js, src/index.js | assembly + embed API | | v8lua | CLI and REPL | | docs/SPEC.md | the binding contract the modules were built against | | docs/TASKS.md | the fine-grained task breakdown used to build this |

How coroutines work

Every evaluation function is a JS generator, chained with yield*. A coroutine.yield deep inside a call stack yields a sentinel object that propagates transparently through every frame to the driving coroutine.resume loop, which passes resume values back in through iterator.next(). The main chunk's driver rejects stray yields ("attempt to yield from outside a coroutine"). V8's generator machinery effectively provides the stack switching.

Proper tail calls

return f(...) compiles to a tailcall completion: the closure-call loop rebinds its frame variables instead of recursing, so tail-recursive loops run in O(1) JS stack.

Semantics notes / limitations

  • Numbers are IEEE doubles (Lua 5.1 model; no 5.3 integer subtype). Formatting follows %.14g.
  • Strings are JS strings (UTF-16 code units); for ASCII data this matches Lua's byte semantics. Embedded \0 works.
  • # on tables follows border semantics (binary-search like PUC-Lua); tables with holes may report a different (but valid) border than LuaJIT's array-part heuristic.
  • goto label visibility is checked per-function (slightly looser than Lua 5.2's block scoping).
  • Not implemented: file handles in io (only write/read on stdout/stdin), require/package, string.dump, debug library, os.setlocale/tmpname/remove/rename, weak tables / __gc (GC is V8's), __len on tables (matches LuaJIT default).
  • error(msg, 2) uses the current line rather than the caller's line (no per-frame line tracking).