I've been stuck thinking about closures (see #51), and eventually rejected them.
It dawned on me that I could support exporting functions to the host environment without using closures, which would remove the need of an event loop.
Perhaps something like this:
def onMouseMove x, y : "company.product.onMouseMove"
# ...
end
The : "company.product.onMouseMove" means that the command will be exported to the host using that name. The name will be hashed into a 64-bit number, just like native commands.
This means inside the host, you could do something like:
sink_val args = sink_list_newempty(ctx);
sink_list_push(ctx, args, sink_num(123));
sink_list_push(ctx, args, sink_num(456));
sink_val result = sink_ctx_call(ctx, "company.product.onMouseMove", args);
The sink_ctx_call function would hash the string (alternatively could use sink_ctx_callhash so symbols could be stripped), then execute the function, and get the result.
This is effectively the reverse of the native function API, which seems very logical and useful.
I've been stuck thinking about closures (see #51), and eventually rejected them.
It dawned on me that I could support exporting functions to the host environment without using closures, which would remove the need of an event loop.
Perhaps something like this:
The
: "company.product.onMouseMove"means that the command will be exported to the host using that name. The name will be hashed into a 64-bit number, just like native commands.This means inside the host, you could do something like:
The
sink_ctx_callfunction would hash the string (alternatively could usesink_ctx_callhashso symbols could be stripped), then execute the function, and get the result.This is effectively the reverse of the native function API, which seems very logical and useful.