github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/foreign.go (about) 1 package wavm 2 3 // #include <stdlib.h> 4 // #include "wavm-c.h" 5 import "C" 6 import "unsafe" 7 8 type Foreign C.wasm_foreign_t 9 10 func NewForeign(compartment *Compartment, debugName string) *Foreign { 11 var name *C.char 12 if debugName == "" { 13 name = EMPTY 14 } else { 15 name = C.CString(debugName) 16 defer C.free(unsafe.Pointer(name)) 17 } 18 return (*Foreign)(C.wasm_foreign_new((*C.wasm_compartment_t)(compartment), name)) 19 } 20 21 func (f *Foreign) Close() error { 22 f.Delete() 23 return nil 24 } 25 26 func (f *Foreign) Delete() { 27 C.wasm_foreign_delete((*C.wasm_foreign_t)(f)) 28 }