Skip to content

Commit edf0a9e

Browse files
mschmickingclaude
andauthored
docs: reposition around Lua 5.1 interop rather than general scripting (#12)
The README led with 'embed Lua 5.1 in your Node.js programs', which invites a comparison against wasmoon and fengari that this package loses: both need no C++ toolchain, and requiring one is a real barrier. That comparison is also the wrong one. The reason to reach for this is that you need Lua 5.1 *exactly* -- to interoperate with a runtime you do not control, such as firmware, Redis scripting or OpenResty -- or that you need real filesystem and process access rather than a sandbox. No no-compile alternative can offer either, because they target a different Lua version and run sandboxed. Adds an honest 'is this the right package?' section that names those alternatives and says plainly when to prefer them. Sending the wrong users away costs nothing; the right ones can now recognise their problem. Also documents that this is stock PUC-Rio Lua 5.1.5 and not LuaJIT, so precompiled bytecode is not interchangeable with a LuaJIT target -- source and C API compatibility are unaffected. And records that Node-API is ABI-stable across Electron as well as Node, which is what makes the addon usable inside a VS Code extension without rebuilding per host release. npm description and keywords updated to match, since that is what appears in search results. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 4312d6f commit edf0a9e

2 files changed

Lines changed: 49 additions & 9 deletions

File tree

README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
# node-lua-runner
22

3-
Embed **Lua 5.1** in your Node.js programs.
3+
**Real Lua 5.1 in Node.js** — for tooling that has to interoperate with a Lua 5.1 runtime you
4+
don't control.
45

5-
Lua and [LuaFileSystem](https://github.com/lunarmodules/luafilesystem) are compiled directly into
6-
the addon, so there is no system Lua to install and nothing to configure — `npm install` builds
7-
everything from source on Linux, macOS and Windows, on both x64 and ARM64.
6+
Lua 5.1 is what Redis scripting, OpenResty/nginx, NodeMCU and ESP-based firmware, and a great
7+
deal of game modding still run on. If you are writing an editor plugin, a build tool or a test
8+
harness that has to speak to one of those, the language version has to match exactly — and it has
9+
to be the real interpreter, not a reimplementation.
810

11+
This package embeds the genuine Lua 5.1.5 interpreter, compiled into a native addon, with the full
12+
standard library and real filesystem and process access. Lua and
13+
[LuaFileSystem](https://github.com/lunarmodules/luafilesystem) are compiled in, so there is no
14+
system Lua to install — `npm install` builds everything from source on Linux, macOS and Windows,
15+
on x64 and ARM64.
16+
17+
- [Is this the right package?](#is-this-the-right-package)
918
- [Installation](#installation)
1019
- [Quick start](#quick-start)
1120
- [Documentation](#documentation)
@@ -14,6 +23,29 @@ everything from source on Linux, macOS and Windows, on both x64 and ARM64.
1423
- [Caveats](#caveats)
1524
- [License](#license)
1625

26+
## Is this the right package?
27+
28+
**Use this when** you need Lua **5.1 specifically**, or you need Lua scripts to touch the real
29+
filesystem and run real processes, or you need the actual Lua C API rather than an approximation
30+
of it.
31+
32+
**Use something else when** you just want to run some Lua and don't care which version. Two good
33+
options that need **no C++ toolchain at all**, which is a genuine advantage:
34+
35+
| | Approach | Toolchain needed |
36+
|---|---|---|
37+
| [wasmoon](https://www.npmjs.com/package/wasmoon) | "A real lua VM with JS bindings made with webassembly" | none |
38+
| [fengari](https://www.npmjs.com/package/fengari) | "A Lua VM written in JS ES6" | none |
39+
| **node-lua-runner** | Native addon around the genuine Lua 5.1.5 C sources | C/C++ compiler |
40+
41+
Both target a newer Lua than 5.1, and both run sandboxed — which is often what you want, and
42+
exactly what you can't use when the point is matching a 5.1 target or reaching the real OS.
43+
44+
> **Note:** this is stock Lua 5.1.5 (PUC-Rio), not LuaJIT. Source-level and C API compatibility
45+
> with a LuaJIT target is fine, but **compiled bytecode is not interchangeable** between LuaJIT
46+
> and PUC-Rio Lua. If you exchange precompiled chunks with a LuaJIT runtime, this is not a drop-in
47+
> replacement.
48+
1749
## Installation
1850

1951
```
@@ -78,10 +110,12 @@ lua.Close();
78110
## How it works
79111

80112
Built on the [Lua 5.1 C API](https://www.lua.org/manual/5.1/manual.html) through
81-
[Node-API](https://nodejs.org/api/n-api.html), which is ABI-stable — a compiled build keeps working
82-
across future Node.js releases instead of breaking on each major version.
113+
[Node-API](https://nodejs.org/api/n-api.html). The API is low-level and maps closely onto the C
114+
API, and it is synchronous throughout — a long-running Lua script blocks the event loop.
83115

84-
The API is low-level and maps closely onto the C API, and it is synchronous throughout.
116+
Node-API matters here beyond mere future-proofing: it is ABI-stable across Node.js **and Electron**
117+
versions, so a single build keeps working as the host updates. That is what makes this usable
118+
inside a VS Code extension, where the extension host's ABI changes with every release.
85119

86120
Descended from [NodeLua](https://github.com/brettlangdon/NodeLua) and
87121
[node-luajit](https://github.com/whtiehack/node-luajit).
@@ -94,6 +128,9 @@ aborts the process rather than throwing a JavaScript exception. `SetField` and `
94128
against this; other methods do not. Keep track of what is on the stack — see
95129
[stack indices](https://github.com/mschmicking/node-lua-runner/blob/master/docs/api.md#stack-indices).
96130

131+
Lua scripts get the full standard library, including `os.execute` and `io.open`. That is the
132+
point of this package, and it means **you should not run Lua you do not trust**.
133+
97134
## License
98135

99136
ISC — see [LICENSE](LICENSE). The vendored Lua and LuaFileSystem sources are MIT; their notices are

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "node-lua-runner",
33
"version": "2.0.1",
4-
"description": "Embed Lua 5.1 in Node.js. Lua and LuaFileSystem are compiled into the addon, so there is nothing to install on the system.",
4+
"description": "Real Lua 5.1 in Node.js, for tooling that must interoperate with a Lua 5.1 runtime. A Node-API native addon with the genuine Lua 5.1.5 interpreter and LuaFileSystem compiled in.",
55
"author": "Maurice Schmicking",
66
"contributors": [
77
"Medaeus245"
@@ -19,7 +19,10 @@
1919
"node-api",
2020
"napi",
2121
"embed",
22-
"scripting"
22+
"scripting",
23+
"lua51",
24+
"embedded",
25+
"interop"
2326
],
2427
"files": [
2528
"index.js",

0 commit comments

Comments
 (0)