lua2php
raw JSON → 0.4.2-1 verified Fri May 01 auth: no javascript
Lua to PHP transpiler that converts Lua source code into PHP. Current version 0.4.2-1. The package is experimental, with many caveats: limited Lua 5.1 support, no metatables, no loadstring, restricted print and error functions, and tables become PHP objects with an 'array' property. It works via CLI command lua2php. Suitable for niche transpilation needs, but not production-ready.
Warnings
gotcha print can only receive one string argument. ↓
fix Concatenate multiple arguments into a single string before passing to print.
gotcha Tables are translated to PHP objects with an 'array' property, not PHP arrays. ↓
fix Access table elements via $table->array[index] instead of $table[index].
gotcha No support for metatables, loadstring, or user-defined iterators. ↓
fix Avoid using these Lua features in code to be transpiled.
Install
npm install lua2php yarn add lua2php pnpm add lua2php Imports
- lua2php CLI wrong
lua2php input.luacorrectnpx lua2php input.lua
Quickstart
// First, install the package:
// yarn add lua2php
// Then, create a Lua file example.lua:
// -- example.lua
// function greet(name)
// print("Hello, " .. name)
// end
// greet("World")
// Finally, run:
// npx lua2php example.lua
// Outputs PHP code to stdout.