diff --git a/src/bin/HelloWorld.hx b/src/bin/HelloWorld.hx index b097af1..6661858 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().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 3a827ab..238ebaa 100644 --- a/src/bin/HelloWorldService.hx +++ b/src/bin/HelloWorldService.hx @@ -1,5 +1,6 @@ package bin; +import kernel.log.Log; import macros.rpc.RPC; import kernel.ps.ProcessHandle; import kernel.ps.Process; @@ -19,7 +20,9 @@ class HelloWorldService implements Process { } @rpc - public function getNumber():Int { + public function getNumber(arg1: Int, arg2: Int):Int { + Log.debug(arg1); + Log.debug(arg2); return 42; } } diff --git a/src/macros/rpc/RPC.hx b/src/macros/rpc/RPC.hx index 6b2a59c..87bbf64 100644 --- a/src/macros/rpc/RPC.hx +++ b/src/macros/rpc/RPC.hx @@ -25,13 +25,15 @@ class RPC { switch (field.kind) { case FFun(f): + var argsExprs:Array = [for (a in f.args) macro $i{a.name}]; + c.fields.push({ name: field.name, pos: field.pos, kind: FFun({ args: f.args, expr: macro { - return cast this._performRequest($v{field.name}, []); + return cast this._performRequest($v{field.name}, $a{argsExprs}); }, ret: TPath({name: "Promise", params: [TPType(f.ret)], pack: ["tink", "core"]}), }), @@ -64,12 +66,22 @@ class RPC { switch (field.kind) { case FMethod(k): var funName = field.name; - exprs.push(macro { - if (pack.data.func == $v{funName}) { - pack.respond(this.$funName()); - } - }); + var exprsType = field.expr().t; + + switch (exprsType){ + case TFun(args, ret): + var callArgs = [for (k => v in args) macro pack.data.args[$v{k}]]; + + // TODO: transform this to a switch statement + exprs.push(macro { + if (pack.data.func == $v{funName}) { + pack.respond(this.$funName($a{callArgs})); + } + }); + default: + Context.error("Only functions can be used for rpc", field.pos); + } default: Context.error("Only functions can be used for rpc", field.pos); } diff --git a/src/macros/rpc/RPCBase.hx b/src/macros/rpc/RPCBase.hx index f1d63c5..86aff12 100644 --- a/src/macros/rpc/RPCBase.hx +++ b/src/macros/rpc/RPCBase.hx @@ -18,7 +18,7 @@ abstract class RPCBase { private function _performRequest(func:String, args:Array):Promise { return Net.sendAndAwait(id, this._proto, { func: func, - // args: args + args: args }).map((res) -> { switch (res) { case Success(pack):