Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paramsiddharth/patterns-wasm
A pattern generator coded in C and used in a webpage using WebAssembly.
https://github.com/paramsiddharth/patterns-wasm
Last synced: about 1 month ago
JSON representation
A pattern generator coded in C and used in a webpage using WebAssembly.
- Host: GitHub
- URL: https://github.com/paramsiddharth/patterns-wasm
- Owner: paramsiddharth
- Created: 2020-11-07T03:15:19.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-01T02:36:49.000Z (over 3 years ago)
- Last Synced: 2024-05-22T20:22:03.788Z (7 months ago)
- Language: JavaScript
- Size: 766 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pattern Generator
A pattern generator coded in C and used in a webpage using WebAssembly.## Tools
The following tools would be required:
- The Emscripten SDK (with `emcc`) and GCC : To compile the C source code to WASM and generate the JavaScript glue.
- The Node Package Manager (`npm`) : To install the dependencies and start the server.## Development
### Compiling to WebAssembly
When inside the `src` directory, use GNU Make to compile the Pattern generator source code in C to WebAssembly by executing:
``` bash
make
```This simply executes the following, exporting the `pattern` function to `data/pattern.wasm` and its glue-code to `data/pattern.js`:
``` bash
emcc -o ../data/pattern.js pattern.c -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' -s EXPORTED_FUNCTIONS='["_pattern"]'
````cwrap` is preferred over `ccall` because it lets us create a JavaScript wrapper around the C function, which we can call like any normal JavaScript function to receive the output.
Optionally, one may test the `pattern` function by compiling `pattern.c` to an executable binary using GCC. The main function's job is only to run the user-defined test, and hence is not exported while building `pattern.wasm`. It can be done by executing:
``` bash
make test
```### Starting the Server
Install the dependencies via `package.json` using:
``` bash
npm install
```Start the local server at port 3000 using:
``` bash
npm start
```The application will be running at http://localhost:3000/.
\
\
Made with ❤ by Param.