func (ir *interpreter) register_command(name string, cbfunc interface{}) error { typ := reflect.TypeOf(cbfunc) if typ.Kind() != reflect.Func { return errors.New("gothic: RegisterCommand only accepts func type as a second argument") } if _, ok := ir.commands[name]; ok { return errors.New("gothic: command with the same name was already registered") } ir.commands[name] = cbfunc cname := C.CString(name) C._gotk_c_add_command(ir.C, cname, C.int(ir.id), C.int(ir.handles.get_handle_for_value(cbfunc))) C.free(unsafe.Pointer(cname)) return nil }
func (ir *interpreter) register_command(name string, cbfunc interface{}) error { typ := reflect.TypeOf(cbfunc) if typ.Kind() != reflect.Func { return errors.New("gothic: RegisterCommand only accepts func type as a second argument") } if _, ok := ir.commands[name]; ok { return errors.New("gothic: command with the same name was already registered") } ir.commands[name] = cbfunc cp, cn := go_string_to_cgo_string(name) cname := C.CString(name) C._gotk_c_add_command(ir.C, cname, unsafe.Pointer(ir), cp, cn, go_interface_to_c_interface(cbfunc)) C.free(unsafe.Pointer(cname)) return nil }