(name: string, autoAttachToScope = true)
| 1119 | } |
| 1120 | |
| 1121 | private getGlobalFuncInternal(name: string, autoAttachToScope = true): PackedFunc { |
| 1122 | const stack = this.lib.getOrAllocCallStack(); |
| 1123 | const nameOffset = stack.allocByteArrayForString(name); |
| 1124 | const outOffset = stack.allocPtrArray(1); |
| 1125 | const outPtr = stack.ptrFromOffset(outOffset); |
| 1126 | |
| 1127 | stack.commitToWasmMemory(outOffset); |
| 1128 | |
| 1129 | this.lib.checkCall( |
| 1130 | (this.exports.TVMFFIFunctionGetGlobal as ctypes.FTVMFFIFunctionGetGlobal)( |
| 1131 | stack.ptrFromOffset(nameOffset), |
| 1132 | outPtr |
| 1133 | ) |
| 1134 | ); |
| 1135 | const handle = this.memory.loadPointer(outPtr); |
| 1136 | this.lib.recycleCallStack(stack); |
| 1137 | if (handle === 0) { |
| 1138 | throw Error("Cannot find global function " + name); |
| 1139 | } |
| 1140 | const ret = this.makePackedFunc(handle); |
| 1141 | if (autoAttachToScope) this.ctx.attachToCurrentScope(ret); |
| 1142 | return ret; |
| 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Check if func is PackedFunc. |
no test coverage detected