This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1280|Reply: 1

[Other] Front-end web pages execute functions in wasm in 3 ways

[Copy link]
Posted on 11/27/2024 8:45:24 AM | | | |
About WebAssembly

WebAssembly is a new way of encoding that can run in modern web browsers – it's a low-level class assembly language with a compact binary format that runs close to native performance and provides compilation targets for languages such as C/C++, C#, and Rust so that they can run on the web. It is also designed to coexist with JavaScript, allowing the two to work together.

Generate a test wasm file

AssemblyScript is a TypeScript-like WebAssembly language (The hyperlink login is visible.)。 Install the AssemblyScript tool, which compiles the typescript file into a WebAssembly file. The installation command is as follows:

Create a new test.ts file and define it as follows:

Generate the .wasm file with the following command:

Configuration parameters:The hyperlink login is visible.

Execute the functions within wasm

Method 1 (Easiest)

Directly reference the generated .js module execution, as follows:



Method 2

With assemblyscript/loader, reference:The hyperlink login is visible., the code is as follows:



The .wasm command can be generated in this way as follows:

This way it doesn't generate .ts, . js file.

Method 3

Load compilation using native WebAssembly, the code is as follows:



Finally, attach the source code file:

Tourists, if you want to see the hidden content of this post, pleaseReply






Previous:Some tips on System.Text.Json manipulating JSON
Next:Check whether the string is IPv4 or IPv6 in JavaScript
 Landlord| Posted on 11/27/2024 8:49:09 AM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com