Registry / devops / lua2rust

lua2rust

JSON →
library0.5.2jsnpmunverified

A transpiler that converts Lua source code to Rust. Current stable version 0.5.2. Release cadence is irregular with occasional updates. Key differentiator: it provides a direct path from Lua scripts to Rust code, though with significant limitations such as no support for metatables, loadstring, or user-defined iterators. It is best suited for simple Lua scripts that use basic constructs.

npm install lua2rust
INSTALL
IMPORT
SIG · LUA2RUST
L
lua2rust
devopsjavascriptv0.5.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (transpiled function)
// no import; transpiled output is a Rust function
import { transpile } from 'lua2rust'
lua2rust is a CLI tool, not a library. Use npx lua2rust to transpile.
cli invocation
npx lua2rust script.lua my_function > output.rs
lua2rust script.lua
Requires two arguments: input file and output function name.
CommonJS require (not applicable)
const lua2rust = require('lua2rust')
Package is CLI only; no programmatic API.

Demonstrates transpiling a simple Lua function to Rust using CLI.

// Create a simple Lua script // test.lua: function greet(name) return "Hello, " .. name end print(greet("World")) # Transpile to Rust npx lua2rust test.lua greet > greet.rs // greet.rs will contain a Rust function corresponding to the Lua code.
lua2rust --version
Debug
Known issues
gotchaTranspiled code uses Rust's `.chars()` for string indexing, which can panic on invalid indices.
fix
Ensure Lua string indices are valid; consider wrapping in Rust's try/catch.
affects: >=0.1.0
gotchaTable operations like `table.insert` and `#t` only work on consecutive arrays starting at index 1.
fix
Restructure Lua tables to be 1-indexed consecutive arrays.
affects: >=0.1.0
gotchaModifying a table while iterating over it leads to undefined behavior.
fix
Avoid modifying tables during iteration; collect changes and apply afterward.
affects: >=0.1.0
gotcha`tonumber` with base argument is not implemented.
fix
Manually implement base conversion in Lua before transpiling.
affects: >=0.1.0
Errors
Common errors & fixes
error: Found argument 'script.lua' which wasn't expected, or isn't valid in this context
Incorrect CLI usage – missing or extra arguments.
fix
Use: npx lua2rust <lua file> <output function name>
thread 'main' panicked at 'index out of bounds: ...'
String index out of range in transpiled Rust code.
fix
Ensure Lua string indices are within bounds (1-based).
Upgrade
Version history
0.5.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
lua2rust — npm install lua2rust · libregistry