CPython extension goPy written in Go language

高洛峰
Release: 2016-10-18 11:40:28
Original
1798 people have browsed it

goPy is a new open source project that implements CPython extensions written in Go language.

Sample code:

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)
}
}
Copy after login

Compilation method:

gopy pymodule.go


Usage method:

import simple

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

Output results:

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


github open source project address: https://github.com/qur/gopy


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template