github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/global.go (about) 1 package wavm 2 3 // #include <stdlib.h> 4 // #include "wavm-c.h" 5 import "C" 6 import "unsafe" 7 8 type Global C.wasm_global_t 9 10 func NewGlobal( 11 compartment *Compartment, 12 globalType *GlobalType, 13 val *Val, 14 debugName string, 15 ) *C.wasm_global_t { 16 var name *C.char 17 if debugName == "" { 18 name = EMPTY 19 } else { 20 name = C.CString(debugName) 21 defer C.free(unsafe.Pointer(name)) 22 } 23 return C.wasm_global_new((*C.wasm_compartment_t)(compartment), (*C.wasm_globaltype_t)(globalType), (*C.wasm_val_t)(val), name) 24 } 25 26 func (g *Global) Close() error { 27 g.Delete() 28 return nil 29 } 30 31 func (g *Global) Delete() { 32 C.wasm_global_delete((*C.wasm_global_t)(g)) 33 } 34 35 func (g *Global) Type() *GlobalType { 36 return (*GlobalType)(C.wasm_global_type((*C.wasm_global_t)(g))) 37 } 38 39 func (g *Global) Get(store *Store) *Val { 40 var out C.wasm_val_t // 41 C.wasm_global_get((*C.wasm_store_t)(store), (*C.wasm_global_t)(g), &out) 42 return (*Val)(&out) 43 } 44 45 //func WASMGlobalSet(global *Global, val *Val) { 46 // C.wasm_global_set((*C.wasm_global_t)(global), (*C.wasm_val_t)(val)) 47 //} 48 // 49 //func (g *Global) Set(val *Val) { 50 // WASMGlobalSet(g, val) 51 //}