Class ObjCRuntime

java.lang.Object
org.lwjgl.system.macosx.ObjCRuntime

public class ObjCRuntime extends Object
Native bindings to the Objective-C Runtime.

Due to the nature of the objc_msgSend* functions, they are not directly exposed in this binding. Advanced users with good understanding of the complexity involved with using these functions, may access them via the getLibrary() method:


 SharedLibrary objc = ObjCRuntime.getLibrary();
 long objc_msgSend = objc.getFunctionAddress("objc_msgSend");
 
 // example usage
 long NSThread = objc_getClass("NSThread");
 long currentThread = invokePPP(NSThread, sel_getUid("currentThread"), objc_msgSend);

The safe way to use objc_msgSend in C code is to cast it to an appropriate function pointer. This is exactly what the JNI class does. If a particular function signature is not available, LibFFI may be used to invoke it.

The functions not exposed are:

  • objc_msgSend
  • objc_msgSend_stret
  • objc_msgSendSuper
  • objc_msgSendSuper_stret
  • Field Details

  • Method Details

    • getLibrary

      public static org.lwjgl.system.SharedLibrary getLibrary()
      Returns the objc SharedLibrary.
    • object_copy

      public static long object_copy(long obj, long size)
      Returns a copy of a given object.
      Parameters:
      obj - an Objective-C object
      size - the size of the object obj
      Returns:
      a copy of obj
    • object_dispose

      public static long object_dispose(long obj)
      Frees the memory occupied by a given object.
      Parameters:
      obj - an Objective-C object
      Returns:
      nil
    • object_getClass

      public static long object_getClass(long obj)
      Returns the class of an object.
      Parameters:
      obj - an Objective-C object
      Returns:
      the class object of which object is an instance, or Nil if obj is nil
    • object_setClass

      public static long object_setClass(long obj, long cls)
      Sets the class of an object.
      Parameters:
      obj - the object to modify
      cls - a class object
      Returns:
      the previous value of object's class, or Nil if obj is nil
    • nobject_getClassName

      public static long nobject_getClassName(long obj)
      Unsafe version of: object_getClassName(long)
    • object_getClassName

      @Nullable public static String object_getClassName(long obj)
      Returns the class name of a given object.
      Parameters:
      obj - an Objective-C object
      Returns:
      the name of the class of which obj is an instance
    • object_getIndexedIvars

      public static long object_getIndexedIvars(long obj)
      This function returns a pointer to any extra bytes allocated with the instance (as specified by class_createInstance(long, long) with extraBytes>0). This memory follows the object's ordinary ivars, but may not be adjacent to the last ivar.

      The returned pointer is guaranteed to be pointer-size aligned, even if the area following the object's last ivar is less aligned than that. Alignment greater than pointer-size is never guaranteed, even if the area following the object's last ivar is more aligned than that.

      In a garbage-collected environment, the memory is scanned conservatively.

      Parameters:
      obj - an Objective-C object
      Returns:
      a pointer to any extra bytes allocated with obj. If obj was not allocated with any extra bytes, then dereferencing the returned pointer is undefined.
    • object_getIvar

      public static long object_getIvar(long obj, long ivar)
      Reads the value of an instance variable in an object.
      Parameters:
      obj - the object containing the instance variable whose value you want to read
      ivar - the Ivar describing the instance variable whose value you want to read
      Returns:
      the value of the instance variable specified by ivar, or nil if obj is nil
    • object_setIvar

      public static void object_setIvar(long obj, long ivar, long value)
      Sets the value of an instance variable in an object.

      object_setIvar is faster than object_setInstanceVariable(long, java.nio.ByteBuffer, java.nio.ByteBuffer) if the Ivar for the instance variable is already known.

      Parameters:
      obj - the object containing the instance variable whose value you want to set
      ivar - the Ivar describing the instance variable whose value you want to set
      value - the new value for the instance variable
    • nobject_setInstanceVariable

      public static long nobject_setInstanceVariable(long obj, long name, long value)
    • object_setInstanceVariable

      public static long object_setInstanceVariable(long obj, ByteBuffer name, ByteBuffer value)
      Changes the value of an instance variable of a class instance.
      Parameters:
      obj - a pointer to an instance of a class. Pass the object containing the instance variable whose value you wish to modify
      name - a C string. Pass the name of the instance variable whose value you wish to modify
      value - the new value for the instance variable
      Returns:
      a pointer to the Ivar data structure that defines the type and name of the instance variable specified by name
    • object_setInstanceVariable

      public static long object_setInstanceVariable(long obj, CharSequence name, ByteBuffer value)
      Changes the value of an instance variable of a class instance.
      Parameters:
      obj - a pointer to an instance of a class. Pass the object containing the instance variable whose value you wish to modify
      name - a C string. Pass the name of the instance variable whose value you wish to modify
      value - the new value for the instance variable
      Returns:
      a pointer to the Ivar data structure that defines the type and name of the instance variable specified by name
    • nobject_getInstanceVariable

      public static long nobject_getInstanceVariable(long obj, long name, long outValue)
    • object_getInstanceVariable

      public static long object_getInstanceVariable(long obj, ByteBuffer name, org.lwjgl.PointerBuffer outValue)
      Obtains the value of an instance variable of a class instance.
      Parameters:
      obj - a pointer to an instance of a class. Pass the object containing the instance variable whose value you wish to obtain
      name - a C string. Pass the name of the instance variable whose value you wish to obtain
      outValue - on return, contains a pointer to the value of the instance variable
      Returns:
      a pointer to the Ivar data structure that defines the type and name of the instance variable specified by name
    • object_getInstanceVariable

      public static long object_getInstanceVariable(long obj, CharSequence name, org.lwjgl.PointerBuffer outValue)
      Obtains the value of an instance variable of a class instance.
      Parameters:
      obj - a pointer to an instance of a class. Pass the object containing the instance variable whose value you wish to obtain
      name - a C string. Pass the name of the instance variable whose value you wish to obtain
      outValue - on return, contains a pointer to the value of the instance variable
      Returns:
      a pointer to the Ivar data structure that defines the type and name of the instance variable specified by name
    • nobjc_getClass

      public static long nobjc_getClass(long name)
    • objc_getClass

      public static long objc_getClass(ByteBuffer name)
      Returns the class definition of a specified class.

      objc_getClass is different from objc_lookUpClass(java.nio.ByteBuffer) in that if the class is not registered, objc_getClass calls the class handler callback and then checks a second time to see whether the class is registered. objc_lookUpClass does not call the class handler callback.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the named class, or nil if the class is not registered with the Objective-C runtime
    • objc_getClass

      public static long objc_getClass(CharSequence name)
      Returns the class definition of a specified class.

      objc_getClass is different from objc_lookUpClass(java.nio.ByteBuffer) in that if the class is not registered, objc_getClass calls the class handler callback and then checks a second time to see whether the class is registered. objc_lookUpClass does not call the class handler callback.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the named class, or nil if the class is not registered with the Objective-C runtime
    • nobjc_getMetaClass

      public static long nobjc_getMetaClass(long name)
    • objc_getMetaClass

      public static long objc_getMetaClass(ByteBuffer name)
      Returns the metaclass definition of a specified class.

      If the definition for the named class is not registered, this function calls the class handler callback and then checks a second time to see if the class is registered. However, every class definition must have a valid metaclass definition, and so the metaclass definition is always returned, whether it’s valid or not.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the metaclass of the named class, or nil if the class is not registered with the Objective-C runtime
    • objc_getMetaClass

      public static long objc_getMetaClass(CharSequence name)
      Returns the metaclass definition of a specified class.

      If the definition for the named class is not registered, this function calls the class handler callback and then checks a second time to see if the class is registered. However, every class definition must have a valid metaclass definition, and so the metaclass definition is always returned, whether it’s valid or not.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the metaclass of the named class, or nil if the class is not registered with the Objective-C runtime
    • nobjc_lookUpClass

      public static long nobjc_lookUpClass(long name)
    • objc_lookUpClass

      public static long objc_lookUpClass(ByteBuffer name)
      Returns the class definition of a specified class.

      objc_getClass(java.nio.ByteBuffer) is different from this function in that if the class is not registered, objc_getClass calls the class handler callback and then checks a second time to see whether the class is registered. This function does not call the class handler callback.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the named class, or nil if the class is not registered with the Objective-C runtime
    • objc_lookUpClass

      public static long objc_lookUpClass(CharSequence name)
      Returns the class definition of a specified class.

      objc_getClass(java.nio.ByteBuffer) is different from this function in that if the class is not registered, objc_getClass calls the class handler callback and then checks a second time to see whether the class is registered. This function does not call the class handler callback.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the named class, or nil if the class is not registered with the Objective-C runtime
    • nobjc_getRequiredClass

      public static long nobjc_getRequiredClass(long name)
    • objc_getRequiredClass

      public static long objc_getRequiredClass(ByteBuffer name)
      Returns the class definition of a specified class.

      This function is the same as objc_getClass(java.nio.ByteBuffer), but kills the process if the class is not found.

      This function is used by ZeroLink, where failing to find a class would be a compile-time link error without ZeroLink.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the named class
    • objc_getRequiredClass

      public static long objc_getRequiredClass(CharSequence name)
      Returns the class definition of a specified class.

      This function is the same as objc_getClass(java.nio.ByteBuffer), but kills the process if the class is not found.

      This function is used by ZeroLink, where failing to find a class would be a compile-time link error without ZeroLink.

      Parameters:
      name - the name of the class to look up
      Returns:
      the Class object for the named class
    • nobjc_getClassList

      public static int nobjc_getClassList(long buffer, int bufferCount)
      Parameters:
      bufferCount - the number of pointers for which you have allocated space in buffer. On return, this function fills in only this number of elements. If this number is less than the number of registered classes, this function returns an arbitrary subset of the registered classes.
    • objc_getClassList

      public static int objc_getClassList(@Nullable org.lwjgl.PointerBuffer buffer)
      Obtains the list of registered class definitions.

      The Objective-C runtime library automatically registers all the classes defined in your source code. You can create class definitions at runtime and register them with the objc_allocateClassPair(long, java.nio.ByteBuffer, long) and objc_registerClassPair(long) functions.

      Special Considerations

      You cannot assume that class objects you get from this function are classes that inherit from NSObject, so you cannot safely call any methods on such classes without detecting that the method is implemented first.

      Parameters:
      buffer - an array of Class values. On output, each Class value points to one class definition, up to either bufferCount or the total number of registered classes, whichever is less. You can pass NULL to obtain the total number of registered class definitions without actually retrieving any class definitions.
      Returns:
      an integer value indicating the total number of registered classes
    • nobjc_copyClassList

      public static long nobjc_copyClassList(long outCount)
      Unsafe version of: objc_copyClassList()
      Parameters:
      outCount - an integer pointer used to store the number of classes returned by this function in the list. This parameter may be nil
    • objc_copyClassList

      @Nullable public static org.lwjgl.PointerBuffer objc_copyClassList()
      Creates and returns a list of pointers to all registered class definitions.
      Returns:
      a nil terminated array of classes. You must free the array with free()
    • nclass_getName

      public static long nclass_getName(long cls)
      Unsafe version of: class_getName(long)
    • class_getName

      @Nullable public static String class_getName(long cls)
      Returns the name of a class.
      Parameters:
      cls - a class object
      Returns:
      the name of the class, or the empty string if cls is Nil
    • class_isMetaClass

      public static boolean class_isMetaClass(long cls)
      Returns a Boolean value that indicates whether a class object is a metaclass.
      Parameters:
      cls - a class object
      Returns:
      YES if cls is a metaclass, NO if cls is a non-meta class, NO if cls is Nil
    • class_getSuperclass

      public static long class_getSuperclass(long cls)
      Returns the superclass of a class.
      Parameters:
      cls - a class object
      Returns:
      the superclass of the class, or Nil if cls is a root class, or Nil if cls is Nil
    • class_getVersion

      public static int class_getVersion(long cls)
      Returns the version number of a class definition.

      You can use the version number of the class definition to provide versioning of the interface that your class represents to other classes. This is especially useful for object serialization (that is, archiving of the object in a flattened form), where it is important to recognize changes to the layout of the instance variables in different class-definition versions.

      Classes derived from the Foundation framework NSObject class can obtain the class-definition version number using the getVersion class method, which is implemented using the class_getVersion function.

      Parameters:
      cls - a pointer to an Class data structure. Pass the class definition for which you wish to obtain the version
      Returns:
      an integer indicating the version number of the class definition
    • class_setVersion

      public static void class_setVersion(long cls, int version)
      Sets the version number of a class definition.

      You can use the version number of the class definition to provide versioning of the interface that your class represents to other classes. This is especially useful for object serialization (that is, archiving of the object in a flattened form), where it is important to recognize changes to the layout of the instance variables in different class-definition versions.

      Classes derived from the Foundation framework NSObject class can set the class-definition version number using the setVersion: class method, which is implemented using the class_setVersion function.

      Parameters:
      cls - a pointer to an Class data structure. Pass the class definition for which you wish to set the version
      version - the new version number of the class definition
    • class_getInstanceSize

      public static long class_getInstanceSize(long cls)
      Returns the size of instances of a class.
      Parameters:
      cls - a class object
      Returns:
      the size in bytes of instances of the class cls, or 0 if cls is Nil
    • nclass_getInstanceVariable

      public static long nclass_getInstanceVariable(long cls, long name)
    • class_getInstanceVariable

      public static long class_getInstanceVariable(long cls, ByteBuffer name)
      Returns the Ivar for a specified instance variable of a given class.
      Parameters:
      cls - the class whose instance variable you wish to obtain
      name - the name of the instance variable definition to obtain
      Returns:
      a pointer to an Ivar data structure containing information about the instance variable specified by name
    • class_getInstanceVariable

      public static long class_getInstanceVariable(long cls, CharSequence name)
      Returns the Ivar for a specified instance variable of a given class.
      Parameters:
      cls - the class whose instance variable you wish to obtain
      name - the name of the instance variable definition to obtain
      Returns:
      a pointer to an Ivar data structure containing information about the instance variable specified by name
    • nclass_getClassVariable

      public static long nclass_getClassVariable(long cls, long name)
    • class_getClassVariable

      public static long class_getClassVariable(long cls, ByteBuffer name)
      Returns the Ivar for a specified class variable of a given class.
      Parameters:
      cls - the class definition whose class variable you wish to obtain
      name - the name of the class variable definition to obtain
      Returns:
      a pointer to an Ivar data structure containing information about the class variable specified by name
    • class_getClassVariable

      public static long class_getClassVariable(long cls, CharSequence name)
      Returns the Ivar for a specified class variable of a given class.
      Parameters:
      cls - the class definition whose class variable you wish to obtain
      name - the name of the class variable definition to obtain
      Returns:
      a pointer to an Ivar data structure containing information about the class variable specified by name
    • nclass_copyIvarList

      public static long nclass_copyIvarList(long cls, long outCount)
      Unsafe version of: class_copyIvarList(long)
      Parameters:
      outCount - on return, contains the length of the returned array. If outCount is NULL, the length is not returned
    • class_copyIvarList

      @Nullable public static org.lwjgl.PointerBuffer class_copyIvarList(long cls)
      Describes the instance variables declared by a class.
      Parameters:
      cls - the class to inspect
      Returns:
      an array of pointers of type Ivar describing the instance variables declared by the class. Any instance variables declared by superclasses are not included. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().

      If the class declares no instance variables, or cls is Nil, NULL is returned and *outCount is 0.

    • class_getInstanceMethod

      public static long class_getInstanceMethod(long cls, long name)
      Returns a specified instance method for a given class.

      Note that this function searches superclasses for implementations, whereas class_copyMethodList(long) does not.

      Parameters:
      cls - the class you want to inspect
      name - the selector of the method you want to retrieve
      Returns:
      the method that corresponds to the implementation of the selector specified by aSelector for the class specified by cls, or NULL if the specified class or its superclasses do not contain an instance method with the specified selector.
    • class_getClassMethod

      public static long class_getClassMethod(long cls, long name)
      Returns a pointer to the data structure describing a given class method for a given class.

      Note that this function searches superclasses for implementations, whereas class_copyMethodList(long) does not.

      Parameters:
      cls - a pointer to a class definition. Pass the class that contains the method you want to retrieve
      name - a pointer of type SEL. Pass the selector of the method you want to retrieve
      Returns:
      a pointer to the Method data structure that corresponds to the implementation of the selector specified by name for the class specified by cls, or NULL if the specified class or its superclasses do not contain a class method with the specified selector.
    • class_getMethodImplementation

      public static long class_getMethodImplementation(long cls, long name)
      Returns the function pointer that would be called if a particular message were sent to an instance of a class.

      class_getMethodImplementation may be faster than method_getImplementation(class_getInstanceMethod(cls, name)).

      The function pointer returned may be a function internal to the runtime instead of an actual method implementation. For example, if instances of the class do not respond to the selector, the function pointer returned will be part of the runtime's message forwarding machinery.

      Parameters:
      cls - the class you want to inspect
      name - a selector
      Returns:
      the function pointer that would be called if [object name] were called with an instance of the class, or NULL if cls is Nil
    • class_respondsToSelector

      public static boolean class_respondsToSelector(long cls, long name)
      Returns a Boolean value that indicates whether instances of a class respond to a particular selector.

      You should usually use NSObject's respondsToSelector: or instancesRespondToSelector: methods instead of this function.

      Parameters:
      cls - the class you want to inspect
      name - a selector
      Returns:
      YES if instances of the class respond to the selector, otherwise NO
    • nclass_copyMethodList

      public static long nclass_copyMethodList(long cls, long outCount)
      Unsafe version of: class_copyMethodList(long)
      Parameters:
      outCount - on return, contains the length of the returned array. If outCount is NULL, the length is not returned
    • class_copyMethodList

      @Nullable public static org.lwjgl.PointerBuffer class_copyMethodList(long cls)
      Describes the instance methods implemented by a class.
      Parameters:
      cls - the class you want to inspect
      Returns:
      an array of pointers of type Method describing the instance methods implemented by the class—any instance methods implemented by superclasses are not included. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().

      If cls implements no instance methods, or cls is Nil, returns NULL and *outCount is 0.

    • class_conformsToProtocol

      public static boolean class_conformsToProtocol(long cls, long protocol)
      Returns a Boolean value that indicates whether a class conforms to a given protocol.

      You should usually use NSObject's conformsToProtocol: method instead of this function.

      Parameters:
      cls - the class you want to inspect
      protocol - a protocol
      Returns:
      YES if cls conforms to protocol, otherwise NO
    • nclass_copyProtocolList

      public static long nclass_copyProtocolList(long cls, long outCount)
      Unsafe version of: class_copyProtocolList(long)
      Parameters:
      outCount - on return, contains the length of the returned array. If outCount is NULL, the length is not returned
    • class_copyProtocolList

      @Nullable public static org.lwjgl.PointerBuffer class_copyProtocolList(long cls)
      Describes the protocols adopted by a class.
      Parameters:
      cls - the class you want to inspect
      Returns:
      an array of pointers of type Protocol* describing the protocols adopted by the class. Any protocols adopted by superclasses or other protocols are not included. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().

      If cls adopts no protocols, or cls is Nil, returns NULL and *outCount is 0.

    • nclass_getProperty

      public static long nclass_getProperty(long cls, long name)
    • class_getProperty

      public static long class_getProperty(long cls, ByteBuffer name)
      Returns a property with a given name of a given class.
      Parameters:
      cls - the class you want to inspect
      name - a C string. Pass the name of the instance variable whose value you wish to modify.
      Returns:
      a pointer of type objc_property_t describing the property, or NULL if the class does not declare a property with that name, or NULL if cls is Nil.
    • class_getProperty

      public static long class_getProperty(long cls, CharSequence name)
      Returns a property with a given name of a given class.
      Parameters:
      cls - the class you want to inspect
      name - a C string. Pass the name of the instance variable whose value you wish to modify.
      Returns:
      a pointer of type objc_property_t describing the property, or NULL if the class does not declare a property with that name, or NULL if cls is Nil.
    • nclass_copyPropertyList

      public static long nclass_copyPropertyList(long cls, long outCount)
      Unsafe version of: class_copyPropertyList(long)
      Parameters:
      outCount - on return, contains the length of the returned array. If outCount is NULL, the length is not returned
    • class_copyPropertyList

      @Nullable public static org.lwjgl.PointerBuffer class_copyPropertyList(long cls)
      Describes the properties declared by a class.
      Parameters:
      cls - the class you want to inspect
      Returns:
      an array of pointers of type objc_property_t describing the properties declared by the class. Any properties declared by superclasses are not included. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().

      If cls declares no properties, or cls is Nil, returns NULL and *outCount is 0.

    • nclass_getIvarLayout

      public static long nclass_getIvarLayout(long cls)
      Unsafe version of: class_getIvarLayout(long)
    • class_getIvarLayout

      @Nullable public static String class_getIvarLayout(long cls)
      Returns a description of the Ivar layout for a given class.
      Parameters:
      cls - the class to inspect
      Returns:
      a description of the Ivar layout for cls
    • nclass_getWeakIvarLayout

      public static long nclass_getWeakIvarLayout(long cls)
    • class_getWeakIvarLayout

      @Nullable public static String class_getWeakIvarLayout(long cls)
      Returns a description of the layout of weak Ivars for a given class.
      Parameters:
      cls - the class to inspect
      Returns:
      a description of the layout of the weak Ivars for cls
    • nclass_addMethod

      public static boolean nclass_addMethod(long cls, long name, long imp, long types)
    • class_addMethod

      public static boolean class_addMethod(long cls, long name, long imp, ByteBuffer types)
      Adds a new method to a class with a given name and implementation.
      Discussion

      class_addMethod will add an override of a superclass's implementation, but will not replace an existing implementation in this class. To change an existing implementation, use method_setImplementation(long, long).

      An Objective-C method is simply a C function that takes at least two arguments – self and _cmd. For example, given the following function:

      
       void myMethodIMP(id self, SEL _cmd)
       {
           // implementation ....
       }

      you can dynamically add it to a class as a method (called resolveThisMethodDynamically) like this:

      
       class_addMethod([self class], @selector(resolveThisMethodDynamically), (IMP) myMethodIMP, "v@:");
      Parameters:
      cls - the class to which to add a method
      name - a selector that specifies the name of the method being added
      imp - a function which is the implementation of the new method. The function must take at least two arguments – self and _cmd.
      types - an array of characters that describe the types of the arguments to the method. For possible values, see Objective-C Runtime Programming Guide > Type Encodings in Objective-C Runtime Programming Guide. Since the function must take at least two arguments – self and _cmd, the second and third characters must be “@:” (the first character is the return type).
      Returns:
      YES if the method was added successfully, otherwise NO (for example, the class already contains a method implementation with that name)
    • class_addMethod

      public static boolean class_addMethod(long cls, long name, long imp, CharSequence types)
      Adds a new method to a class with a given name and implementation.
      Discussion

      class_addMethod will add an override of a superclass's implementation, but will not replace an existing implementation in this class. To change an existing implementation, use method_setImplementation(long, long).

      An Objective-C method is simply a C function that takes at least two arguments – self and _cmd. For example, given the following function:

      
       void myMethodIMP(id self, SEL _cmd)
       {
           // implementation ....
       }

      you can dynamically add it to a class as a method (called resolveThisMethodDynamically) like this:

      
       class_addMethod([self class], @selector(resolveThisMethodDynamically), (IMP) myMethodIMP, "v@:");
      Parameters:
      cls - the class to which to add a method
      name - a selector that specifies the name of the method being added
      imp - a function which is the implementation of the new method. The function must take at least two arguments – self and _cmd.
      types - an array of characters that describe the types of the arguments to the method. For possible values, see Objective-C Runtime Programming Guide > Type Encodings in Objective-C Runtime Programming Guide. Since the function must take at least two arguments – self and _cmd, the second and third characters must be “@:” (the first character is the return type).
      Returns:
      YES if the method was added successfully, otherwise NO (for example, the class already contains a method implementation with that name)
    • nclass_replaceMethod

      public static long nclass_replaceMethod(long cls, long name, long imp, long types)
    • class_replaceMethod

      public static long class_replaceMethod(long cls, long name, long imp, ByteBuffer types)
      Replaces the implementation of a method for a given class.
      Discussion

      This function behaves in two different ways:

      • If the method identified by name does not yet exist, it is added as if class_addMethod were called. The type encoding specified by types is used as given.
      • If the method identified by name does exist, its IMP is replaced as if method_setImplementation were called. The type encoding specified by types is ignored.
      Parameters:
      cls - the class you want to modify
      name - a selector that identifies the method whose implementation you want to replace
      imp - the new implementation for the method identified by name for the class identified by cls
      types - an array of characters that describe the types of the arguments to the method. For possible values, see Objective-C Runtime Programming Guide > Type Encodings in Objective-C Runtime Programming Guide. Since the function must take at least two arguments – self and _cmd, the second and third characters must be “@:” (the first character is the return type).
      Returns:
      the previous implementation of the method identified by name for the class identified by cls
    • class_replaceMethod

      public static long class_replaceMethod(long cls, long name, long imp, CharSequence types)
      Replaces the implementation of a method for a given class.
      Discussion

      This function behaves in two different ways:

      • If the method identified by name does not yet exist, it is added as if class_addMethod were called. The type encoding specified by types is used as given.
      • If the method identified by name does exist, its IMP is replaced as if method_setImplementation were called. The type encoding specified by types is ignored.
      Parameters:
      cls - the class you want to modify
      name - a selector that identifies the method whose implementation you want to replace
      imp - the new implementation for the method identified by name for the class identified by cls
      types - an array of characters that describe the types of the arguments to the method. For possible values, see Objective-C Runtime Programming Guide > Type Encodings in Objective-C Runtime Programming Guide. Since the function must take at least two arguments – self and _cmd, the second and third characters must be “@:” (the first character is the return type).
      Returns:
      the previous implementation of the method identified by name for the class identified by cls
    • nclass_addIvar

      public static boolean nclass_addIvar(long cls, long name, long size, byte alignment, long types)
    • class_addIvar

      public static boolean class_addIvar(long cls, ByteBuffer name, long size, byte alignment, ByteBuffer types)
      Adds a new instance variable to a class.

      This function may only be called after objc_allocateClassPair(long, java.nio.ByteBuffer, long) and before objc_registerClassPair(long). Adding an instance variable to an existing class is not supported.

      The class must not be a metaclass. Adding an instance variable to a metaclass is not supported.

      The instance variable's minimum alignment in bytes is 1<<align. The minimum alignment of an instance variable depends on the ivar's type and the machine architecture. For variables of any pointer type, pass log2(sizeof(pointer_type)).

      Returns:
      YES if the instance variable was added successfully, otherwise NO (for example, the class already contains an instance variable with that name)
    • class_addIvar

      public static boolean class_addIvar(long cls, CharSequence name, long size, byte alignment, CharSequence types)
      Adds a new instance variable to a class.

      This function may only be called after objc_allocateClassPair(long, java.nio.ByteBuffer, long) and before objc_registerClassPair(long). Adding an instance variable to an existing class is not supported.

      The class must not be a metaclass. Adding an instance variable to a metaclass is not supported.

      The instance variable's minimum alignment in bytes is 1<<align. The minimum alignment of an instance variable depends on the ivar's type and the machine architecture. For variables of any pointer type, pass log2(sizeof(pointer_type)).

      Returns:
      YES if the instance variable was added successfully, otherwise NO (for example, the class already contains an instance variable with that name)
    • class_addProtocol

      public static boolean class_addProtocol(long cls, long protocol)
      Adds a protocol to a class.
      Parameters:
      cls - the class to modify
      protocol - the protocol to add to cls
      Returns:
      YES if the protocol was added successfully, otherwise NO (for example, the class already conforms to that protocol)
    • nclass_addProperty

      public static boolean nclass_addProperty(long cls, long name, long attributes, int attributeCount)
      Parameters:
      attributeCount - the number of attributes in attributes
    • class_addProperty

      public static boolean class_addProperty(long cls, ByteBuffer name, ObjCPropertyAttribute.Buffer attributes)
      Adds a property to a class.
      Parameters:
      cls - the class to modify
      name - the name of the property
      attributes - an array of property attributes
      Returns:
      YES if the property was added successfully; otherwise NO (for example, this function returns NO if the class already has that property)
    • class_addProperty

      public static boolean class_addProperty(long cls, CharSequence name, ObjCPropertyAttribute.Buffer attributes)
      Adds a property to a class.
      Parameters:
      cls - the class to modify
      name - the name of the property
      attributes - an array of property attributes
      Returns:
      YES if the property was added successfully; otherwise NO (for example, this function returns NO if the class already has that property)
    • nclass_replaceProperty

      public static void nclass_replaceProperty(long cls, long name, long attributes, int attributeCount)
      Parameters:
      attributeCount - the number of attributes in attributes
    • class_replaceProperty

      public static void class_replaceProperty(long cls, ByteBuffer name, ObjCPropertyAttribute.Buffer attributes)
      Replaces a property of a class.
      Parameters:
      cls - the class to modify
      name - the name of the property
      attributes - an array of property attributes
    • class_replaceProperty

      public static void class_replaceProperty(long cls, CharSequence name, ObjCPropertyAttribute.Buffer attributes)
      Replaces a property of a class.
      Parameters:
      cls - the class to modify
      name - the name of the property
      attributes - an array of property attributes
    • nclass_setIvarLayout

      public static void nclass_setIvarLayout(long cls, long layout)
    • class_setIvarLayout

      public static void class_setIvarLayout(long cls, ByteBuffer layout)
      Sets the Ivar layout for a given class.
      Parameters:
      cls - the class to modify
      layout - the layout of the Ivars for cls
    • class_setIvarLayout

      public static void class_setIvarLayout(long cls, CharSequence layout)
      Sets the Ivar layout for a given class.
      Parameters:
      cls - the class to modify
      layout - the layout of the Ivars for cls
    • nclass_setWeakIvarLayout

      public static void nclass_setWeakIvarLayout(long cls, long layout)
    • class_setWeakIvarLayout

      public static void class_setWeakIvarLayout(long cls, ByteBuffer layout)
      Sets the layout for weak Ivars for a given class.
      Parameters:
      cls - the class to modify
      layout - the layout of the weak Ivars for cls
    • class_setWeakIvarLayout

      public static void class_setWeakIvarLayout(long cls, CharSequence layout)
      Sets the layout for weak Ivars for a given class.
      Parameters:
      cls - the class to modify
      layout - the layout of the weak Ivars for cls
    • class_createInstance

      public static long class_createInstance(long cls, long extraBytes)
      Creates an instance of a class, allocating memory for the class in the default malloc memory zone.
      Parameters:
      cls - the class that you want to allocate an instance of
      extraBytes - an integer indicating the number of extra bytes to allocate. The additional bytes can be used to store additional instance variables beyond those defined in the class definition.
      Returns:
      an instance of the class cls
    • nobjc_constructInstance

      public static long nobjc_constructInstance(long cls, long bytes)
    • objc_constructInstance

      public static long objc_constructInstance(long cls, @Nullable ByteBuffer bytes)
      Creates an instance of a class at the specified location.
      Parameters:
      cls - the class that you want to allocate an instance of
      bytes - the location at which to allocate an instance of the cls class. bytes must point to at least class_getInstanceSize(cls) bytes of well-aligned, zero-filled memory.
      Returns:
      an instance of the class cls at bytes, if successful; otherwise nil (for example, if cls or bytes are themselves nil)
    • objc_destructInstance

      public static long objc_destructInstance(long obj)
      Destroys an instance of a class without freeing memory and removes any of its associated references.

      This method does nothing if obj is nil.

      Important

      The garbage collector does not call this function. As a result, if you edit this function, you should also edit finalize. That said, Core Foundation and other clients do call this function under garbage collection.

      Parameters:
      obj - the instance to destroy
    • nobjc_allocateClassPair

      public static long nobjc_allocateClassPair(long superclass, long name, long extraBytes)
    • objc_allocateClassPair

      public static long objc_allocateClassPair(long superclass, ByteBuffer name, long extraBytes)
      Creates a new class and metaclass.

      You can get a pointer to the new metaclass by calling object_getClass(newClass).

      To create a new class, start by calling objc_allocateClassPair. Then set the class's attributes with functions like class_addMethod(long, long, long, java.nio.ByteBuffer) and class_addIvar(long, java.nio.ByteBuffer, long, byte, java.nio.ByteBuffer). When you are done building the class, call objc_registerClassPair(long). The new class is now ready for use.

      Instance methods and instance variables should be added to the class itself. Class methods should be added to the metaclass.

      Parameters:
      superclass - the class to use as the new class's superclass, or Nil to create a new root class
      name - the string to use as the new class's name. The string will be copied.
      extraBytes - the number of bytes to allocate for indexed ivars at the end of the class and metaclass objects. This should usually be 0.
      Returns:
      the new class, or Nil if the class could not be created (for example, the desired name is already in use)
    • objc_allocateClassPair

      public static long objc_allocateClassPair(long superclass, CharSequence name, long extraBytes)
      Creates a new class and metaclass.

      You can get a pointer to the new metaclass by calling object_getClass(newClass).

      To create a new class, start by calling objc_allocateClassPair. Then set the class's attributes with functions like class_addMethod(long, long, long, java.nio.ByteBuffer) and class_addIvar(long, java.nio.ByteBuffer, long, byte, java.nio.ByteBuffer). When you are done building the class, call objc_registerClassPair(long). The new class is now ready for use.

      Instance methods and instance variables should be added to the class itself. Class methods should be added to the metaclass.

      Parameters:
      superclass - the class to use as the new class's superclass, or Nil to create a new root class
      name - the string to use as the new class's name. The string will be copied.
      extraBytes - the number of bytes to allocate for indexed ivars at the end of the class and metaclass objects. This should usually be 0.
      Returns:
      the new class, or Nil if the class could not be created (for example, the desired name is already in use)
    • objc_registerClassPair

      public static void objc_registerClassPair(long cls)
      Registers a class that was allocated using objc_allocateClassPair(long, java.nio.ByteBuffer, long).
      Parameters:
      cls - the class you want to register
    • objc_disposeClassPair

      public static void objc_disposeClassPair(long cls)
      Destroys a class and its associated metaclass.

      Do not call this function if instances of the cls class or any subclass exist.

      Parameters:
      cls - the class to be destroyed. This class must have been allocated using objc_allocateClassPair(long, java.nio.ByteBuffer, long).
    • method_getName

      public static long method_getName(long m)
      Returns the name of a method.

      To get the method name as a C string, call sel_getName(method_getName(method)).

      Parameters:
      m - the method to inspect
      Returns:
      a pointer of type SEL
    • method_getImplementation

      public static long method_getImplementation(long m)
      Returns the implementation of a method.
      Parameters:
      m - the method to inspect
      Returns:
      a function pointer of type IMP
    • nmethod_getTypeEncoding

      public static long nmethod_getTypeEncoding(long m)
      Unsafe version of: method_getTypeEncoding(long)
    • method_getTypeEncoding

      @Nullable public static String method_getTypeEncoding(long m)
      Returns a string describing a method's parameter and return types.
      Parameters:
      m - the method to inspect
      Returns:
      a C string. The string may be NULL
    • method_getNumberOfArguments

      public static int method_getNumberOfArguments(long m)
      Returns the number of arguments accepted by a method.
      Parameters:
      m - a pointer to a Method data structure. Pass the method in question.
      Returns:
      an integer containing the number of arguments accepted by the given method
    • nmethod_copyReturnType

      public static long nmethod_copyReturnType(long m)
      Unsafe version of: method_copyReturnType(long)
    • method_copyReturnType

      @Nullable public static String method_copyReturnType(long m)
      Returns a string describing a method's return type.
      Parameters:
      m - the method to inspect
      Returns:
      a C string describing the return type. You must free the string with free().
    • nmethod_copyArgumentType

      public static long nmethod_copyArgumentType(long m, int index)
    • method_copyArgumentType

      @Nullable public static String method_copyArgumentType(long m, int index)
      Returns a string describing a single parameter type of a method.
      Parameters:
      m - the method to inspect
      index - the index of the parameter to inspect
      Returns:
      a C string describing the type of the parameter at index index, or NULL if method has no parameter index index. You must free the string with free().
    • nmethod_getReturnType

      public static void nmethod_getReturnType(long m, long dst, long dst_len)
      Parameters:
      dst_len - the maximum number of characters that can be stored in dst
    • method_getReturnType

      public static void method_getReturnType(long m, ByteBuffer dst)
      Returns by reference a string describing a method's return type.

      The method's return type string is copied to dst. dst is filled as if strncpy(dst, parameter_type, dst_len) were called.

      Parameters:
      m - the method to inspect
      dst - the reference string to store the description
    • method_getReturnType

      public static String method_getReturnType(long m, long dst_len)
      Returns by reference a string describing a method's return type.

      The method's return type string is copied to dst. dst is filled as if strncpy(dst, parameter_type, dst_len) were called.

      Parameters:
      m - the method to inspect
      dst_len - the maximum number of characters that can be stored in dst
    • nmethod_getArgumentType

      public static void nmethod_getArgumentType(long m, int index, long dst, long dst_len)
      Parameters:
      dst_len - the maximum number of characters that can be stored in dst
    • method_getArgumentType

      public static void method_getArgumentType(long m, int index, ByteBuffer dst)
      Returns by reference a string describing a single parameter type of a method.

      The parameter type string is copied to dst. dst is filled as if strncpy(dst, parameter_type, dst_len) were called. If the method contains no parameter with that index, dst is filled as if strncpy(dst, "", dst_len) were called.

      Parameters:
      m - the method you want to inquire about
      index - the index of the parameter you want to inquire about
      dst - the reference string to store the description
    • method_getArgumentType

      public static String method_getArgumentType(long m, int index, long dst_len)
      Returns by reference a string describing a single parameter type of a method.

      The parameter type string is copied to dst. dst is filled as if strncpy(dst, parameter_type, dst_len) were called. If the method contains no parameter with that index, dst is filled as if strncpy(dst, "", dst_len) were called.

      Parameters:
      m - the method you want to inquire about
      index - the index of the parameter you want to inquire about
      dst_len - the maximum number of characters that can be stored in dst
    • method_setImplementation

      public static long method_setImplementation(long m, long imp)
      Sets the implementation of a method.
      Parameters:
      m - the method for which to set an implementation
      imp - the implemention to set to this method
      Returns:
      the previous implementation of the method
    • method_exchangeImplementations

      public static void method_exchangeImplementations(long m1, long m2)
      Exchanges the implementations of two methods.
      Parameters:
      m1 - the method to exchange with second method
      m2 - the method to exchange with first method
    • nivar_getName

      public static long nivar_getName(long v)
      Unsafe version of: ivar_getName(long)
    • ivar_getName

      @Nullable public static String ivar_getName(long v)
      Returns the name of an instance variable.
      Parameters:
      v - the instance variable
      Returns:
      a C string containing the instance variable's name
    • nivar_getTypeEncoding

      public static long nivar_getTypeEncoding(long v)
      Unsafe version of: ivar_getTypeEncoding(long)
    • ivar_getTypeEncoding

      @Nullable public static String ivar_getTypeEncoding(long v)
      Returns the type string of an instance variable.
      Parameters:
      v - the instance variable
      Returns:
      a C string containing the instance variable's type encoding
    • ivar_getOffset

      public static long ivar_getOffset(long v)
      Returns the offset of an instance variable.

      For instance variables of type id or other object types, call object_getIvar(long, long) and object_setIvar(long, long, long) instead of using this offset to access the instance variable data directly.

      Parameters:
      v - the instance variable
      Returns:
      the offset of v
    • nproperty_getName

      public static long nproperty_getName(long property)
      Unsafe version of: property_getName(long)
    • property_getName

      @Nullable public static String property_getName(long property)
      Returns the name of a property.
      Parameters:
      property - the property you want to inquire about
      Returns:
      a C string containing the property's name
    • nproperty_getAttributes

      public static long nproperty_getAttributes(long property)
      Unsafe version of: property_getAttributes(long)
    • property_getAttributes

      @Nullable public static String property_getAttributes(long property)
      Returns the attribute string of a property.
      Parameters:
      property - a property
      Returns:
      a C string containing the property's attributes
    • nproperty_copyAttributeList

      public static long nproperty_copyAttributeList(long property, long outCount)
      Parameters:
      outCount - the number of attributes returned in the array
    • property_copyAttributeList

      @Nullable public static ObjCPropertyAttribute.Buffer property_copyAttributeList(long property)
      Returns an array of property attributes for a given property.
      Parameters:
      property - the property whose attributes you want to copy
      Returns:
      an array of property attributes. You must free the array with free().
    • nproperty_copyAttributeValue

      public static long nproperty_copyAttributeValue(long property, long attributeName)
    • property_copyAttributeValue

      @Nullable public static String property_copyAttributeValue(long property, ByteBuffer attributeName)
      Returns the value of a property attribute given the attribute name.
      Parameters:
      property - the property whose value you are interested in
      attributeName - a C string representing the name of the attribute
      Returns:
      The value string of the attributeName attribute, if one exists in property; otherwise, nil. You must free the returned value string with free().
    • property_copyAttributeValue

      @Nullable public static String property_copyAttributeValue(long property, CharSequence attributeName)
      Returns the value of a property attribute given the attribute name.
      Parameters:
      property - the property whose value you are interested in
      attributeName - a C string representing the name of the attribute
      Returns:
      The value string of the attributeName attribute, if one exists in property; otherwise, nil. You must free the returned value string with free().
    • nobjc_getProtocol

      public static long nobjc_getProtocol(long name)
    • objc_getProtocol

      public static long objc_getProtocol(ByteBuffer name)
      Returns a specified protocol.

      This function acquires the runtime lock.

      Parameters:
      name - the name of a protocol
      Returns:
      the protocol named name{, or NULL if no protocol named name could be found
    • objc_getProtocol

      public static long objc_getProtocol(CharSequence name)
      Returns a specified protocol.

      This function acquires the runtime lock.

      Parameters:
      name - the name of a protocol
      Returns:
      the protocol named name{, or NULL if no protocol named name could be found
    • nobjc_copyProtocolList

      public static long nobjc_copyProtocolList(long outCount)
      Unsafe version of: objc_copyProtocolList()
      Parameters:
      outCount - upon return, contains the number of protocols in the returned array
    • objc_copyProtocolList

      @Nullable public static org.lwjgl.PointerBuffer objc_copyProtocolList()
      Returns an array of all the protocols known to the runtime.
      Returns:
      a C array of all the protocols known to the runtime. The array contains *outCount pointers followed by a NULL terminator. You must free the list with free().
    • protocol_conformsToProtocol

      public static boolean protocol_conformsToProtocol(long proto, long other)
      Returns a Boolean value that indicates whether one protocol conforms to another protocol.
      Discussion

      One protocol can incorporate other protocols using the same syntax that classes use to adopt a protocol:

      @protocol ProtocolName < protocol list >

      All the protocols listed between angle brackets are considered part of the ProtocolName protocol.

      Parameters:
      proto - a protocol
      other - a protocol
      Returns:
      YES if proto conforms to other, otherwise NO
    • protocol_isEqual

      public static boolean protocol_isEqual(long proto, long other)
      Returns a Boolean value that indicates whether two protocols are equal.
      Parameters:
      proto - a protocol
      other - a protocol
      Returns:
      YES if proto is the same as other, otherwise NO
    • nprotocol_getName

      public static long nprotocol_getName(long p)
      Unsafe version of: protocol_getName(long)
    • protocol_getName

      @Nullable public static String protocol_getName(long p)
      Returns a the name of a protocol.
      Parameters:
      p - a protocol
      Returns:
      the name of the protocol p as a C string
    • nprotocol_getMethodDescription

      public static void nprotocol_getMethodDescription(long p, long aSel, boolean isRequiredMethod, boolean isInstanceMethod, long __functionAddress, long __result)
    • nprotocol_getMethodDescription

      public static void nprotocol_getMethodDescription(long p, long aSel, boolean isRequiredMethod, boolean isInstanceMethod, long __result)
    • protocol_getMethodDescription

      public static ObjCMethodDescription protocol_getMethodDescription(long p, long aSel, boolean isRequiredMethod, boolean isInstanceMethod, ObjCMethodDescription __result)
      Returns a method description structure for a specified method of a given protocol.
      Parameters:
      p - a protocol
      aSel - a selector
      isRequiredMethod - a Boolean value that indicates whether aSel is a required method
      isInstanceMethod - a Boolean value that indicates whether aSel is a instance method
      __result - an objc_method_description structure that describes the method specified by aSel, isRequiredMethod, and isInstanceMethod for the protocol p.

      If the protocol does not contain the specified method, returns an objc_method_description structure with the value {NULL, NULL}.

    • nprotocol_copyMethodDescriptionList

      public static long nprotocol_copyMethodDescriptionList(long p, boolean isRequiredMethod, boolean isInstanceMethod, long outCount)
      Parameters:
      outCount - upon return, contains the number of method description structures in the returned array
    • protocol_copyMethodDescriptionList

      @Nullable public static ObjCMethodDescription.Buffer protocol_copyMethodDescriptionList(long p, boolean isRequiredMethod, boolean isInstanceMethod)
      Returns an array of method descriptions of methods meeting a given specification for a given protocol.

      Methods in other protocols adopted by this protocol are not included.

      Parameters:
      p - a protocol
      isRequiredMethod - a Boolean value that indicates whether returned methods should be required methods (pass YES to specify required methods)
      isInstanceMethod - a Boolean value that indicates whether returned methods should be instance methods (pass YES to specify instance methods)
      Returns:
      a C array of objc_method_description structures containing the names and types of p's methods specified by isRequiredMethod and isInstanceMethod. The array contains *outCount pointers followed by a NULL terminator. You must free the list with free().

      If the protocol declares no methods that meet the specification, NULL is returned and *outCount is 0.

    • nprotocol_getProperty

      public static long nprotocol_getProperty(long proto, long name, boolean isRequiredProperty, boolean isInstanceProperty)
    • protocol_getProperty

      public static long protocol_getProperty(long proto, ByteBuffer name, boolean isRequiredProperty, boolean isInstanceProperty)
      Returns the specified property of a given protocol.
      Parameters:
      proto - a protocol
      name - the name of a property
      isRequiredProperty - a Boolean value that indicates whether name is a required property
      isInstanceProperty - a Boolean value that indicates whether name is a instance property
      Returns:
      the property specified by name, isRequiredProperty, and isInstanceProperty for proto, or NULL if none of proto's properties meets the specification
    • protocol_getProperty

      public static long protocol_getProperty(long proto, CharSequence name, boolean isRequiredProperty, boolean isInstanceProperty)
      Returns the specified property of a given protocol.
      Parameters:
      proto - a protocol
      name - the name of a property
      isRequiredProperty - a Boolean value that indicates whether name is a required property
      isInstanceProperty - a Boolean value that indicates whether name is a instance property
      Returns:
      the property specified by name, isRequiredProperty, and isInstanceProperty for proto, or NULL if none of proto's properties meets the specification
    • nprotocol_copyPropertyList

      public static long nprotocol_copyPropertyList(long proto, long outCount)
      Parameters:
      outCount - upon return, contains the number of elements in the returned array
    • protocol_copyPropertyList

      @Nullable public static org.lwjgl.PointerBuffer protocol_copyPropertyList(long proto)
      Returns an array of the properties declared by a protocol.
      Parameters:
      proto - a protocol
      Returns:
      a C array of pointers of type objc_property_t describing the properties declared by proto. Any properties declared by other protocols adopted by this protocol are not included. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().

      If the protocol declares no properties, NULL is returned and *outCount is 0.

    • nprotocol_copyProtocolList

      public static long nprotocol_copyProtocolList(long proto, long outCount)
      Parameters:
      outCount - upon return, contains the number of elements in the returned array
    • protocol_copyProtocolList

      @Nullable public static org.lwjgl.PointerBuffer protocol_copyProtocolList(long proto)
      eturns an array of the protocols adopted by a protocol.
      Parameters:
      proto - a protocol
      Returns:
      a C array of protocols adopted by proto. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().

      If the protocol declares no properties, NULL is returned and *outCount is 0.

    • nobjc_allocateProtocol

      public static long nobjc_allocateProtocol(long name)
    • objc_allocateProtocol

      public static long objc_allocateProtocol(ByteBuffer name)
      Creates a new protocol instance.

      You must register the returned protocol instance with the objc_registerProtocol(long) function before you can use it.

      There is no dispose method associated with this function.

      Parameters:
      name - the name of the protocol you want to create
      Returns:
      a new protocol instance or nil if a protocol with the same name as name already exists
    • objc_allocateProtocol

      public static long objc_allocateProtocol(CharSequence name)
      Creates a new protocol instance.

      You must register the returned protocol instance with the objc_registerProtocol(long) function before you can use it.

      There is no dispose method associated with this function.

      Parameters:
      name - the name of the protocol you want to create
      Returns:
      a new protocol instance or nil if a protocol with the same name as name already exists
    • objc_registerProtocol

      public static void objc_registerProtocol(long proto)
      Registers a newly created protocol with the Objective-C runtime.

      When you create a new protocol using the objc_allocateProtocol(java.nio.ByteBuffer), you then register it with the Objective-C runtime by calling this function. After a protocol is successfully registered, it is immutable and ready to use.

      Parameters:
      proto - the protocol you want to register with the Objective-C runtime
    • nprotocol_addMethodDescription

      public static void nprotocol_addMethodDescription(long proto, long name, long types, boolean isRequiredMethod, boolean isInstanceMethod)
    • protocol_addMethodDescription

      public static void protocol_addMethodDescription(long proto, long name, ByteBuffer types, boolean isRequiredMethod, boolean isInstanceMethod)
      Adds a method to a protocol.

      To add a method to a protocol using this function, the protocol must be under construction. That is, you must add any methods to proto before you register it with the Objective-C runtime (via the objc_registerProtocol(long) function).

      Parameters:
      proto - the protocol you want to add a method to
      name - the name of the method you want to add
      types - a C string representing the signature of the method you want to add
      isRequiredMethod - a Boolean indicating whether the method is a required method of the proto protocol. If YES, the method is a required method; if NO, the method is an optional method.
      isInstanceMethod - a Boolean indicating whether the method is an instance method. If YES, the method is an instance method; if NO, the method is a class method.
    • protocol_addMethodDescription

      public static void protocol_addMethodDescription(long proto, long name, CharSequence types, boolean isRequiredMethod, boolean isInstanceMethod)
      Adds a method to a protocol.

      To add a method to a protocol using this function, the protocol must be under construction. That is, you must add any methods to proto before you register it with the Objective-C runtime (via the objc_registerProtocol(long) function).

      Parameters:
      proto - the protocol you want to add a method to
      name - the name of the method you want to add
      types - a C string representing the signature of the method you want to add
      isRequiredMethod - a Boolean indicating whether the method is a required method of the proto protocol. If YES, the method is a required method; if NO, the method is an optional method.
      isInstanceMethod - a Boolean indicating whether the method is an instance method. If YES, the method is an instance method; if NO, the method is a class method.
    • protocol_addProtocol

      public static void protocol_addProtocol(long proto, long addition)
      Adds a registered protocol to another protocol that is under construction.

      The protocol you want to add to (proto) must be under construction – allocated but not yet registered with the Objective-C runtime. The protocol you want to add (addition) must be registered already.

      Parameters:
      proto - the protocol you want to add the registered protocol to
      addition - the registered protocol you want to add to proto
    • nprotocol_addProperty

      public static void nprotocol_addProperty(long proto, long name, long attributes, int attributeCount, boolean isRequiredProperty, boolean isInstanceProperty)
      Parameters:
      attributeCount - the number of properties in attributes
    • protocol_addProperty

      public static void protocol_addProperty(long proto, ByteBuffer name, ObjCPropertyAttribute.Buffer attributes, boolean isRequiredProperty, boolean isInstanceProperty)
      Adds a property to a protocol that is under construction.

      The protocol you want to add the property to must be under construction – allocated but not yet registered with the Objective-C runtime (via the objc_registerProtocol(long) function).

      Parameters:
      proto - the protocol you want to add a property to
      name - the name of the property you want to add.
      attributes - an array of property attributes
      isRequiredProperty - a Boolean indicating whether the property's accessor methods are required methods of the proto protocol. If YES, the property's accessor methods are required methods; if NO, the property's accessor methods are optional methods.
      isInstanceProperty - a Boolean indicating whether the property's accessor methods are instance methods. If YES, the property's accessor methods are instance methods. YES is the only value allowed for a property. As a result, if you set this value to NO, the property will not be added to the protocol.
    • protocol_addProperty

      public static void protocol_addProperty(long proto, CharSequence name, ObjCPropertyAttribute.Buffer attributes, boolean isRequiredProperty, boolean isInstanceProperty)
      Adds a property to a protocol that is under construction.

      The protocol you want to add the property to must be under construction – allocated but not yet registered with the Objective-C runtime (via the objc_registerProtocol(long) function).

      Parameters:
      proto - the protocol you want to add a property to
      name - the name of the property you want to add.
      attributes - an array of property attributes
      isRequiredProperty - a Boolean indicating whether the property's accessor methods are required methods of the proto protocol. If YES, the property's accessor methods are required methods; if NO, the property's accessor methods are optional methods.
      isInstanceProperty - a Boolean indicating whether the property's accessor methods are instance methods. If YES, the property's accessor methods are instance methods. YES is the only value allowed for a property. As a result, if you set this value to NO, the property will not be added to the protocol.
    • nobjc_copyImageNames

      public static long nobjc_copyImageNames(long outCount)
      Unsafe version of: objc_copyImageNames()
      Parameters:
      outCount - the number of names in the returned array
    • objc_copyImageNames

      @Nullable public static org.lwjgl.PointerBuffer objc_copyImageNames()
      Returns the names of all the loaded Objective-C frameworks and dynamic libraries.
      Returns:
      an array of C strings representing the names of all the loaded Objective-C frameworks and dynamic libraries
    • nclass_getImageName

      public static long nclass_getImageName(long cls)
      Unsafe version of: class_getImageName(long)
    • class_getImageName

      @Nullable public static String class_getImageName(long cls)
      Returns the name of the dynamic library a class originated from.
      Parameters:
      cls - the class you are inquiring about
      Returns:
      a C string representing the name of the library containing the cls class.
    • nobjc_copyClassNamesForImage

      public static long nobjc_copyClassNamesForImage(long image, long outCount)
      Parameters:
      outCount - the number of names in the returned array
    • objc_copyClassNamesForImage

      @Nullable public static org.lwjgl.PointerBuffer objc_copyClassNamesForImage(ByteBuffer image)
      Returns the names of all the classes within a specified library or framework.
      Parameters:
      image - the library or framework you are inquiring about
      Returns:
      an array of C strings representing all of the class names within the specified library or framework
    • objc_copyClassNamesForImage

      @Nullable public static org.lwjgl.PointerBuffer objc_copyClassNamesForImage(CharSequence image)
      Returns the names of all the classes within a specified library or framework.
      Parameters:
      image - the library or framework you are inquiring about
      Returns:
      an array of C strings representing all of the class names within the specified library or framework
    • nsel_getName

      public static long nsel_getName(long sel)
      Unsafe version of: sel_getName(long)
    • sel_getName

      @Nullable public static String sel_getName(long sel)
      Returns the name of the method specified by a given selector.
      Parameters:
      sel - a pointer of type SEL. Pass the selector whose name you wish to determine.
      Returns:
      a C string indicating the name of the selector
    • nsel_getUid

      public static long nsel_getUid(long str)
    • sel_getUid

      public static long sel_getUid(ByteBuffer str)
      Registers a method name with the Objective-C runtime system.

      The implementation of this method is identical to the implementation of sel_registerName(java.nio.ByteBuffer).

      Parameters:
      str - a pointer to a C string. Pass the name of the method you wish to register
      Returns:
      a pointer of type SEL specifying the selector for the named method
    • sel_getUid

      public static long sel_getUid(CharSequence str)
      Registers a method name with the Objective-C runtime system.

      The implementation of this method is identical to the implementation of sel_registerName(java.nio.ByteBuffer).

      Parameters:
      str - a pointer to a C string. Pass the name of the method you wish to register
      Returns:
      a pointer of type SEL specifying the selector for the named method
    • nsel_registerName

      public static long nsel_registerName(long str)
    • sel_registerName

      public static long sel_registerName(ByteBuffer str)
      Registers a method with the Objective-C runtime system, maps the method name to a selector, and returns the selector value.

      You must register a method name with the Objective-C runtime system to obtain the method’s selector before you can add the method to a class definition. If the method name has already been registered, this function simply returns the selector.

      Parameters:
      str - a pointer to a C string. Pass the name of the method you wish to register
      Returns:
      a pointer of type SEL specifying the selector for the named method
    • sel_registerName

      public static long sel_registerName(CharSequence str)
      Registers a method with the Objective-C runtime system, maps the method name to a selector, and returns the selector value.

      You must register a method name with the Objective-C runtime system to obtain the method’s selector before you can add the method to a class definition. If the method name has already been registered, this function simply returns the selector.

      Parameters:
      str - a pointer to a C string. Pass the name of the method you wish to register
      Returns:
      a pointer of type SEL specifying the selector for the named method
    • sel_isEqual

      public static boolean sel_isEqual(long lhs, long rhs)
      Returns a Boolean value that indicates whether two selectors are equal.

      sel_isEqual is equivalent to ==.

      Parameters:
      lhs - the selector to compare with rhs
      rhs - the selector to compare with lhs
      Returns:
      YES if rhs and rhs are equal, otherwise NO
    • objc_enumerationMutation

      public static void objc_enumerationMutation(long obj)
      Inserted by the compiler when a mutation is detected during a foreach iteration.

      The compiler inserts this function when it detects that an object is mutated during a foreach iteration. The function is called when a mutation occurs, and the enumeration mutation handler is enacted if it is set up (via the objc_setEnumerationMutationHandler(org.lwjgl.system.macosx.EnumerationMutationHandlerI) function). If the handler is not set up, a fatal error occurs.

      Parameters:
      obj - the object being mutated
    • nobjc_setEnumerationMutationHandler

      public static void nobjc_setEnumerationMutationHandler(long handler)
    • objc_setEnumerationMutationHandler

      public static void objc_setEnumerationMutationHandler(EnumerationMutationHandlerI handler)
      Sets the current mutation handler.
      Parameters:
      handler - a function pointer to the new mutation handler
    • imp_implementationWithBlock

      public static long imp_implementationWithBlock(long block)
      Creates a pointer to a function that calls the specified block when the method is called.
      Parameters:
      block - the block that implements this method. The signature of block should be method_return_type ^(id self, self, method_args …). The selector of the method is not available to block. block is copied with Block_copy().
      Returns:
      the IMP that calls block. You must dispose of the returned IMP using the function.
    • imp_getBlock

      public static long imp_getBlock(long anImp)
      Returns the block associated with an IMP that was created using imp_implementationWithBlock(long).
      Parameters:
      anImp - the IMP that calls this block
      Returns:
      the block called by anImp
    • imp_removeBlock

      public static boolean imp_removeBlock(long anImp)
      Disassociates a block from an IMP that was created using imp_implementationWithBlock(long), and releases the copy of the block that was created.
      Parameters:
      anImp - an IMP that was created using the imp_implementationWithBlock(long) function.
      Returns:
      YES if the block was released successfully; otherwise, NO (for example, the function returns NO if the block was not used to create anImp previously).
    • nobjc_loadWeak

      public static long nobjc_loadWeak(long location)
    • objc_loadWeak

      public static long objc_loadWeak(@Nullable org.lwjgl.PointerBuffer location)
      Loads the object referenced by a weak pointer and returns it.

      This function loads the object referenced by a weak pointer and returns it after retaining and autoreleasing the object. As a result, the object stays alive long enough for the caller to use it. This function is typically used anywhere a __weak variable is used in an expression.

      Parameters:
      location - the address of the weak pointer
      Returns:
      the object pointed to by location, or nil if location is nil
    • nobjc_storeWeak

      public static long nobjc_storeWeak(long location, long obj)
    • objc_storeWeak

      public static long objc_storeWeak(org.lwjgl.PointerBuffer location, long obj)
      Stores a new value in a __weak variable.

      This function is typically used anywhere a __weak variable is the target of an assignment.

      Parameters:
      location - the address of the weak pointer
      obj - the new object you want the weak pointer to now point to
      Returns:
      the value stored in location (that is, obj)
    • objc_setAssociatedObject

      public static void objc_setAssociatedObject(long object, long key, long value, long policy)
      Sets an associated value for a given object using a given key and association policy.
      Parameters:
      object - the source object for the association
      key - the key for the association
      value - the value to associate with the key key for object. Pass nil to clear an existing association.
      policy - the policy for the association. One of:
      OBJC_ASSOCIATION_ASSIGNOBJC_ASSOCIATION_RETAIN_NONATOMICOBJC_ASSOCIATION_COPY_NONATOMIC
      OBJC_ASSOCIATION_RETAINOBJC_ASSOCIATION_COPY
    • objc_getAssociatedObject

      public static long objc_getAssociatedObject(long object, long key)
      Returns the value associated with a given object for a given key.
      Parameters:
      object - the source object for the association
      key - the key for the association
      Returns:
      the value associated with the key key for object.
    • objc_removeAssociatedObjects

      public static void objc_removeAssociatedObjects(long object)
      Removes all associations for a given object.

      The main purpose of this function is to make it easy to return an object to a "pristine state". You should not use this function for general removal of associations from objects, since it also removes associations that other clients may have added to the object. Typically you should use objc_setAssociatedObject(long, long, long, long) with a nil value to clear an association.

      Parameters:
      object - an object that maintains associated objects