Skip to content

Davvex87/reflaxe.lua

Repository files navigation

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.

Powered by Reflaxe

Also check-out roblox-hx!

Example

Haxe source input:
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


Lua source output (simplified):
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

Progress

Code Generation Efficiency

How optimized the generated output is compared to naturally written Lua.

75

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.

80

Missing:

  • table (native)
  • string (native)
  • math (native)

Haxe Std Library Coverage

How complete are the Std Library's Lua bindings.

60

Missing:

  • net (requires external lib)
  • EReg (somewhat broken)

Haxe Primitives & Types

How many of Haxe's primitive and support types are implemented.

100

Haxe Language Features Support

How many of Haxe's language features are correctly compiled to their Lua alternatives.

100

Setup

  1. Installing Reflaxe:
  • haxelib install reflaxe 4.0.0-beta
  1. Installing the library:
  • haxelib: haxelib install reflaxe.lua
  • github: haxelib git reflaxe.lua https://github.com/Davvex87/reflaxe.lua.git

  1. Adding to project:
  • hxml: -lib reflaxe.lua

  1. Bind an output folder:
-D lua-output=out

  1. 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.

About

A cleaner implementation of the Lua target for Haxe

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages