-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create separate closure for each host function (#8)
- Loading branch information
1 parent
8b0bc35
commit 5f8df6d
Showing
6 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/extism/extism-sdk-plugins-host-multiple | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/extism/go-pdk v0.0.0-20230119214914-65bffbeb3e64 // indirect | ||
github.com/valyala/fastjson v1.6.3 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/extism/go-pdk v0.0.0-20230119214914-65bffbeb3e64 h1:IfR1k741q+yQLvv5sLShCkvt3FgKU4wQVJfp7hhb/iY= | ||
github.com/extism/go-pdk v0.0.0-20230119214914-65bffbeb3e64/go.mod h1:1wdiAoG8306g4WK+6laBrS+75089/0V4XRVTllt8b5U= | ||
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc= | ||
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/extism/go-pdk" | ||
) | ||
|
||
//export hostPurpleMessage | ||
func hostPurpleMessage(offset uint64) uint64 | ||
|
||
func purpleMessage(message string) pdk.Memory { | ||
messageMemory := pdk.AllocateString(message) | ||
off := hostPurpleMessage(messageMemory.Offset()) | ||
return pdk.FindMemory(off) | ||
} | ||
|
||
//export hostGreenMessage | ||
func hostGreenMessage(offset uint64) uint64 | ||
|
||
func greenMessage(message string) pdk.Memory { | ||
messageMemory := pdk.AllocateString(message) | ||
off := hostGreenMessage(messageMemory.Offset()) | ||
return pdk.FindMemory(off) | ||
} | ||
|
||
//export say_purple | ||
func say_purple() int32 { | ||
input := pdk.InputString() | ||
output := "👋 Hello from say_purple " + input | ||
|
||
mem := purpleMessage(output) | ||
|
||
pdk.OutputMemory(mem) | ||
return 0 | ||
|
||
} | ||
|
||
//export say_green | ||
func say_green() int32 { | ||
input := pdk.Input() | ||
output := "🫱 Hey from say_green " + string(input) | ||
|
||
mem := greenMessage(output) | ||
|
||
pdk.OutputMemory(mem) | ||
return 0 | ||
|
||
} | ||
func main() {} |
Binary file not shown.