Giter Club home page Giter Club logo

pyruntime's Introduction

PyRuntime Mod

一个用来在 npl 平台执行 python 代码的 npl mod,通过 transpiler 技术实现。

支持语言版本

针对 python 3.4 版本,对于 feature 的支持可参考列表 https://github.com/tatfook/PyRuntime/blob/master/Mod/PyRuntime/py2npl/doc/features.md

usage

确保 PyRuntime 已添加到 Mod 搜索路径下

local transpiler = NPL.load("Mod/PyRuntime/Transpiler.lua")

transpiler:start()

error, luacode = transpiler:transpile(py_code)

if error then
    local error_msg = luacode
    print("error msg", error_msg)
end

-- handle with the transpiled luacode

transpiler:terminate()

其中注意两个地方

  1. transpiler 使用了 C/S 结构来增加性能,意味着底层有一个 transpile 服务,我们通过 transpile() 方法来调用这个服务,这也是为什么需要 start() 和 terminate() 方法的原因
  2. transpile() 方法的返回值有两个,第一个为错误标识,第二个为返回信息
    • 当没有错误时,第二个参数为转换得到的 lua 代码
    • 当发生错误时,第二个参数表示 transpile 过程中的错误信息

details

transpile 的底层服务是一个 http 服务器,使用 python 代码编写,最终打包成为 exe。 这样 npl 就可以开启/关闭服务器,并且使用 http 接口来获取 transpile 服务。

至于具体的 transpiler 实现,参考 py2npl

pyruntime's People

Contributors

zhangleio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.