AngelScript
 
Loading...
Searching...
No Matches
The variable parameter type

The application can register functions that take a reference to a variable type, which means that the function can receive a reference to a variable of any type. This is useful when making generic containers.

When a function is registered with this special parameter type, the function will receive both the reference and an extra argument with the type id of the variable type. The reference refers to the actual value that the caller sent, i.e. if the expression is an object handle then the reference will refer to the handle, not the actual object.

// An example usage with a native function
engine->RegisterGlobalFunction("void func_c(?&in)", asFUNCTION(func_c), asCALL_CDECL);
void func_c(void *ref, int typeId)
{
// Do something with the reference
// The type of the reference is determined through the type id
}
// An example usage with a generic function
engine->RegisterGlobalFunction("void func_g(?&in)", asFUNCTION(func_g), asCALL_GENERIC);
void func_g(asIScriptGeneric *gen)
{
void *ref = gen->GetArgAddress(0);
int typeId = gen->GetArgTypeId(0);
func_c(ref, typeId);
}
@ asCALL_CDECL
A cdecl function.
Definition: angelscript.h:305
@ asCALL_GENERIC
A function using the generic calling convention.
Definition: angelscript.h:317
#define asFUNCTION(f)
Returns an asSFuncPtr representing the function specified by the name.
Definition: angelscript.h:708
The interface for the generic calling convention.
Definition: angelscript.h:3450
virtual int GetArgTypeId(asUINT arg, asDWORD *flags=0) const =0
Returns the type id of the argument.
virtual void * GetArgAddress(asUINT arg)=0
Returns the address held in a reference or handle argument.

The variable type can also be used with out references, but not with inout references. Currently it can only be used with global functions, object constructors, and object methods. It cannot be used with other behaviours and operators.

The variable type is not available within scripts, so it can only be used to register application functions.

See also
any object and dictionary object for examples

Variable conversion operators

The variable parameter type can also be used in special versions of the opConv and opCast operator overloads. This is especially useful for generic container types that need to be able to hold any type of content.

  • void opCast(?&out)
  • void opConv(?&out)
See also
ref object and dictionary object for examples