{"id":25908,"library":"lua2rust","title":"lua2rust","description":"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.","status":"active","version":"0.5.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install lua2rust","lang":"bash","label":"npm"},{"cmd":"yarn add lua2rust","lang":"bash","label":"yarn"},{"cmd":"pnpm add lua2rust","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"lua2rust is a CLI tool, not a library. Use npx lua2rust to transpile.","wrong":"import { transpile } from 'lua2rust'","symbol":"default (transpiled function)","correct":"// no import; transpiled output is a Rust function"},{"note":"Requires two arguments: input file and output function name.","wrong":"lua2rust script.lua","symbol":"cli invocation","correct":"npx lua2rust script.lua my_function > output.rs"},{"note":"Package is CLI only; no programmatic API.","wrong":"const lua2rust = require('lua2rust')","symbol":"CommonJS require (not applicable)","correct":""}],"quickstart":{"code":"// Create a simple Lua script\n// test.lua:\nfunction greet(name)\n  return \"Hello, \" .. name\nend\n\nprint(greet(\"World\"))\n\n# Transpile to Rust\nnpx lua2rust test.lua greet > greet.rs\n\n// greet.rs will contain a Rust function corresponding to the Lua code.","lang":"javascript","description":"Demonstrates transpiling a simple Lua function to Rust using CLI."},"warnings":[{"fix":"Ensure Lua string indices are valid; consider wrapping in Rust's try/catch.","message":"Transpiled code uses Rust's `.chars()` for string indexing, which can panic on invalid indices.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Restructure Lua tables to be 1-indexed consecutive arrays.","message":"Table operations like `table.insert` and `#t` only work on consecutive arrays starting at index 1.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Avoid modifying tables during iteration; collect changes and apply afterward.","message":"Modifying a table while iterating over it leads to undefined behavior.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Manually implement base conversion in Lua before transpiling.","message":"`tonumber` with base argument is not implemented.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: npx lua2rust <lua file> <output function name>","cause":"Incorrect CLI usage – missing or extra arguments.","error":"error: Found argument 'script.lua' which wasn't expected, or isn't valid in this context"},{"fix":"Ensure Lua string indices are within bounds (1-based).","cause":"String index out of range in transpiled Rust code.","error":"thread 'main' panicked at 'index out of bounds: ...'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}