Skip to content

【开源自荐】shift - 基于 WebAssembly 的在线代码编辑器,可在线运行 Python、Lua、Ruby 等语言 #8440

@hubenchang0515

Description

@hubenchang0515

网页地址:https://shift.js.org/
源码地址:https://github.com/hubenchang0515/shift

shift 是一个基于 WebAssembly 的在线代码编辑器,可在线运行 Python、Lua、Ruby 等语言。

可以随时随地在任何设备上运行代码、验证想法,并且可以生成分享链接,读者点开即可查看运行结果。

代码直接在浏览器上运行,因此除了首次加载 WASM 资源以外,不再有其它网络延迟,可以秒出运行结果。安全高效、低碳环保。

并且可以作为渐进式 Web 应用(PWA)缓存到本地,没有网络时也能使用。

示例:

杨辉三角

Image

此外,这个项目还提供 NPM 包 和 CDN 链接,任何人都能加载此项目的 WASM 资源来在线运行代码。

这是一个简单的示例:

<html>
    <body>
        <!-- 用于显示结果的 HTML 元素 -->
        <pre id="output"></pre>
        <script type="module">
            // 加载 js 资源
            import python from "https://shift.js.org/wasm/python.js";
            import makeConfig from "https://shift.js.org/wasm/common.js";

            // 要运行的代码
            const code = 
`import platform
import sys
print(sys.version)
print(platform.platform())
`;

            // 回调函数:获取运行结果
            const fn = (stdout) => document.querySelector("#output").innerText = stdout;

            // 运行代码
            python(makeConfig(code, fn));
        </script>
    </body>
</html>
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions