Esempio n. 1
0
func init() {
	lock := py.NewLock()
	defer lock.Unlock()

	/* Setup default targets */
	stdoutTarget := log.NewTextTarget(os.Stdout)
	bufferingTarget := log.NewBufferingTarget(stdoutTarget)
	log.Targets["stdout"] = bufferingTarget

	/* Create package */
	var err error
	var module *py.Module
	if module, err = modules.Init("gem.log", []py.Method{
		{"begin_redirect", Py_begin_redirect, ""},
		{"end_redirect", Py_end_redirect, ""},
	}); err != nil {
		panic(err)
	}

	/* Register modules */
	for _, registerFunc := range moduleRegisterFuncs {
		if err = registerFunc(module); err != nil {
			panic(err)
		}
	}
}
Esempio n. 2
0
// TestPyBindOut tests creating objects in python and extracting them
func TestPyBindOut(t *testing.T) {
	_ = py.NewLock()
	safe.Unsafe = true

	if main, err := py.NewDict(); err != nil {
		t.Fatal(err)
	} else if g, err := py.GetBuiltins(); err != nil {
		t.Fatal(err)
	} else if err := main.SetItemString("__builtins__", g); err != nil {
		t.Fatal(err)
	} else if module, err := modules.Init("test_module", []py.Method{}); err != nil {
		t.Fatal(err)
	} else if err := RegisterCat(module); err != nil {
		t.Fatal(err)
	} else if _, err := py.RunString(testCatOut, py.FileInput, main, nil); err != nil {
		t.Fatal(err)
	} else if a, err := main.GetItemString("the_cat"); err != nil {
		t.Fatal(err)
	} else if the_cat, ok := a.(*Cat); !ok {
		t.Errorf("Unable to extract test object")
	} else {
		if the_cat.Name != "Garfield" || the_cat.Cheeseburgers != 1 {
			t.Errorf("Object's properties weren't updated")
		}
		t.Logf("%V", the_cat)
	}
}
Esempio n. 3
0
File: events.go Progetto: gemrs/gem
func init() {
	lock := py.NewLock()
	defer lock.Unlock()

	/* Create package */
	var err error
	var module *py.Module
	if module, err = modules.Init("gem.game.event", []py.Method{}); err != nil {
		panic(err)
	}

	createEventObjects(module)
}
Esempio n. 4
0
func init() {
	lock := py.NewLock()
	defer lock.Unlock()

	/* Create package */
	var err error
	var module *py.Module
	if module, err = modules.Init("gem.archive", []py.Method{}); err != nil {
		panic(err)
	}

	/* Register modules */
	for _, registerFunc := range moduleRegisterFuncs {
		if err = registerFunc(module); err != nil {
			panic(err)
		}
	}
}
Esempio n. 5
0
func init() {
	lock := py.NewLock()
	defer lock.Unlock()

	/* Create package */
	var err error
	var module *py.Module
	methods := []py.Method{
		{"submit", Py_submit, "submit a task to the scheduler"},
	}
	if module, err = modules.Init("gem.task", methods); err != nil {
		panic(err)
	}

	createTaskHookConstants(module)

	/* Register modules */
	for _, registerFunc := range moduleRegisterFuncs {
		if err = registerFunc(module); err != nil {
			panic(err)
		}
	}
}