diff --git a/src/bin/HelloWorld.hx b/src/bin/HelloWorld.hx index 6661858..6e5ef93 100644 --- a/src/bin/HelloWorld.hx +++ b/src/bin/HelloWorld.hx @@ -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); }); diff --git a/src/bin/HelloWorldService.hx b/src/bin/HelloWorldService.hx index 238ebaa..e037952 100644 --- a/src/bin/HelloWorldService.hx +++ b/src/bin/HelloWorldService.hx @@ -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; diff --git a/src/macros/Helper.hx b/src/macros/Helper.hx index 80c1a15..c7df933 100644 --- a/src/macros/Helper.hx +++ b/src/macros/Helper.hx @@ -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 { - if (t == null) return null; - return TypeTools.toComplexType(Context.resolveType(t,pos)); - } + public static function resolveType(t:ComplexType, pos:Position):Null { + 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 diff --git a/src/macros/rpc/RPC.hx b/src/macros/rpc/RPC.hx index 3242ef7..6fa9745 100644 --- a/src/macros/rpc/RPC.hx +++ b/src/macros/rpc/RPC.hx @@ -31,10 +31,10 @@ 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); } - + c.fields.push({ name: field.name, pos: field.pos, @@ -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}));