Exemplo n.º 1
0
func (sv *StringVar) Set(s string) {
	if sv.data != nil {
		C.Tcl_Free(sv.data)
	}
	sv.data = C.Tcl_Alloc(C.uint(len(s) + 1))
	svslice := (*((*[alot]byte)(unsafe.Pointer(sv.data))))[:]
	copy(svslice, s)
	svslice[len(s)] = 0

	cname := C.CString(sv.name)
	C.Tcl_UpdateLinkedVar(sv.ir.C, cname)
	C.free_string(cname)
}
Exemplo n.º 2
0
func (ir *Interpreter) NewStringVar(name string) *StringVar {
	sv := new(StringVar)
	sv.ir = ir
	sv.name = name
	sv.data = C.Tcl_Alloc(1)
	(*((*[alot]byte)(unsafe.Pointer(sv.data))))[0] = 0

	cname := C.CString(name)
	status := C.Tcl_LinkVar(ir.C, cname, (*C.char)(unsafe.Pointer(&sv.data)),
		C.TCL_LINK_STRING)
	C.free_string(cname)
	if status != C.TCL_OK {
		panic(C.GoString(C.Tcl_GetStringResult(ir.C)))
	}
	return sv
}