py

Golang bindings to the CPython C-API

  • 所有者: goplus/py
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

py - Golang bindings to the CPython C-API

Build Status

Qiniu Logo

py is Golang bindings to the CPython C-API.

py project's homepage is: https://github.com/qiniu/py

Install

go get github.com/qiniu/py

Example

package main

import (
	"fmt"
	"github.com/qiniu/log"
	"github.com/qiniu/py"
)

// -------------------------------------------------------------------

type FooModule struct {
}

func (r *FooModule) Py_bar(args *py.Tuple) (ret *py.Base, err error) {
	var i int
	var s string
	err = py.Parse(args, &i, &s)
	if err != nil {
		return
	}
	fmt.Println("call foo.bar:", i, s)
	return py.IncNone(), nil
}

func (r *FooModule) Py_bar2(args *py.Tuple) (ret *py.Base, err error) {
	var i int
	var s []string
	err = py.ParseV(args, &i, &s)
	if err != nil {
		return
	}
	fmt.Println("call foo.bar2:", i, s)
	return py.IncNone(), nil
}

// -------------------------------------------------------------------

const pyCode = `

import foo
foo.bar(1, 'Hello')
foo.bar2(1, 'Hello', 'world!')
`

func main() {

	gomod, err := py.NewGoModule("foo", "", new(FooModule))
	if err != nil {
		log.Fatal("NewGoModule failed:", err)
	}
	defer gomod.Decref()

	code, err := py.Compile(pyCode, "", py.FileInput)
	if err != nil {
		log.Fatal("Compile failed:", err)
	}
	defer code.Decref()

	mod, err := py.ExecCodeModule("test", code.Obj())
	if err != nil {
		log.Fatal("ExecCodeModule failed:", err)
	}
	defer mod.Decref()
}

// -------------------------------------------------------------------

主要指標

概覽
名稱與所有者goplus/py
主編程語言Go
編程語言Go (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2013-03-10 11:16:16
推送於2024-06-07 00:17:38
最后一次提交2024-06-07 08:17:38
發布數3
最新版本名稱v1.1.00 (發布於 2013-05-30 01:23:48)
第一版名稱v1.0.00 (發布於 2013-03-10 20:19:28)
用户参与
星數322
關注者數36
派生數57
提交數35
已啟用問題?
問題數11
打開的問題數3
拉請求數16
打開的拉請求數0
關閉的拉請求數3
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?