Table.hx 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. package lua;
  2. /**
  3. This library provides generic functions for table manipulation.
  4. **/
  5. // TODO: use an abstract here?
  6. @:native("_G.table")
  7. extern class Table<A,B> implements ArrayAccess<B> implements Dynamic<B> {
  8. public inline static function create<A,B>(?arr:Array<B>, ?hsh:Dynamic<B>) : Table<A,B> {
  9. return untyped __lua_table__(arr,hsh);
  10. }
  11. @:overload(function<A,B>(table:Table<A,B>):Void{})
  12. public static function concat<A,B>(table:Table<A,B>, ?sep:String) : String;
  13. public static function foreach<A,B>(table:Table<A,B>, f:A->B->Void) : Void;
  14. public static function foreachi<A,B>(table:Table<A,B>, f:A->B->Int->Void) : Void;
  15. public static function sort<A,B>(table:Table<A,B>, ?order : A->A->Bool) : Void;
  16. @:overload(function<B>(table:Table<Int,B>, value:B):Void{})
  17. public static function insert<B>(table:Table<Int,B>, pos:Int, value:B) : Void;
  18. @:overload(function<B>(table:Table<Int,B>):Void{})
  19. public static function remove<B>(table:Table<Int,B>, ?pos:Int) : Void;
  20. #if (lua_ver >= 5.2)
  21. public static function pack<T>(args:haxe.extern.Rest<T>) : Table<Int,T>;
  22. public static function unpack<Int,V>(args:lua.Table<Int,V>, ?min : Int, ?max : Int) : Dynamic;
  23. #end
  24. }
  25. typedef AnyTable = Table<Dynamic, Dynamic>;