Files
sx/examples/96-objc-block-capture.sx
2026-05-18 17:40:10 +03:00

18 lines
481 B
Plaintext

// A capturing closure rides through `xx ... : Block` and the
// captured state survives across the call. The block's sx_env field
// holds the closure's env pointer; the invoke trampoline restores it
// before delegating.
#import "modules/std.sx";
#import "modules/std/objc_block.sx";
main :: () -> s32 {
x : s64 = 42;
y : s64 = 100;
cl := () => { print("x + y = {}\n", x + y); };
b : Block = xx cl;
invoke_fn : (*Block) -> void = xx b.invoke;
invoke_fn(@b);
0;
}