github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/compartment.go (about)

     1  package wavm
     2  
     3  // #include <stdlib.h>
     4  // #include "wavm-c.h"
     5  import "C"
     6  import "unsafe"
     7  
     8  type Compartment C.wasm_compartment_t
     9  
    10  func NewCompartment(engine *Engine, debugName string) *Compartment {
    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 (*Compartment)(C.wasm_compartment_new((*C.wasm_engine_t)(engine), name))
    19  }
    20  
    21  func (c *Compartment) Close() error {
    22  	c.Delete()
    23  	return nil
    24  }
    25  
    26  func (c *Compartment) Delete() {
    27  	C.wasm_compartment_delete((*C.wasm_compartment_t)(c))
    28  }
    29  
    30  func (c *Compartment) Clone() *Compartment {
    31  	return (*Compartment)(C.wasm_compartment_clone((*C.wasm_compartment_t)(c)))
    32  }
    33  
    34  func (c *Compartment) Contains(ref *Ref) bool {
    35  	return bool(C.wasm_compartment_contains((*C.wasm_compartment_t)(c), (*C.wasm_ref_t)(ref)))
    36  }
    37  
    38  func (c *Compartment) NewStore(debugName string) *Store {
    39  	return NewStore(c, debugName)
    40  }