Skip to content

Allow hosts to call into scripts #66

@velipso

Description

@velipso

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions