HaxeFoundation / HaxeFoundation/haxe

haxe.Rest and haxe.PosInfos as last arguments

Open
#10,808 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Hej,

It's not something vital, I just wanted do make a little helper function `traceif` where last argument is the condition that makes trace occurs, so first I did it simply with macros :
```haxe
import haxe.macro.Expr;
class Log {
public macro static function traceif( exprs : Array ){
var cond = exprs.pop();
return macro @:pos( exprs[ 0 ].pos ) if( $cond ) trace( $a{ exprs } );
}
}
```
But can't use this wonderful and awesome function in macros (macro-in-macro)
So I tried without macro, using `haxe.Rest` and `haxe.PosInfos` but we can't have both as last argument :
```haxe
class Log {
public static function traceif(...rest:Dynamic /*, ?pos : haxe.PosInfos*/) {
var args = rest.toArray();
var cond = args.pop();
if (cond) {
haxe.Log.trace(args.join(",") /*, pos*/);
}
}
}
```
One day, could we maybe do a special case for that please ?

Thanks for reading,

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.