A compiler that compiles Haxe code into native Lua 5.1 without all of the bloat that the default Haxe compiler produces. It attempts to match Haxe's sources as closely as possible to their Lua implementations (arrays and objects get converted into tables, Int, Int64, Int32, Float and Double also just get converted to Lua's number type, etc...).
Made to be editable and extendable to other Lua versions/subsets (i.e. Lua 5.3, LuaJIT, Luau, Squirrel) with ease.
Also check-out roblox-hx!
Example
class Main
{
static function main()
{
var arr = [1, 2, 5];
arr.push(8);
trace(arr[2]); // 5
}
}
// Most types will be converted to
// their native lua implementations
// whenever possible. Less bloat :D
local Main = setmetatable({}, {
__tostring = function(self)
return "Class<Main>"
end;
})
Main.__index = Main
function Main.main()
local arr = {1, 2, 5}
table.insert(arr, 8)
Log.trace(arr[3], {
fileName = "Code.hx",
lineNumber = 300,
className = "Main",
methodName = "main"
})
end
Table of Contents
- Introduction
- Example
- Progress
- Setup
- Installing the library
- Adding to project
- Bind an output folder
- Configure as needed
- Usage
- Troubleshooting
- Contributing
- TODO
Progress
Code Generation Efficiency
How optimized the generated output is compared to naturally written Lua.
Generation Problems:
- Unary operator overhead through unnecessary function calls
- OpAssignOp (+=, -=, &=, etc..) overhead through unnecessary function calls
- Blind objects (the compiler makes often heavy assumptions about objects)
- Null checks often create variables and unecessary scope blocks since the or lua op is the same as ??
Lua API Coverage
How much of Lua's API is covered by Reflaxe.lua.
Missing: - table (native) - string (native) - math (native)
Haxe Std Library Coverage
How complete are the Std Library's Lua bindings.
Missing: - net (requires external lib) - EReg (somewhat broken)
Haxe Primitives & Types
How many of Haxe's primitive and support types are implemented.
Haxe Language Features Support
How many of Haxe's language features are correctly compiled to their Lua alternatives.
Setup
- Installing Reflaxe:
-
haxelib install reflaxe 4.0.0-beta -
Installing the library:
- haxelib:
haxelib install reflaxe.lua - github:
haxelib git reflaxe.lua https://github.com/Davvex87/reflaxe.lua.git
- Adding to project:
- hxml:
-lib reflaxe.lua
- Bind an output folder:
-D lua-output=out- Configure as needed:
# Paste this script in your .hxml file and configure to suit your needs.
# To enable a configuration, uncomment by removing the "#" character before each -D flag.
# Flags which include an argument assignment (i.e. ``-D lua-safe=<no|soft|full>``) can be selected to have a mode.
# Bitwise operations will use the bit32 library when possible.
#-D lua-bit32
# String operations will use the utf8 library when possible.
#-D lua-utf8
# Inline log operations to the ``print`` function
#-D lua-inline-trace
# All type checking operations at runtime will do deep checks to ensure the correct result is always returned, at the cost of runtime performance.
# ``no`` - Safe checking is off (default);
# ``soft`` - Performs only fast checks (ideal);
# ``full`` - Ensures that type checks return the correct value every time (safest, but heavy);
#-D lua-safe=<no|soft|full>
Usage
All Haxe types present in the Haxe Standard Library can be used as usual.
Reflaxe.lua also provides it's own lua library for quick access to lua objects and methods, these operations can be found under the rlua package
Troubleshooting
If you are having compile-time errors or run-time issues, please take a look at TROUBLESHOOTING.md before submitting an Issue.
Contributing
If you're interested in helping the project, feel free to open a pull request or submit an issue. Please just make sure that the issue you're reporting has not been reported yet, same thing for pull requests.
Both Reflaxe.lua and Reflaxe are community ran projects made for everyone and to suit everyone's needs. There's still a lot to implement and improve, every contribution helps a ton ❤️.
To-Do
View TODO.md.