| 21 | } |
| 22 | |
| 23 | int main() { |
| 24 | /* Create the VM context. */ |
| 25 | WasmEdge_VMContext *VMCxt = WasmEdge_VMCreate(NULL, NULL); |
| 26 | |
| 27 | /* Create the import object. */ |
| 28 | WasmEdge_String ExportName = WasmEdge_StringCreateByCString("extern"); |
| 29 | WasmEdge_ModuleInstanceContext *ImpObj = |
| 30 | WasmEdge_ModuleInstanceCreate(ExportName); |
| 31 | WasmEdge_ValType ParamList[1] = {WasmEdge_ValTypeGenExternRef()}; |
| 32 | WasmEdge_ValType ReturnList[1] = {WasmEdge_ValTypeGenExternRef()}; |
| 33 | WasmEdge_FunctionTypeContext *HostFType = |
| 34 | WasmEdge_FunctionTypeCreate(ParamList, 1, ReturnList, 1); |
| 35 | WasmEdge_FunctionInstanceContext *HostFunc = |
| 36 | WasmEdge_FunctionInstanceCreate(HostFType, parseJson, NULL, 0); |
| 37 | WasmEdge_FunctionTypeDelete(HostFType); |
| 38 | WasmEdge_String HostFuncName = |
| 39 | WasmEdge_StringCreateByCString("func-parse-json"); |
| 40 | WasmEdge_ModuleInstanceAddFunction(ImpObj, HostFuncName, HostFunc); |
| 41 | WasmEdge_StringDelete(HostFuncName); |
| 42 | |
| 43 | WasmEdge_VMRegisterModuleFromImport(VMCxt, ImpObj); |
| 44 | |
| 45 | /* The parameters and returns arrays. */ |
| 46 | char *Key = "testValue"; |
| 47 | WasmEdge_Value Params[1] = {WasmEdge_ValueGenExternRef(Key)}; |
| 48 | WasmEdge_Value Returns[1]; |
| 49 | WasmEdge_String FuncName = WasmEdge_StringCreateByCString("parseJson"); |
| 50 | WasmEdge_Result Res = WasmEdge_VMRunWasmFromFile( |
| 51 | VMCxt, "parse-json.wasm", FuncName, Params, 1, Returns, 1); |
| 52 | if (WasmEdge_ResultOK(Res)) { |
| 53 | printf("Got the result: %s\n", |
| 54 | (char *)WasmEdge_ValueGetExternRef(Returns[0])); |
| 55 | } else { |
| 56 | printf("Error message: %s\n", WasmEdge_ResultGetMessage(Res)); |
| 57 | } |
| 58 | |
| 59 | /* Resources deallocations. */ |
| 60 | WasmEdge_VMDelete(VMCxt); |
| 61 | WasmEdge_StringDelete(FuncName); |
| 62 | WasmEdge_ModuleInstanceDelete(ImpObj); |
| 63 | return 0; |
| 64 | } |
nothing calls this directly
no test coverage detected