我有一个枚举器类型:
enum PlayerProps {
Attempts;
Gold;
Diamonds;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能遍历所有枚举值?就像是:
var props = new Map<PlayerProps, Int>();
for (prop in PlayerProps)
props[prop] = 0;
Run Code Online (Sandbox Code Playgroud) 在ActionScript中,我可以...
在函数声明中使用它,因此它接受任意参数:
function foo(... args):void { trace(args.length); }
Run Code Online (Sandbox Code Playgroud)
然后我可以调用传递数组的函数:
foo.apply(this, argsArray);
Run Code Online (Sandbox Code Playgroud)
我想用未知类型和计数的参数调用该函数.在Haxe这可能吗?
我想使用模型的类或接口作为键将模型的实例存储在公共提供程序中,然后通过类引用将其弹出。我写了一些代码:
class Provider {
public function new() { }
public function set<T:Any>(instance:T, ?type:Class<T>) {
if (type == null)
type = Type.getClass(instance);
if (type != null && instance != null)
map.set(type, instance);
}
public function get<T:Any>(type:Class<T>):Null<T> {
return cast map.get(type);
}
var map = new Map<Class<Any>, Any>();
}
Run Code Online (Sandbox Code Playgroud)
... ala,甚至无法编译。可能我必须使用合格的类名作为键而不是类/接口引用?但我想保持整洁的get函数设计,该函数将类型作为参数并返回仅采用类型的对象,而无需进行其他类型转换。
我是否有可能或应该更改此问题的方法?
我有一个通用的接口来描述对输出流的访问,如下所示:
interface IOutput {
function writeInteger(aValue:Int):Void;
}
Run Code Online (Sandbox Code Playgroud)
我有一个基于标准haxe.io.BytesOutput
类的接口的抽象实现:
abstract COutput(BytesOutput) from BytesOutput {
public inline function new(aData:BytesOutput) {
this = aData;
}
public inline function writeInteger(aValue:Int):Void {
this.writeInt32(aValue);
}
}
Run Code Online (Sandbox Code Playgroud)
尽管此抽象确实实现了上面描述的接口,但没有直接引用接口,当我尝试像这样使用它时:
class Main {
public static function out(aOutput:IOutput) {
aOutput.writeInteger(0);
}
public static function main() {
var output:COutput = new BytesOutput();
out(output); // type error
}
}
Run Code Online (Sandbox Code Playgroud)
编译器将引发错误:COutput should be IOutput
。我只能通过使用包装BytesOutput
和实现的通用类来解决此问题IOutput
。
我的问题是如何向Haxe编译器表明抽象实现了该接口。
我想创建应该能够监听标准输入并流式传输到标准输出的实用程序.此外,我想将命令行参数传递给实用程序.是否可以使用haxe/cpp环境?
什么"跟踪()"究竟做什么?我可以用一些ascii控制字符覆盖它的自动CR/LF来打印假数据活动量表吗?