Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save hubenchang0515/629c134f00bc7fd932dcc234c659643e to your computer and use it in GitHub Desktop.

Select an option

Save hubenchang0515/629c134f00bc7fd932dcc234c659643e to your computer and use it in GitHub Desktop.
Shift - WebAssembly runtime for Python, Lua, Ruby and etc.

I recently used emsdk to build interpreters for languages like Python. Then I wrote an online code editor based on WebAssembly that supports languages such as Python, Lua, and Ruby. No backend is needed, the code runs directly in the browser. Therefore, apart from the initial loading of WASM resources, there are no other network delays, and the results are displayed almost instantly. It can generate shareable links, so now I include the link when posting code online, and clicking it shows the results.

Web Site:https://shift.js.org/

Source:https://github.com/hubenchang0515/shift

Example:

Pascal's Triangle

Pascal's Triangle

fibonacci

fibonacci

In addition, this project provides an NPM package and CDN links. Everyone can load the project's WASM resources to run the code online.

This is an example:

<html>
    <body>
        <!-- HTML Element to show the result -->
        <pre id="output"></pre>
        <script type="module">
            // load js
            import python from "https://shift.js.org/wasm/python.js";
            import makeConfig from "https://shift.js.org/wasm/common.js";

            // condo to run
            const code = 
`import platform
import sys
print(sys.version)
print(platform.platform())
`;

            // callback to get result
            const fn = (stdout) => document.querySelector("#output").innerText = stdout;

            // run the code
            python(makeConfig(code, fn));
        </script>
    </body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment