Esempio n. 1
0
func NewInterpreter() (*Interpreter, os.Error) {
	ir := &Interpreter{
		C:         C.Tcl_CreateInterp(),
		callbacks: make(map[string]interface{}),
		channels:  make(map[string]interface{}),
		valuesbuf: make([]reflect.Value, 0, 10),
		queue:     make(chan string, 50),
	}

	status := C.Tcl_Init(ir.C)
	if status != C.TCL_OK {
		return nil, os.NewError(C.GoString(C.Tcl_GetStringResult(ir.C)))
	}

	status = C.Tk_Init(ir.C)
	if status != C.TCL_OK {
		return nil, os.NewError(C.GoString(C.Tcl_GetStringResult(ir.C)))
	}

	return ir, nil
}
Esempio n. 2
0
func new_interpreter(init interface{}) (*interpreter, error) {
	ir := &interpreter{
		C:              C.Tcl_CreateInterp(),
		errfilt:        func(err error) error { return err },
		commands:       make(map[string]interface{}),
		methods:        make(map[string]interface{}),
		method_handles: make(map[string][]int),
		valuesbuf:      make([]reflect.Value, 0, 10),
		queue:          make(chan async_action, 50),
		thread:         C.Tcl_GetCurrentThread(),
	}

	C.Tcl_FindExecutable(C.CString(os.Args[0]))

	switch realinit := init.(type) {
	case string:
		err := ir.eval([]byte(realinit))
		if err != nil {
			panic(err)
		}
	case func(*interpreter):
		realinit(ir)
	}

	status := C.Tcl_Init(ir.C)
	if status != C.TCL_OK {
		return nil, errors.New(C.GoString(C.Tcl_GetStringResult(ir.C)))
	}

	status = C.Tk_Init(ir.C)
	if status != C.TCL_OK {
		return nil, errors.New(C.GoString(C.Tcl_GetStringResult(ir.C)))
	}

	ir.id = global_handles.get_handle_for_value(ir)
	runtime.SetFinalizer(ir, release_interpreter)
	return ir, nil
}
Esempio n. 3
0
func new_interpreter() (*interpreter, error) {
	ir := &interpreter{
		C:         C.Tcl_CreateInterp(),
		errfilt:   func(err error) error { return err },
		commands:  make(map[string]interface{}),
		channels:  make(map[string]interface{}),
		valuesbuf: make([]reflect.Value, 0, 10),
		queue:     make(chan async_action, 50),
		thread:    C.Tcl_GetCurrentThread(),
	}

	status := C.Tcl_Init(ir.C)
	if status != C.TCL_OK {
		return nil, errors.New(C.GoString(C.Tcl_GetStringResult(ir.C)))
	}

	status = C.Tk_Init(ir.C)
	if status != C.TCL_OK {
		return nil, errors.New(C.GoString(C.Tcl_GetStringResult(ir.C)))
	}

	return ir, nil
}