Skip to content

bradparks/LuaXe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LuaXe

Lua target for Haxe language

State: pre-alpha

Primarily LuaJIT -> make super-optimized portable Haxe target!

I have some working fast (beats V8 and Neko) code otput.

Note: dont beleave benchmarks from demo folder, they show low performance just because of immature code generator. Manually tweaked code works really well. Happily, this process would be automated soon.

Require Haxe Compiler 3.1, Lua 5.2 or LuaJIT 2

Installation & Usage !fully functional!

Quick install:

haxelib git luaxe https://github.com/PeyTy/LuaXe.git

Quick update:

haxelib update luaxe

First, you need to set JS target in your HXML file: -js bin/hx.lua Note to set .lua file type. Than, add LuaXe lib: -lib luaxe Add LuaXe macro: --macro luaxe.LuaGenerator.use() Dont forget to add -D lua or it won't compile. Path luaxe/std contains patched std libs. Complete HXML file:

-main Main
-D lua
-lib luaxe
-cp luaxe/std
-js bin/hx.lua
--macro luaxe.LuaGenerator.use()
-dce full
--connect 6000

(dce and connect is optional)

You can run your file just after compilation directly in stand-alone Lua environment:

-cmd /usr/local/bin/luajit bin/hx.lua
or:
-cmd /usr/local/bin/lua bin/hx.lua

Magic

Untyped:

untyped __lua__("_G.print('__lua__')");
untyped __call__(print, 1, 2, 3);
untyped __tail__(os, clock, 1, 2, "hi");
untyped __global__(print,'__lua__', 2);
untyped __hash__(z);
_G.print('__lua__');
print(1, 2, 3);
os:clock(1, 2, "hi");
_G.print("__lua__", 2);
#z

Meta`s:

@:require("hello", "world")
class Main { ... }
require "hello" -- added to top of your lua file
require "world"

External Classes Usage

Using external Lua tables fairly simple, but requires special meta @dotpath. Here is example for Love2D:

class Main {
 static function main() {
  LoveGraphics.setColor(0, 0, 0, 0);
 }
}

@:native("love.graphics") @dotpath
extern class LoveGraphics {
 static public function setColor(r:Float, g:Float, b:Float, a:Float):Void;
}

Outputs:

function Main_Main.main(  )
	love.graphics.setColor(0, 0, 0, 0)
end

External Classes Creation

It is very easy to create external classes for LuaXe. Create extern class definition:

// placed inside root package TestExtern
extern class Extern {
	function new(x:Int);
	static function test():String;
	static var hi:String;
	function selfcall():String;
	var X:Int;
}

Create implementation of class in Lua that is fully compatible with OOP-style LuaXe API:

local Extern = {}
TestExtern_Extern = Extern -- setting proper namespace 
-- Another namespace? Use "_": namespace.TestExtern.Extern -> namespace_TestExtern_Extern
Extern.__index = Extern -- need for metatable
Extern.hi = "Hello!" -- static var

function Extern.new(x) -- constructor
	local self = { X = x } -- "X" is a class field
	setmetatable(self, Extern)
	return self
end

function Extern:selfcall() return self.X end -- public function
function Extern.test() return "static test" end -- static function

Everything works just as usual:

// static:
trace(Extern.test());
trace(Extern.hi);
// fields:
var inst = new Extern(5);
trace(inst.selfcall());
trace(inst.X);

Links

https://github.com/frabbit/hx2python https://bitbucket.org/AndrewVernon/hx2dart http://api.haxe.org/

About

Lua target for Haxe language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published