API Documentation
Public Member Functions | List of all members
nkScripts::UserType Class Referenceabstract

Represents a user type and all the information and control related. More...

Public Member Functions

 UserType (nkMemory::StringView name) noexcept
 
virtual ~UserType ()
 
nkMemory::StringView getName () const
 
nkMemory::StringView getFullName () const
 
virtual FunctiongetMethod (nkMemory::StringView name)=0
 
virtual FunctiongetStaticMethod (nkMemory::StringView name)=0
 
virtual void setConstructor (ConstructorCallback constructor)=0
 
virtual void setDestructor (DestructorCallback destructor)=0
 
virtual FunctionaddMethod (nkMemory::StringView name, bool strongReferenceOverThis=false)=0
 
virtual FunctionaddStaticMethod (nkMemory::StringView name)=0
 
virtual FunctionoverrideBuiltInFunction (TYPE_BUILT_IN_FUNCTIONS builtInFunc)=0
 
virtual void addField (const UserTypeFieldDescriptor &fieldDescriptor)=0
 
virtual void enableArrayIndexing (const ArrayAccessorDescriptor &descriptor)=0
 
virtual void reset ()=0
 

Detailed Description

Represents a user type and all the information and control related.

Current information is true for the lua environment, especially.

Principle

User types are types defined from the C++ API, and addressable within the script environment. A User type is given by a pointer to an object, and an identifier string, that identifies it within the scripting environment.

Ownership

When an object is given in an Environment through external API calls, the C++ environment is considered as the owner of the memory. This means that garbage collection won't happen when the object is collected. However, if the object is allocated within the scripting environment (through a call to new()), then the environment is considered owner, and the memory will be freed when garbage collection happens. To override the creation and garbage collection of an object, see setConstructor() and setDestructor(). External code should provide the way to create and garbage collect user types when needed. They usually go in pair.

Constructor & Destructor Documentation

◆ UserType()

nkScripts::UserType::UserType ( nkMemory::StringView  name)
noexcept

Constructor.

Parameters
nameThe user type name.

◆ ~UserType()

virtual nkScripts::UserType::~UserType ( )
virtual

Destructor.

Member Function Documentation

◆ getName()

nkMemory::StringView nkScripts::UserType::getName ( ) const
Returns
The user type's name.

◆ getFullName()

nkMemory::StringView nkScripts::UserType::getFullName ( ) const
Returns
The fully qualified user type's name (with namespaces prefixed).

◆ getMethod()

virtual Function* nkScripts::UserType::getMethod ( nkMemory::StringView  name)
pure virtual
Parameters
nameThe name of the method to get.
Returns
The method linked to the name specified if existant, nullptr else.

◆ getStaticMethod()

virtual Function* nkScripts::UserType::getStaticMethod ( nkMemory::StringView  name)
pure virtual
Parameters
nameThe name of the static method to get.
Returns
The static method linked to the name specified if existant, nullptr else.

◆ setConstructor()

virtual void nkScripts::UserType::setConstructor ( ConstructorCallback  constructor)
pure virtual

Sets the user type constructor. Called when an object is created within a script.

Parameters
constructorThe constructor callback to use.

◆ setDestructor()

virtual void nkScripts::UserType::setDestructor ( DestructorCallback  destructor)
pure virtual

Sets the user type destructor. Called when an object the environment is responsible for gets garbage collected.

Parameters
destructorThe destructor callback to use.

◆ addMethod()

virtual Function* nkScripts::UserType::addMethod ( nkMemory::StringView  name,
bool  strongReferenceOverThis = false 
)
pure virtual

Adds a callable method to the user type.

Parameters
nameThe method's name.
strongReferenceOverThisWhether the first argument, user value over the caller, should have a strong reference (true) or not (false).
Returns
The function created. The UserType owns the memory, external code should not delete it.
Remarks
A non-static method will receive in the stack a user value, as its first argument, pointing to the caller. If the reference is weak, then only the pointer will be retrieved (equivalent to FUNCTION_PARAMETER_TYPE::USER_DATA_PTR). If the reference is strong, then the script reference is also provided (equivalent to FUNCTION_PARAMETER_TYPE::USER_DATA). A strong reference can be desired for instance to safely return a reference over the caller, by returning the reference given as a parameter.

◆ addStaticMethod()

virtual Function* nkScripts::UserType::addStaticMethod ( nkMemory::StringView  name)
pure virtual

Adds a callable static method to the user type.

Parameters
nameThe static method's name.
Returns
The function created. The UserType owns the memory, external code should not delete it.

◆ overrideBuiltInFunction()

virtual Function* nkScripts::UserType::overrideBuiltInFunction ( TYPE_BUILT_IN_FUNCTIONS  builtInFunc)
pure virtual

Overrides a built in operator for the user type.

Parameters
builtInFuncThe function to override.
Returns
The function created. The UserType owns the memory, external code should not delete it.

◆ addField()

virtual void nkScripts::UserType::addField ( const UserTypeFieldDescriptor fieldDescriptor)
pure virtual

Adds a field within the user type.

Parameters
fieldDescriptorThe description of the field to create.

◆ enableArrayIndexing()

virtual void nkScripts::UserType::enableArrayIndexing ( const ArrayAccessorDescriptor descriptor)
pure virtual

Enables indexing the user type as an array.

Parameters
descriptorThe description of the accessing method.

◆ reset()

virtual void nkScripts::UserType::reset ( )
pure virtual

Resets the user type. Frees all methods, static methods, fields, and access descriptions.


The documentation for this class was generated from the following file: