goPyGo 語言編寫 CPython 擴(kuò)展
goPy 是一個新的開源項(xiàng)目,實(shí)現(xiàn)了用 Go 語言來編寫 CPython 擴(kuò)展。
示例代碼:
package simple
import (
"fmt"
"gopy"
)
func example(args *py.Tuple) (py.Object, error) {
fmt.Printf("simple.example: %v\n", 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}) 輸出結(jié)果:
simple.example: [hello map[123:true]]
評論
圖片
表情
