package haxe; import lua.Lua.select; import lua.Table; import lua.PairTools.copy; import lua.TableTools.maxn; import lua.TableTools.pack; import lua.TableTools.unpack; import haxe.iterators.RestIterator; import haxe.iterators.RestKeyValueIterator; private typedef NativeRest = Table; @:coreApi abstract Rest(NativeRest) { public var length(get, never):Int; inline function get_length():Int return maxn(this); @:from static public function of(array:Array):Rest { return new Rest(Table.fromArray(array)); } inline function new(table:Table):Void this = table; @:arrayAccess inline function get(index:Int):T return this[index + 1]; @:to public function toArray():Array { return Table.toArray(this); } public inline function iterator():RestIterator return new RestIterator(this); public inline function keyValueIterator():RestKeyValueIterator return new RestKeyValueIterator(this); public inline function append(item:T):Rest { var result = copy(this); Table.insert(result, item); return new Rest(result); } public inline function prepend(item:T):Rest { var result = copy(this); Table.insert(result, 1, item); return new Rest(result); } public function toString():String { return toArray().toString(); } }