diff --git a/packages/run-wasm-clarity/README.md b/packages/run-wasm-clarity/README.md new file mode 100644 index 0000000..22ca8a2 --- /dev/null +++ b/packages/run-wasm-clarity/README.md @@ -0,0 +1,127 @@ +TODO: Update for Clarity + +

+ + + +

+ +# run-wasm + +[run-wasm](https://www.runwasm.com) is an easy to use tool for running WASM based code executions in the browser. + +Brought to you by [Slip](https://www.slip.so) and our amazing OSS contributors. + +## Install + +npm + +```bash +npm i @run-wasm/run-wasm +``` + +yarn + +```bash +yarn add @run-wasm/run-wasm +``` + +## Usage - Python + +After installing run-wasm you'll need to import the run-wasm python package + +Install run-wasm python package + +```bash +npm i @run-wasm/python +``` + +yarn + +```bash +yarn add @run-wasm/python +``` + +`@run-wasm/python` uses Pyodide to execute Python. We recommend using the latest version of Pyodide and bringing it into your project via a script. + +[Next.js example](https://github.com/slipHQ/run-wasm/blob/main/example-nextjs/pages/index.tsx) + +```jsx +import React, { useEffect, useState, useRef } from 'react' +import { createPythonClient } from '@run-wasm/python' +import { Editor } from '@run-wasm/run-wasm +import Script from 'next/script' + +declare global { + // <- [reference](https://stackoverflow.com/a/56458070/11542903) + interface Window { + pyodide: any + languagePluginLoader: any + loadPyodide: Function + } +} + +const initialCode = `# Implementation of the Sieve of Eratosthenes +# https://stackoverflow.com/questions/3939660/sieve-of-eratosthenes-finding-primes-python +# Finds all prime numbers up to n +def eratosthenes(n): + multiples = [] + for i in range(2, n+1): + if i not in multiples: + print (i) + for j in range(i*i, n+1, i): + multiples.append(j) +eratosthenes(100)` + +function App() { + const [pyodide, setPyodide] = useState(null) + const [output, setOutput] = React.useState('') + + async function runCode(code: string) { + let pythonClient = createPythonClient(pyodide) + const output = await pythonClient.run({ code }) + if (output) { + setOutput(output) + } + } + + // Note that window.loadPyodide comes from the beforeInteractive pyodide.js Script + useEffect(() => { + window + .loadPyodide({ + indexURL: 'https://cdn.jsdelivr.net/pyodide/v0.18.1/full/', + }) + .then((pyodide) => { + setPyodide(pyodide) + }) + }, []) + + return ( + <> +