Table.hx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. @:analyzer(no_fusion)
  9. public inline static function create<A,B>(?arr:Array<B>, ?hsh:Dynamic) : Table<A,B> {
  10. return untyped __lua_table__(arr,hsh);
  11. }
  12. @:overload(function<A,B>(table:Table<A,B>):Void{})
  13. public static function concat<A,B>(table:Table<A,B>, ?sep:String) : String;
  14. public static function foreach<A,B>(table:Table<A,B>, f:A->B->Void) : Void;
  15. public static function foreachi<A,B>(table:Table<A,B>, f:A->B->Int->Void) : Void;
  16. public static function sort<A,B>(table:Table<A,B>, ?order : A->A->Bool) : Void;
  17. @:overload(function<B>(table:Table<Int,B>, value:B):Void{})
  18. public static function insert<B>(table:Table<Int,B>, pos:Int, value:B) : Void;
  19. @:overload(function<B>(table:Table<Int,B>):Void{})
  20. public static function remove<B>(table:Table<Int,B>, ?pos:Int) : Void;
  21. #if (lua_ver >= 5.2)
  22. public static function pack<T>(args:haxe.extern.Rest<T>) : Table<Int,T>;
  23. public static function unpack<Int,V>(args:lua.Table<Int,V>, ?min : Int, ?max : Int) : Dynamic;
  24. #end
  25. }
  26. typedef AnyTable = Table<Dynamic, Dynamic>;