runfib.lpr 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. program runfib;
  2. uses ctypes, libwasmedge;
  3. var
  4. ConfCxt : PWasmEdge_ConfigureContext;
  5. VMCxt : PWasmEdge_VMContext;
  6. Returns, Params : Array[0..0] of TWasmEdge_Value;
  7. FuncName : TWasmEdge_String;
  8. Res : TWasmEdge_Result;
  9. begin
  10. Loadlibwasmedge('libwasmedge.so');
  11. { Create the configure context and add the WASI support.
  12. This step is not necessary unless you need WASI support.}
  13. ConfCxt:=WasmEdge_ConfigureCreate();
  14. WasmEdge_ConfigureAddHostRegistration(ConfCxt, WasmEdge_HostRegistration_Wasi);
  15. { The configure and store context to the VM creation can be NULL. }
  16. VMCxt:=WasmEdge_VMCreate(ConfCxt,Nil);
  17. { The parameters }
  18. Params[0] := WasmEdge_ValueGenI32(32);
  19. { Function name. }
  20. FuncName:=WasmEdge_StringCreateByCString(Pcchar(Pansichar('fib')));
  21. { Run the WASM function from file. }
  22. Res := WasmEdge_VMRunWasmFromFile(VMCxt, pcchar(PAnsiChar(ParamStr(1))), FuncName, @Params, 1, @Returns, 1);
  23. if (WasmEdge_ResultOK(Res)) then
  24. Writeln('Get result: ', WasmEdge_ValueGetI32(Returns[0]))
  25. else
  26. Writeln('Error message: ', PAnsiChar(WasmEdge_ResultGetMessage(Res)));
  27. { Resources deallocations. }
  28. WasmEdge_VMDelete(VMCxt);
  29. WasmEdge_ConfigureDelete(ConfCxt);
  30. WasmEdge_StringDelete(FuncName);
  31. end.