Plugin Examples
These examples demonstrate Scriptling plugins loaded from executable files with
--plugin-dir.
Go Plugin
hello-go demonstrates all registration styles in one plugin:
go build -o /tmp/scriptling-plugins/hello-go ./examples/plugins/hello-go
scriptling --plugin-dir /tmp/scriptling-plugins -c 'import plugin.hello; print(plugin.hello.greet("Ada"))'
It exposes:
plugin.hello.greet(name) — function via RegisterFunc
plugin.hello.label(name) — function via RegisterFunc
plugin.hello.Config(name).get(key) — class via RegisterClass
plugin.hello.Counter(start).inc(amount) — class via RegisterClass
plugin.hello.default_name — constant
Mixed Wrapper Plugin
mixed-wrapper shows generated proxies and custom Scriptling wrappers in the
same plugin:
go build -o /tmp/scriptling-plugins/wrap ./examples/plugins/mixed-wrapper
scriptling --plugin-dir /tmp/scriptling-plugins -c 'import plugin.wrap; print(plugin.wrap.greet("Ada"))'
It exposes:
plugin.wrap.generated(name) — auto-generated function proxy
plugin.wrap.greet(name) — custom function wrapper
plugin.wrap.Settings(name) — auto-generated class proxy
plugin.wrap.Config(name) — custom class wrapper with a defaulted get
Bash Plugin
bash/hello-plugin.sh implements the JSON-RPC protocol directly. It requires
jq and is meant as a small protocol example rather than a production plugin.
mkdir -p /tmp/scriptling-plugins
cp examples/plugins/bash/hello-plugin.sh /tmp/scriptling-plugins/hello-plugin
chmod +x /tmp/scriptling-plugins/hello-plugin
scriptling --plugin-dir /tmp/scriptling-plugins -c 'import plugin.hello; print(plugin.hello.greet("Ada"))'
Callback Plugin
callback demonstrates passing a Scriptling function into a Go plugin. The
plugin invokes it several times while the outer function is still running.
go build -o /tmp/scriptling-plugins/callback ./examples/plugins/callback
cat > /tmp/callback-demo.sl <<'EOF'
import plugin.callback
events = []
def on_event(e):
events.append(e)
print(plugin.callback.stream(on_event))
print(events)
EOF
scriptling --plugin-dir /tmp/scriptling-plugins /tmp/callback-demo.sl
Property Plugin
properties demonstrates read-only and read/write properties on a plugin class.
go build -o /tmp/scriptling-plugins/properties ./examples/plugins/properties
cat > /tmp/properties-demo.sl <<'EOF'
import plugin.properties
c = plugin.properties.Counter(10)
c.value = c.value + 5
print(c.value)
print(c.label)
EOF
scriptling --plugin-dir /tmp/scriptling-plugins /tmp/properties-demo.sl
Logger Plugin
logger demonstrates writing plugin logs through the host logger.
go build -o /tmp/scriptling-plugins/logger ./examples/plugins/logger
scriptling --plugin-dir /tmp/scriptling-plugins -c 'import plugin.logger; print(plugin.logger.work("Ada", ["demo", 1]))'