What is Haxe?
Haxe is a language that is designed to be transpiled from. It has support for languages such as Java, C++, C#, Python, JavaScript, and of course Lua.
Why?
Well for starters, haxe is a strongly typed object orientated language. I wrote this for 3 reasons.
- Strongly typed languages are less error prone in my experience.
- Because Haxe is a language that is designed to be transpiled from, writing a game in Haxe allows you to share logic between different platforms. What this means is a carefully designed game could in theory be released on Roblox as well as another platform through a different game engine (IE Heaps).
- Because I could
How?
Roblox has an endpoint where you can download its API in JSON format. You can see how this is done here. A whole lot of parsing later, it spits out valid haxe externs.
Where can one learn haxe?
Due to dev forum restrictions, I canāt put a direct link to that. However Haxeās homepage has some great tutorials!
How do I make a roblox game in Haxe
-
Download Haxe
-
Learn how to write Haxe
-
Once you have downloaded haxe and got the basics down, run
haxelib install RBXHaxe
-
Open up a place, and install nevermore (Iām to lazy to write my own lazy library loader, so its got a dependency on this for now)
-
Grab this model, put it in nevermores shared folder. This adds support for bitwise operators, and redirects Haxe unicode to the default string library.
-
Create a Lua file in your Haxe project directory and insert the following:
_G.table = table
require = require(game.ReplicatedStorage:WaitForChild(āNevermoreā))
local globalEnv = getfenv()
local RBXEnum = globalEnv[āEnumā]
setmetatable(_G, {__index = (function(t, i) return globalEnv[i] end)})
Haxe assumes that default Lua libraries are in the global table. You canāt override this behavior as far as I know, so this snippet redirects them to the global scope where they reside in roblox Lua.
- In your build.hxml (you did actually read a haxe tutorial didnāt you?) insert the following compiler instructions:
-D lua_ver 5.1
-D LuaVanilla
-lib RBXHaxe
āmacro includeFile(āFile name of the lua snippet aboveā)
- Build it, plop your files into studio and call it a day
I have questions or things arenāt working
I canāt put a discord link, so yea. Send a reply, post an issue on github, or something. I dunno.
Things to note
The Enum keyword was factored out. Enums are accessed directly.
IE
var a:SurfaceType = SurfaceType.Smooth
Operator overloading is not possible in Haxe. In order to call operators, inline functions were implemented. In other words:
var a:CFrame = new CFrame(0,0,0)
var b:CFrame = a.mul(new CFrame(1,0,0))
Changelog
0.0.1 Initial commit
0.0.2 Fixed a bug where Int64s were not being imported correctly
1.0.0 Functions that return an instance now return a Dynamic instead to avoid having to cast constantly
1.0.1 Fixed a bug where ProtectedStrings were not a defined type (damn documentation not listing them as a basic type reeee)
2.0.1 Implemented Instance.newInstance in order to create an instance without casting. (also accidentally messed up the version number
2.0.2 Fixed a bug where function arguments that were named āfunctionā would cause a type error.
2.0.3 Imported function type into all class files
2.0.4 Implemented Game:GetService() (oops)
2.0.5 Changed the keyword game to an instance type
2.0.6 Made instance functions that return an instance (FindFirstChild, WaitForChild, etcā¦) return a dynamic to reduce casting
2.0.7 Made game methods non-static (oops)
2.0.8 Added in the debug class
3.1.2 O-boy, am I behind on changelogs. A LARGE amount of fixes and stuff including stuff such as changing int64 definitions to ints, fixing a bug where arguments called āoverrideā would die horribly, and a ton of other tweaks.
3.1.3 Added new types. Updated API to current version.