Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
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
}