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

     1  package wavm
     2  
     3  // #include <stdlib.h>
     4  // #include "wavm-c.h"
     5  import "C"
     6  import "unsafe"
     7  
     8  type Table C.wasm_table_t
     9  
    10  func NewTable(
    11  	compartment *Compartment,
    12  	tableType *TableType,
    13  	init *Ref,
    14  	debugName string) *Table {
    15  	name := C.CString(debugName)
    16  	defer C.free(unsafe.Pointer(name))
    17  	return (*Table)(C.wasm_table_new((*C.wasm_compartment_t)(compartment), (*C.wasm_tabletype_t)(tableType), (*C.wasm_ref_t)(init), name))
    18  }
    19  
    20  func (t *Table) Close() error {
    21  	t.Delete()
    22  	return nil
    23  }
    24  
    25  func (t *Table) Delete() {
    26  	C.wasm_table_delete((*C.wasm_table_t)(t))
    27  }
    28  
    29  func (t *Table) Type() *TableType {
    30  	return (*TableType)(C.wasm_table_type((*C.wasm_table_t)(t)))
    31  }
    32  
    33  func (t *Table) Get(index int) *Ref {
    34  	return (*Ref)(C.wasm_table_get((*C.wasm_table_t)(t), (C.wasm_table_size_t)(index)))
    35  }
    36  
    37  func (t *Table) Set(index int, value *Ref) bool {
    38  	return bool(C.wasm_table_set((*C.wasm_table_t)(t), (C.wasm_table_size_t)(index), (*C.wasm_ref_t)(value)))
    39  }
    40  
    41  func (t *Table) Size() int {
    42  	return int(C.wasm_table_size((*C.wasm_table_t)(t)))
    43  }
    44  
    45  func (t *Table) Grow(delta int, init *Ref) (bool, int) {
    46  	var previousSize C.wasm_table_size_t
    47  	ok := bool(C.wasm_table_grow((*C.wasm_table_t)(t), (C.wasm_table_size_t)(delta), (*C.wasm_ref_t)(init), &previousSize))
    48  	return ok, int(previousSize)
    49  }