ソースを参照

Lua : Basic table abstract

I created a lua table abstract for Haxe.  Tables will work basically the
same way as anonymous (dynamic) objects.  However, the abstract will use
haxe's 0-based indexing instead of lua's 1-based version for int keys.
Justin Donaldson 10 年 前
コミット
c66d25a074
1 ファイル変更23 行追加0 行削除
  1. 23 0
      std/lua/Table.hx

+ 23 - 0
std/lua/Table.hx

@@ -0,0 +1,23 @@
+package lua;
+/**
+  Abstract implementation of a standard Lua table.  Automatically converts to the
+  1-based indexing that Lua uses as default for int-keyed tables.
+ **/
+abstract Table<A,B>({}) {
+	inline public function new() this = {};
+	@:arrayAccess inline function getIntV(k:Int) : B{
+		return untyped this[k+1];
+	}
+	@:arrayAccess inline function setIntV(k:Int, v:B){
+		untyped this[k+1] = v;
+		return v;
+	}
+	@:arrayAccess inline function getV(k:A) : B{
+		return untyped this[k];
+	}
+	@:arrayAccess inline function setV(k:A, v:B){
+		untyped this[k] = v;
+		return v;
+	}
+}
+