formatting
This commit is contained in:
parent
0fc2d4d397
commit
016063e3be
@ -14,7 +14,7 @@ class HelloWorld implements Process {
|
||||
|
||||
var c = new HelloWorldServiceRPC(0);
|
||||
|
||||
c.getNumber(2,3).handle((res) -> {
|
||||
c.getNumber(2, 3).handle((res) -> {
|
||||
Log.debug("Got number: " + res);
|
||||
});
|
||||
|
||||
|
@ -20,7 +20,7 @@ class HelloWorldService implements Process {
|
||||
}
|
||||
|
||||
@rpc
|
||||
public function getNumber(arg1: Int, arg2: Int):Int {
|
||||
public function getNumber(arg1:Int, arg2:Int):Int {
|
||||
Log.debug(arg1);
|
||||
Log.debug(arg2);
|
||||
return 42;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package macros;
|
||||
|
||||
#if macro
|
||||
|
||||
import haxe.macro.TypeTools;
|
||||
import haxe.macro.Expr.Position;
|
||||
import haxe.macro.Expr.ComplexType;
|
||||
@ -9,38 +8,36 @@ import haxe.macro.Context;
|
||||
import haxe.macro.Type;
|
||||
|
||||
class Helper {
|
||||
public static function resolveType(t: ComplexType,pos: Position): Null<ComplexType> {
|
||||
if (t == null) return null;
|
||||
return TypeTools.toComplexType(Context.resolveType(t,pos));
|
||||
}
|
||||
public static function resolveType(t:ComplexType, pos:Position):Null<ComplexType> {
|
||||
if (t == null)
|
||||
return null;
|
||||
return TypeTools.toComplexType(Context.resolveType(t, pos));
|
||||
}
|
||||
|
||||
public static function newPromise(t: ComplexType): ComplexType {
|
||||
if (Helper.isVoidC(t)){
|
||||
return TPath({name: "Promise", params: [TPType(TPath({name:"Noise",pack: ["tink", "core"]}))], pack: ["tink", "core"]});
|
||||
}
|
||||
public static function newPromise(t:ComplexType):ComplexType {
|
||||
if (Helper.isVoidC(t)) {
|
||||
return TPath({name: "Promise", params: [TPType(TPath({name: "Noise", pack: ["tink", "core"]}))], pack: ["tink", "core"]});
|
||||
}
|
||||
|
||||
return TPath({name: "Promise", params: [TPType(t)], pack: ["tink", "core"]});
|
||||
}
|
||||
return TPath({name: "Promise", params: [TPType(t)], pack: ["tink", "core"]});
|
||||
}
|
||||
|
||||
public static function isVoidC(t:ComplexType):Bool {
|
||||
switch (t) {
|
||||
case TPath(p):
|
||||
return (p.name == "Void");
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isVoidC(t: ComplexType): Bool {
|
||||
switch (t){
|
||||
case TPath(p):
|
||||
return (p.name == "Void");
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isVoid(t: Type) {
|
||||
switch (t){
|
||||
case TAbstract(t, _):
|
||||
return (t.get().name == "Void");
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isVoid(t:Type) {
|
||||
switch (t) {
|
||||
case TAbstract(t, _):
|
||||
return (t.get().name == "Void");
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
||||
|
@ -31,7 +31,7 @@ class RPC {
|
||||
var convertedArgs = [];
|
||||
|
||||
for (a in f.args) {
|
||||
a.type = Helper.resolveType(a.type,field.pos);
|
||||
a.type = Helper.resolveType(a.type, field.pos);
|
||||
convertedArgs.push(a);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class RPC {
|
||||
expr: macro {
|
||||
return cast this._performRequest($v{field.name}, $a{argsExprs});
|
||||
},
|
||||
ret: Helper.newPromise(Helper.resolveType(f.ret,field.pos)),
|
||||
ret: Helper.newPromise(Helper.resolveType(f.ret, field.pos)),
|
||||
}),
|
||||
access: [APublic],
|
||||
doc: null,
|
||||
@ -76,18 +76,18 @@ class RPC {
|
||||
|
||||
var exprsType = field.expr().t;
|
||||
|
||||
switch (exprsType){
|
||||
switch (exprsType) {
|
||||
case TFun(args, ret):
|
||||
var callArgs = [for (k => v in args) macro pack.data.args[$v{k}]];
|
||||
|
||||
if (Helper.isVoid(ret)){
|
||||
if (Helper.isVoid(ret)) {
|
||||
exprs.push(macro {
|
||||
if (pack.data.func == $v{funName}) {
|
||||
this.$funName($a{callArgs});
|
||||
pack.respond(null);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
} else {
|
||||
exprs.push(macro {
|
||||
if (pack.data.func == $v{funName}) {
|
||||
pack.respond(this.$funName($a{callArgs}));
|
||||
|
Loading…
Reference in New Issue
Block a user