Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hosts to call into scripts #66

Open
velipso opened this issue Nov 20, 2024 · 0 comments
Open

Allow hosts to call into scripts #66

velipso opened this issue Nov 20, 2024 · 0 comments
Labels

Comments

@velipso
Copy link
Owner

velipso commented Nov 20, 2024

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.

@velipso velipso added the idea label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant