示例#1
0
文件: python.go 项目: xushiwei/gopy
func callPyCmd(fn py.Object, args []string) error {
	lock := py.NewLock()
	defer lock.Unlock()

	pyArgs, err := py.NewTuple(int64(len(args)))
	if err != nil {
		return nil
	}
	defer pyArgs.Decref()

	for i, arg := range args {
		s, err := py.NewString(arg)
		if err != nil {
			return err
		}
		err = pyArgs.SetItem(int64(i), s)
		if err != nil {
			s.Decref()
			return err
		}
	}

	ret, err := fn.Base().CallObject(pyArgs)
	if err != nil {
		return err
	}
	ret.Decref()

	return nil
}
示例#2
0
文件: module.go 项目: xushiwei/gopy
func pyTokenise(args *py.Tuple) (py.Object, error) {
	s := ""
	err := py.ParseTuple(args, "s", &s)
	if err != nil {
		return nil, err
	}

	parts := tokenise(s)

	t, err := py.NewTuple(int64(len(parts)))
	if err != nil {
		return nil, err
	}

	for i, arg := range parts {
		pyS, err := py.NewString(arg)
		if err != nil {
			t.Decref()
			return nil, err
		}
		t.SetItem(int64(i), pyS)
	}

	return t, nil
}