您好,欢迎来到爱go旅游网。
搜索
您的当前位置:首页Go语言编写CPython扩展goPy

Go语言编写CPython扩展goPy

来源:爱go旅游网

goPy 是一个新的开源项目,实现了用 Go 语言来编写 CPython 扩展。

示例代码:

package simple
 
import (
"fmt"
"gopy"
)
 
func example(args *py.Tuple) (py.Object, error) {
fmt.Printf("simple.example: %v
", args)
py.None.Incref()
return py.None, nil
}
 
func init() {
methods := []py.Method{
{"example", example, "example function"},
}
 
_, err := py.InitModule("simple", methods)
if err != nil {
panic(err)
}
}

编译方法:

gopy pymodule.go


使用方法:

import simple

simple.example("hello", {123: True})

输出结果:

simple.example: [hello map[123:true]]


github开源项目地址:https://github.com/qur/gopy

Copyright © 2019- igat.cn 版权所有 赣ICP备2024042791号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务