Zig: Cross-mod: bus, services and lanes¶
Functions¶
busSubscribe¶
| Zig | |
|---|---|
Calls handler(topic, payload) for every message on topic, from mods of any language, on the publisher's thread. It returns a veto: true refuses a vetoable publish and false has no opinion, and a plain publish ignores it. Namespace topics, as "plot:enter".
- Parameters:
- topic :
[]const u8 - handler :
comptime fn ([]const u8, []const u8) bool
- topic :
- Return type:
Error!Subscription - Slots:
bus_subscribe
busPublish¶
| Zig | |
|---|---|
Sends payload to every subscriber of topic and returns how many ran; 0 means nobody is listening, which is not an error.
- Parameters:
- topic :
[]const u8 - payload :
[]const u8
- topic :
- Return type:
Error!u32 - Slots:
bus_publish
busPublishVetoable¶
| Zig | |
|---|---|
Sends payload and collects the subscribers' vetoes.
- Parameters:
- topic :
[]const u8 - payload :
[]const u8
- topic :
- Return type:
Error!Vetoable - Slots:
bus_publish_vetoable
busSubscriberCount¶
| Zig | |
|---|---|
How many subscribers topic has now.
- Parameters:
- topic :
[]const u8
- topic :
- Return type:
Error!u32 - Slots:
bus_subscriber_count
registerService¶
| Zig | |
|---|---|
Answers calls to name from mods of any language, and from native plugins through the bridge. provider(request, reply) runs on the caller's thread, also while this mod is disabled but loaded, since consumers resolve services in their own on_load.
- Parameters:
- name :
[]const u8 - provider :
comptime fn ([]const u8, *const Reply) bool
- name :
- Return type:
Error!ServiceRegistration - Slots:
service_register
callService¶
| Zig | |
|---|---|
Calls another mod's service, whatever language it is written in.
- Parameters:
- allocator :
std.mem.Allocator - name :
[]const u8 - request :
[]const u8
- allocator :
- Return type:
Error!CallOutcome - Slots:
service_call
listServicesJson¶
| Zig | |
|---|---|
Every registered service as the host's JSON array of {"name","mod"}, owned by the caller.
- Parameters:
- allocator :
std.mem.Allocator
- allocator :
- Return type:
Error![]u8 - Slots:
service_list
serviceCaller¶
| Zig | |
|---|---|
Inside a provider, the mod whose call is running; null outside one and for a caller with no mod, such as a native plugin through the bridge.
- Parameters:
- allocator :
std.mem.Allocator
- allocator :
- Return type:
Error!?[]u8 - Slots:
service_caller
Subscription¶
One bus subscription, kept to end it.
Subscription.unsubscribe¶
| Zig | |
|---|---|
Ends the subscription; calling it twice is harmless.
- Return type:
Error!void - Slots:
bus_unsubscribe
Reply¶
The way a service provider answers: send the reply and return true, or send the reason and return false, which the caller receives unchanged as the provider's message.
Reply.send¶
| Zig | |
|---|---|
- Parameters:
- text :
[]const u8
- text :
- Return type:
void
ServiceRegistration¶
One service this mod provides, kept to withdraw it.
ServiceRegistration.unregister¶
| Zig | |
|---|---|
Withdraws the service; calling it twice is harmless.
- Return type:
Error!void - Slots:
service_unregister
Vetoable¶
The result of one vetoable publish. There is no short circuit: after a veto the later subscribers still receive the message.
CallCode¶
How a service call ended, matching the PIER_SERVICE_* results.
CallOutcome¶
One service call's outcome. body is the reply for ok and the provider's message for provider_error, owned by the caller.