Go: Cross-mod: bus, services and lanes¶
Functions¶
BusSubscribe¶
| Go | |
|---|---|
BusSubscribe calls fn for every message published on topic, on the publisher's thread, whichever language the publisher is written in. fn returns a veto: true refuses a vetoable publish and false has no opinion, and a plain publish ignores it. A subscriber can only refuse, never overturn another's refusal. Namespace topics, as "plot:enter".
- Parameters:
- topic :
string - fn :
func(topic, payload string) (veto bool)
- topic :
- Return type:
(*Subscription, error) - Slots:
bus_subscribe
BusPublish¶
| Go | |
|---|---|
BusPublish sends payload to every subscriber of topic and returns how many ran; 0 is a normal answer, meaning nobody is listening. The payload is opaque to the host, so the two mods agree on its format, JSON or SNBT, out of band.
- Parameters:
- topic :
string - payload :
string
- topic :
- Return type:
(uint32, error) - Slots:
bus_publish
BusPublishVetoable¶
| Go | |
|---|---|
BusPublishVetoable sends payload and collects the subscribers' vetoes.
- Parameters:
- topic :
string - payload :
string
- topic :
- Return type:
(Vetoable, error) - Slots:
bus_publish_vetoable
BusSubscriberCount¶
| Go | |
|---|---|
BusSubscriberCount is how many subscribers topic has now.
- Parameters:
- topic :
string
- topic :
- Return type:
(uint32, error) - Slots:
bus_subscriber_count
RegisterService¶
| Go | |
|---|---|
RegisterService answers calls to name from mods of any language, and from native plugins through the bridge. fn receives the request and returns the reply, or an error whose message reaches the caller unchanged. It runs on the caller's thread, and also while this mod is disabled but loaded, since consumers resolve services in their own on_load.
- Parameters:
- name :
string - fn :
func(request string) (string, error)
- name :
- Return type:
(*ServiceRegistration, error) - Slots:
service_register
CallService¶
| Go | |
|---|---|
CallService calls another mod's service, whatever language it is written in, and returns its reply or a *CallError.
- Parameters:
- name :
string - request :
string
- name :
- Return type:
(string, error) - Slots:
service_call
CallServiceOptional¶
| Go | |
|---|---|
CallServiceOptional is CallService with nobody providing the name as found false, for an optional integration that works without the other mod.
- Parameters:
- name :
string - request :
string
- name :
- Return type:
(reply string, found bool, err error) - Slots:
service_call
ListServices¶
| Go | |
|---|---|
ListServices lists every registered service.
- Return type:
([]ServiceInfo, error) - Slots:
service_list
ServiceExists¶
| Go | |
|---|---|
ServiceExists reports whether some mod provides name now.
- Parameters:
- name :
string
- name :
- Return type:
bool - Slots:
service_list
ServiceCaller¶
| Go | |
|---|---|
ServiceCaller is the mod whose call is running, asked inside a provider. It is false outside a provider and for a caller with no mod, such as a native plugin through the bridge: a provider then knows it cannot attribute the request.
- Return type:
(string, bool) - Slots:
service_caller
Lanes¶
| Go | |
|---|---|
Lanes lists every published lane. It passes no pointer at all, so it suits looking at what exists first.
- Return type:
([]LaneInfo, error) - Slots:
lane_list
PublishLane¶
| Go | |
|---|---|
PublishLane publishes a lane, exclusively under name. fingerprint is the value of the contract and must not be 0, which means anyone may connect and which the host refuses. table is the provider's table of function pointers and data the pointer each of them receives; both must point into C memory, since the consumer reaches them from outside Go. retain and release, when not nil, are C functions that count leases on data. The lane is withdrawn automatically at unload.
- Parameters:
- name :
string - fingerprint :
uint64 - data :
unsafe.Pointer - table :
unsafe.Pointer - retain :
unsafe.Pointer - release :
unsafe.Pointer
- name :
- Return type:
(*LanePublication, error) - Slots:
lane_publish
AcquireLane¶
| Go | |
|---|---|
AcquireLane acquires a lane. fingerprint must be the value the consumer computed itself from the contract; 0 is not valid and always fails. A missing lane is a *LaneNotFoundError and a contract that differs is a *LaneFingerprintError.
- Parameters:
- name :
string - fingerprint :
uint64
- name :
- Return type:
(*LaneLease, error) - Slots:
lane_acquire
Subscription¶
Subscription is one bus subscription, kept to end it.
Subscription.ID¶
| Go | |
|---|---|
ID is the host's id of the subscription.
- Return type:
uint64
Subscription.Topic¶
| Go | |
|---|---|
Topic is the topic subscribed to.
- Return type:
string
Subscription.Unsubscribe¶
| Go | |
|---|---|
Unsubscribe ends the subscription. Calling it twice is harmless.
- Return type:
error - Slots:
bus_unsubscribe
ServiceRegistration¶
ServiceRegistration is one service this mod provides, kept to withdraw it.
ServiceRegistration.ID¶
| Go | |
|---|---|
ID is the host's id of the registration.
- Return type:
uint64
ServiceRegistration.Name¶
| Go | |
|---|---|
Name is the service name.
- Return type:
string
ServiceRegistration.Unregister¶
| Go | |
|---|---|
Unregister withdraws the service. Calling it twice is harmless.
- Return type:
error - Slots:
service_unregister
LaneLease¶
LaneLease is a lease on a published lane, kept to return it.
LaneLease.IsAlive¶
| Go | |
|---|---|
IsAlive reports whether the provider is still there.
- Return type:
bool
LaneLease.Enter¶
| Go | |
|---|---|
Enter enters the provider for one call and returns the provider's table and data pointers. ok is false when the provider is gone. Call leave when the call is over, so the provider cannot unload underneath a call that is running.
- Return type:
(table, data unsafe.Pointer, leave func(), ok bool)
LaneLease.Release¶
| Go | |
|---|---|
Release returns the lease. It reports false when the provider is already gone, since the loader has released it by then and releasing again would be a double free.
- Return type:
(bool, error) - Slots:
lane_release
CallError¶
CallError is why a service call failed: nobody provides the name, the provider said no and Message is what it said, the host refused the call (a bad name, a call to itself or a cycle), or the host has no service capability.
CallError.Error¶
| Go | |
|---|---|
- Return type:
string
LanePublication¶
LanePublication is one published lane.
LanePublication.Withdraw¶
| Go | |
|---|---|
Withdraw takes the lane back; calling it twice is harmless. Every outstanding lease is released.
- Return type:
error - Slots:
lane_unpublish
LaneNotFoundError¶
LaneNotFoundError means no lane by that name is published.
LaneNotFoundError.Error¶
| Go | |
|---|---|
- Return type:
string
LaneFingerprintError¶
LaneFingerprintError means the provider's contract is not the one the consumer asked for.
LaneFingerprintError.Error¶
| Go | |
|---|---|
- Return type:
string
Vetoable¶
| Go | |
|---|---|
Vetoable is the result of one vetoable publish.
CallErrorKind¶
| Go | |
|---|---|
CallErrorKind says why a service call failed.
| Name | Value | Description |
|---|---|---|
CallNotFound |
1 |
|
CallProvider |
2 |
|
CallRefused |
3 |
|
CallUnavailable |
4 |
ServiceInfo¶
ServiceInfo is one registered service and the mod providing it.
LaneInfo¶
| Go | |
|---|---|
LaneInfo is the registration record of a published lane.