Beispiel #1
0
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()
}
Beispiel #2
0
func TestCall(t *testing.T) {

	log.SetOutputLevel(0)

	for _, c := range g_moduleCases {
		code, err := py.Compile(c.exp, "", py.FileInput)
		if err != nil {
			t.Fatal("Compile failed:", err)
		}
		defer code.Decref()

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

		plg, err := New(mod.Obj(), "Plugin")
		if err != nil {
			t.Fatal("NewPlugin failed:", errors.Detail(err))
		}

		ret, err := CallMethod(plg, "init", "_stage")
		if err != nil {
			t.Fatal("CallMethod failed:", err)
		}
		defer ret.Decref()

		if ret.String() != c.ret {
			t.Fatal("CallMethod ret:", ret.String(), c.ret)
		}

		tbl, _ := plg.GetAttrString("tbl")
		if tbl.String() != c.tbl {
			t.Fatal("mod.GetAttrString('tbl') ret:", tbl.String(), c.tbl)
		}
	}
}