NewImportType creates a new `ImportType` with the given `module` and `name` and the type provided.
(module, name string, ty AsExternType)
| 14 | // NewImportType creates a new `ImportType` with the given `module` and `name` and the type |
| 15 | // provided. |
| 16 | func NewImportType(module, name string, ty AsExternType) *ImportType { |
| 17 | moduleVec := stringToByteVec(module) |
| 18 | nameVec := stringToByteVec(name) |
| 19 | |
| 20 | // Creating an import type requires taking ownership, so create a copy |
| 21 | // so we don't have to invalidate pointers here. Shouldn't be too |
| 22 | // costly in theory anyway. |
| 23 | extern := ty.AsExternType() |
| 24 | ptr := C.wasm_externtype_copy(extern.ptr()) |
| 25 | runtime.KeepAlive(extern) |
| 26 | |
| 27 | // And once we've got all that create the import type! |
| 28 | importPtr := C.wasm_importtype_new(&moduleVec, &nameVec, ptr) |
| 29 | |
| 30 | return mkImportType(importPtr, nil) |
| 31 | } |
| 32 | |
| 33 | func mkImportType(ptr *C.wasm_importtype_t, owner interface{}) *ImportType { |
| 34 | importtype := &ImportType{_ptr: ptr, _owner: owner} |
searching dependent graphs…