RBXHaxe - Haxe Library for Roblox

How does this benefit students who are learning the codes such as C++ in university?

I’ve heard the Lua output code from Haxe could use some work. Probably wouldn’t use this for performance intensive code, otherwise this is really cool.

1 Like

I wouldn’t even use the outputted code period. It’s the worst compiled code I’ve seen, beating out even MoonScript.

The one Hello World script I made is 366 lines long. A hello world program. Here’s the link if you care to see.

1 Like

A large amount of the compiled code is never really executed unless you use certain language features.

The only code that really executes at run time in your example is

local Fruits = _hx_tab_array({[0]=“Apple”, “Pear”, “Grape”, “Banana” }, 4);
haxe.Log.trace(Fruits,_hx_o({fields={fileName=true,lineNumber=true,className=true,methodName=true},fileName=“Main.hx”,lineNumber=6,className=“Main”,methodName=“main”}));
local _g = 0;
while (_g < Fruits.length) do
local Fruit = Fruits[_g];
_g = _g + 1;
haxe.Log.trace(Fruit,_hx_o({fields={fileName=true,lineNumber=true,className=true,methodName=true},fileName=“Main.hx”,lineNumber=9,className=“Main”,methodName=“main”}));
end;

That’s still way too much for Hello World.

1 Like

That’s not a hello world :shrug:

An actual hello world would be one line executing, and then the setup for different data structures and watnot (which would never be called)

Although for iterating through a small array and printing it, yea its a bit much

For reference, I wrote a stress test for your example in haxe and pure lua.

Lua:

local fruits = {"apple", "pear", "grape", "banana"}

local startTime = tick()

for i=0, 10000 do
	for k=1, #fruits do
		print(fruits[k])
	end
end

print(tick() - startTime)

Haxe:

class Main {
	static function main() {
		var fruits:Array<String> = ["apple", "pear", "grape", "banana"];
		var startTime:Float = untyped __lua__("tick()");
		for(i in 0...10000)
		{
			for(fruit in fruits) {
				trace(fruit);
			}
		}
		var endTime:Float = untyped __lua__("tick()");
		trace(endTime-startTime);
	}
}

Both running in studio

Haxe runtime: 23.477569103241

Lua runtime: 19.081376075745

So your haxe is 18.72% slower than Lua. A decent difference, but still workable :man_shrugging:

You could increase haxe performance by using the correct type (lua table is a thing in haxe), but to stay true to your source, I kept it as an array.

We are transpiling here so of course there is gonna be a lot of boilerplate code which is basically what you are seeing.

Have you tried comparing a Hello World program to something a little longer? I bet the difference in lines isn’t nearly as drastic. I’m sure it could be a lot shorter if you want to sacrifice readability, but then we’d be back at square one with complaints about that despite Haxe’s intention if you not needing to touch the outputted language. Its a careful balancing act.

1 Like

I’ve been trying out this project and whenever I try to reference a script object, it fails to compile because it says protected string is an unknown type. Any solutions?

Yeah, I already ran into this bug. It was fixed in 1.0.1.

Just run

haxelib update RBXHaxe

and it will fix itself.

So when creating a new instance through new Instance(“Part”) or whatever, it still needs a cast to the actual type. Would it be possible for you to create a fix for this?

Yeah, I have just been casting it thus far. I will go write something up to fix it.

You can now use

Instance.newInstance(“Part”)

in order to create an instance without casting.

run haxelib update in order to install the changes.

So now that the bit library has been ported to roblox, are you planning on porting it over to this instead of using nevermore for it?

Trying to access runservice throws me a syntax error. What am I doing wrong?

O well, impeccable timing. There was a syntax error in the generated file for RunService.

Run:
haxelib update RBXHaxe

1 Like

You keep talking about “casting” but what actually is that?

Do you have a discord I can talk to you on?

Yea, I can’t post it because this is a public section. I’ll DM you it.

Not suree if you’re still maintaining this (1.5 years later) but trying to build it when including anything Roblox gives me this error

/usr/local/lib/haxe/lib/RBXHaxe/3,1,2/PVInstance.hx:7: characters 20-31 : Missing ;