Files
nim/examples/calculator_client.nim
zeekay 68037f9ca4 Rebrand Cap'n Proto Nim port to ZAP
Rename the capnp/ module set to zap/ and the capnpc compiler to zapc;
rename all .capnp schemas and fixtures to .zap; update every import,
include guard (isInZap), generated-code emission, exception type
(ZapFormatError), and the macro-generated zapUnpackStructImpl/
zapPackStructImpl identifiers to the ZAP brand. Zero capnp/Cap'n Proto
references remain in source or build files; upstream MIT attribution
(Sandstorm, Michał Zieliński) is preserved.

Raise the nimble nim floor from the fictional 0.12.0 to the locked,
verified 0.15.2 (matches nimenv.cfg/build.sh; code carries fixes through
Nim 0.18). Rewrite TODO.md as honest, source-anchored known-limitations
(two-word intersegment pointers, nested/named-union codegen, RPC
interface inheritance) instead of a bare wishlist.
2026-06-19 23:42:02 -07:00

46 lines
1.7 KiB
Nim

import reactor, zap, caprpc, calculator_schema
proc main() {.async.} =
echo "connecting"
let sys = newTwoPartyClient(await connectTcp("127.0.0.1:7890")) # localhost:6789
echo "ok"
discard createFromCap(Calculator_Value, CapServer(Interface()))
discard createFromCap(Calculator, CapServer(Interface()))
let calculator = await sys.bootstrap().castAs(Calculator)
let addOp = await calculator.getOperator(Calculator_Operator.add)
let myExpr = Calculator_Expression(kind: Calculator_ExpressionKind.call,
function: addOp,
params: @[
Calculator_Expression(kind: Calculator_ExpressionKind.literal, literal: 1),
Calculator_Expression(kind: Calculator_ExpressionKind.literal, literal: 2)])
let ret = await calculator.evaluate(myExpr)
let retb = await ret.read()
echo(retb)
let myFunc = inlineCap(Calculator_Function, Calculator_FunctionInlineImpl(
call: proc(params: seq[float64]): Future[float64] =
echo "called!"
return now(just(666.0 + params[0]))
))
let expr2 = Calculator_Expression(kind: Calculator_ExpressionKind.call,
function: myFunc,
params: @[
Calculator_Expression(kind: Calculator_ExpressionKind.literal, literal: 1)])
let ret1 = await calculator.evaluate(expr2)
let ret1b = await ret1.read()
echo(ret1b)
discard (await calculator.getOperator(Calculator_Operator.subtract))
echo "collecting garbage..."
GC_fullCollect()
when isMainModule:
main().runMain()
GC_fullCollect()