/////////////////////////////////////////////////////////////////////////////////////////////// private static ReturnCode SetupObjectType( string name, /* in */ ref Tcl_ObjType objType, /* in, out */ ref Result error /* out */ ) { try { if (objType == null) { objType = new Tcl_ObjType(); } if ((name != null) && (objType.name == IntPtr.Zero)) { // // NOTE: *WARNING* This string can NEVER be // freed while Tcl remains loaded. // objType.name = Marshal.StringToCoTaskMemAnsi(name); } if (objType.setFromAnyProc == null) { objType.setFromAnyProc = new Tcl_SetFromAnyProc(SetFromAnyProc); } if (objType.updateStringProc == null) { objType.updateStringProc = new Tcl_UpdateStringProc(UpdateStringProc); } if (objType.dupIntRepProc == null) { objType.dupIntRepProc = new Tcl_DupInternalRepProc(DupInternalRepProc); } if (objType.freeIntRepProc == null) { objType.freeIntRepProc = new Tcl_FreeInternalRepProc(FreeInternalRepProc); } return(ReturnCode.Ok); } catch (Exception e) { error = e; return(ReturnCode.Error); } }
/////////////////////////////////////////////////////////////////////////////////////////////// #if HAVE_SIZEOF public static Tcl_ObjType MarshalObjectType(Tcl_Obj obj) { Tcl_ObjType result = null; try { if (obj.typePtr != IntPtr.Zero) { result = MarshalObjectType(obj.typePtr); } } catch { // do nothing. } return(result); }
/////////////////////////////////////////////////////////////////////////////////////////////// public static Tcl_ObjType MarshalObjectType(IntPtr typePtr) { Tcl_ObjType result = null; try { if (typePtr != IntPtr.Zero) { result = (Tcl_ObjType)Marshal.PtrToStructure(typePtr, typeof(Tcl_ObjType)); } } catch { // do nothing. } return(result); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region Tcl Object Type Setup public static ReturnCode RegisterObjectType( Interpreter interpreter, /* in */ string name, /* in */ IObjectType objectType, /* in */ ref Result error /* out */ ) { ReturnCode code; if (interpreter != null) { if (interpreter.tclApi != null) { // // NOTE: *WARNING* Empty Tcl object type names are allowed, // please do not change this to "!String.IsNullOrEmpty". // if (name != null) { // // NOTE: Get the specified object type from Tcl. If we are // registering this object type, it must not already // exist; otherwise, it must already exist. // IntPtr typePtr = interpreter.tclApi.GetObjType(name); // // // if (objectType != null) { if (typePtr == IntPtr.Zero) { Tcl_ObjType objType = null; code = SetupObjectType(name, ref objType, ref error); if (code == ReturnCode.Ok) { interpreter.tclApi.RegisterObjType(ref objType); } } else { error = String.Format( "object type \"{0}\" already registered", name); code = ReturnCode.Error; } } else { if (typePtr != IntPtr.Zero) { // // NOTE: We want to "unregister" the object type. Since // Tcl does not directly support this we will simply // make the specified object type a synonym for the // built-in "string" object type. // Tcl_ObjType objType = MarshalObjectType(typePtr); IntPtr stringTypePtr = interpreter.tclApi.GetObjType("string"); if (stringTypePtr != IntPtr.Zero) { Tcl_ObjType stringObjType = MarshalObjectType(stringTypePtr); } else { } } else { error = String.Format( "object type \"{0}\" is not registered", name); code = ReturnCode.Error; } } } else { } code = ReturnCode.Ok; } else { error = "invalid Tcl API object"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }