Runtime Reference

File
XSFoundation/include/XS/Functions/Runtime.h
Author
Jean-David Gadina - www.xs-labs.com
Copyright
© (c) 2020 - Jean-David Gadina - www.xs-labs.com
Date
Sunday, September 27, 2020

Overview

Runtime functions

Tasks

XSRuntimeCreateInstance

Initializes a new instance of a registered class

XS_EXPORT XSMutableObjectRef XSRuntimeCreateInstance( XSClassID classID );

Parameters
  • classID
    The class type ID
Return value

The allocated instance

XSRuntimeCreateInstanceOfClassNamed

Initializes a new instance of a class with a specific name

XS_EXPORT XSMutableObjectRef XSRuntimeCreateInstanceOfClassNamed( const char *name );

Parameters
  • name
    The name of the class
Return value

The allocated instance

XSRuntimeGetClassID

Gets the class type ID for an object

XS_EXPORT XSClassID XSRuntimeGetClassID( XSObjectRef object );

Parameters
  • object
    The object
Return value

The class type ID for the object

XSRuntimeGetClassIDOfClassNamed

Gets the class type ID for a class with a specific name

XS_EXPORT XSClassID XSRuntimeGetClassIDOfClassNamed( const char *className );

Parameters
  • className
    The name of the class
Return value

The class type ID

XSRuntimeGetClassName

Gets the class name for an class type ID

XS_EXPORT const char * XSRuntimeGetClassName( XSClassID classID );

Parameters
  • classID
    The class type ID
Return value

The name of the class

XSRuntimeGetClassType

Gets the class type for an class type ID

XS_EXPORT XSClassType XSRuntimeGetClassType( XSClassID classID );

Parameters
  • classID
    The class type ID
Return value

The type of the class

XSRuntimeGetDescription

Gets an object's description

XS_EXPORT const char * XSRuntimeGetDescription( XSObjectRef object );

Parameters
  • object
    The pointer to the object
Return value

The object's description

XSRuntimeGetSharedInstance

Gets the shared instance of a registered class

XS_EXPORT XSObjectRef XSRuntimeGetSharedInstance( XSClassID classID );

Parameters
  • classID
    The class type ID
Return value

The shared instance if it exists, otherwise NULL

XSRuntimeInitialize

Initializes the XSFoundation runtime

XS_EXPORT void XSRuntimeInitialize( void );

Discussion

This function must be called before using any XSFoundation function.

XSRuntimeIsInstance

Checks whether a pointer is an object instance

XS_EXPORT bool XSRuntimeIsInstance( const void *ptr );

Parameters
  • ptr
    The pointer to check
Return value

True if the pointer represents an instance, otherwise false

XSRuntimeIsRegisteredClass

Checks whether a class type ID corresponds to a registered class

XS_EXPORT bool XSRuntimeIsRegisteredClass( XSClassID classID );

Parameters
  • classID
    The class type ID
Return value

True if the class ID represents an valid class, otherwise false

XSRuntimeRegisterClass

Registers a class for the runtime

XS_EXPORT XSClassID XSRuntimeRegisterClass( const XSClassInfo *cls );

Discussion

All runtime classes needs to be registered before the runtime can use them and create instances. This function needs to be called once per class, ie using pthread_once().

Parameters
  • cls
    The class information structure to register
Return value

The runtime type ID for the class

XSRuntimeRegisterFinalizer

Registers a finalizer function, to be called when the program exits

void XSRuntimeRegisterFinalizer( void ( *func )( void ) );

Discussion

Based on its address, a finalizer function will only be registered once.

Parameters
  • func
    The finalizer function