MPR Universal Variable C API
Detailed DescriptionMPR Universal Variable Type.
The MPR Variable module provides routines to create and manage a universal variable type. These variable types can efficiently store primitive data types such as integers, strings, booleans or floating point numbers. They can also hold references to objects.
It is used by Embedded JavaScript to store JavaScript variables and objects and by Embedded Server Pages. The following API may be used by these services to create and manage variables and objects.
A variable may store one of the following types:
- boolean
- floating point
- integer
- 64 bit integer
- string
- C function or C++ method
- C function with string args
- Javascript function
- Null value.
- Undefined value
Objects can hold object properties which are themselves MPR variables. Properties can be primitive data types, object types or functions. Properties are hash indexed by a character name. Objects may be referenced by multiple variables and they use reference counting as part of a for garbage collection mechanism.
This module is not thread safe for performance and compactness. It relies on upper modules to provide thread synchronization as required. The API provides primitives to get variable/object references or to get copies of variables which should help minimize required lock times.
|
Defines
|
#define |
MPR_DEEP_COPY 2
|
#define |
MPR_ENUM_DATA 0x1
|
#define |
MPR_ENUM_FUNCTIONS 0x2
|
#define |
MPR_NO_COPY 0
|
#define |
MPR_NUM_VAR BLD_FEATURE_NUM_TYPE_ID
|
#define |
MPR_SHALLOW_COPY 1
|
#define
|
MPR_TYPE_BOOL 2
|
|
Boolean type.
|
#define
|
MPR_TYPE_CFUNCTION 3
|
|
C function or C++ method.
|
#define
|
MPR_TYPE_FLOAT 4
|
|
Floating point number.
|
#define
|
MPR_TYPE_FUNCTION 8
|
|
JavaScript function.
|
#define
|
MPR_TYPE_INT 5
|
|
Integer number.
|
#define
|
MPR_TYPE_INT64 6
|
|
64-bit Integer number
|
#define
|
MPR_TYPE_NULL 1
|
|
Value defined to be null.
|
#define
|
MPR_TYPE_OBJECT 7
|
|
Object reference.
|
#define
|
MPR_TYPE_STRING 9
|
|
String (immutable).
|
#define
|
MPR_TYPE_STRING_CFUNCTION 10
|
|
C/C++ function with string args.
|
#define
|
MPR_TYPE_UNDEFINED 0
|
|
Undefined. No value has been set.
|
#define |
MPR_VAR_ALT_HANDLE 0x1
|
#define |
MPR_VAR_SCRIPT_HANDLE 0x2
|
Typedefs
|
typedef int(* |
MprCFunction )(MprVarHandle userHandle, int argc, struct MprVar **argv)
|
|
Function signature for C function callbacks. The mprDefineCFunctionVar call takes a function of this prototype when initializing the variable.
|
typedef BLD_FEATURE_NUM_TYPE |
MprNum
|
typedef int(* |
MprStringCFunction )(MprVarHandle userHandle, int argc, char **argv)
|
|
Function signature for C function callbacks that require string arguments. The mprDefineStringCFunctionVar call takes a function of this prototype when initializing the variable.
|
typedef int |
MprVarHandle
|
|
Handle type used for C function callbacks.
|
Functions
|
void |
mprCopyVar (MprVar *dest, MprVar *src, int copyDepth)
|
void |
mprCopyVarValue (MprVar *dest, MprVar src, int copyDepth)
|
MprVar |
mprCreateBoolVar (bool value)
|
MprVar |
mprCreateCFunctionVar (MprCFunction fn, void *thisPtr, int flags)
|
MprVar |
mprCreateFloatVar (double value)
|
MprVar |
mprCreateFunctionVar (char *args, char *body, int flags)
|
MprVar |
mprCreateInteger64Var (int64 value)
|
MprVar |
mprCreateIntegerVar (int value)
|
MprVar |
mprCreateNullVar ()
|
MprVar |
mprCreateNumberVar (MprNumber value)
|
MprVar |
mprCreateObjVar (char *name, int hashSize)
|
MprVar |
mprCreateStringCFunctionVar (MprStringCFunction fn, void *thisPtr, int flags)
|
MprVar |
mprCreateStringVar (char *value, bool allocate)
|
MprVar |
mprCreateUndefinedVar ()
|
bool |
mprDestroyVar (MprVar *vp)
|
MprVar * |
mprDupVar (MprVar *src, int copyDepth)
|
int |
mprGetVarRefCount (MprVar *vp)
|
MprType |
mprGetVarType (MprVar *vp)
|
Define Documentation
|
Copy strings and do complete object copies.
|
#define MPR_ENUM_DATA 0x1 |
|
|
Step into data properties.
|
#define MPR_ENUM_FUNCTIONS 0x2 |
|
|
Step into functions properties.
|
|
Don't copy any data. Copy only the variable name
|
#define MPR_NUM_VAR BLD_FEATURE_NUM_TYPE_ID |
|
|
Set to the MPR_TYPE used for MPR numeric variables. Will equate to MPR_TYPE_INT, MPR_TYPE_INT64 or MPR_TYPE_FLOAT.
|
#define MPR_SHALLOW_COPY 1 |
|
|
Copy strings. Increment object reference counts.
|
#define MPR_VAR_ALT_HANDLE 0x1 |
|
|
Use the alternate handle on function callbacks
|
#define MPR_VAR_SCRIPT_HANDLE 0x2 |
|
|
Use the script handle on function callbacks
|
Typedef Documentation
|
Function signature for C function callbacks. The mprDefineCFunctionVar call takes a function of this prototype when initializing the variable.
- Parameters:
-
userHandle |
User defined handle. The user handles are normally specified by upper layers. |
argc |
Count of the number of arguments in argv |
argv |
Array of MprVar arguments |
- Stability classification:
- Evolving
- Library:
- libmpr, libappWeb
- See also:
-
MprStringCFunction, MprVarHandle
|
typedef BLD_FEATURE_NUM_TYPE MprNum
|
|
|
Set to the type used for MPR numeric variables. Will equate to int, int64 or double.
|
|
Function signature for C function callbacks that require string arguments. The mprDefineStringCFunctionVar call takes a function of this prototype when initializing the variable.
- Parameters:
-
userHandle |
User defined handle. |
argc |
Count of the number of arguments in argv |
argv |
Array of string arguments |
- Stability classification:
- Evolving
- Library:
- libmpr, libappWeb
- See also:
-
MprCFunction, MprVarHandle
|
Function Documentation
void mprCopyVar |
( |
MprVar * |
dest, |
|
|
MprVar * |
src, |
|
|
int |
copyDepth |
|
) |
|
|
|
- Synopsis:
- Copies a variable
- Overview:
- This call copies the src variable to the dest variable. The data will be copied differently depending on copyDepth. If src stores a primitive data type, such as an integer, the data is always copied. Otherwise, copyDepth determines how the copy is made.
When finished using the dest variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
dest |
Destination variable to copy into. |
src |
Source variable to copy from. |
copyDepth |
Flags to specify how to copy the data inside the variable. If copyDepth is MPR_DEEP_COPY, the all data fields are completely copies. If the source variable is an object, then all its properties will also be copied. If these properties are themselves objects, they will also be copied recursively.
If copyDepth is MPR_SHALLOW_COPY, objects will not be copied. Rather the object's reference count will be incremented. Objects use reference counts to assist the garbage collection mechanism. When the reference count is zero, the object is discarded. For MPR_SHALLOW_COPY, string data will still be copied.
If copyDepth is 0 or MPR_NO_COPY, then no objects or strings are copied. Only primitive data and the string or object reference is copied. Object reference counts are not changed. Use care when using MPR_NO_COPY particularly when running multithreaded. |
- Returns:
- Returns zero if successful, otherwise a negative MPR error code is returned.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVarValue, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprDupVar, mprGetVarType, mprParseVar
|
void mprCopyVarValue |
( |
MprVar * |
dest, |
|
|
MprVar |
src, |
|
|
int |
copyDepth |
|
) |
|
|
|
- Synopsis:
- Copies a variable
- Overview:
- This call copies the src variable to the dest variable. The data will be copied differently depending on copyDepth. If src stores a primitive data type, such as an integer, the data is always copied. This call is similar to mprCopyVar but the source variable is passed by "value". This allows you to use the mprCreate function calls as actual arguments.
When finished using the dest variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
dest |
Destination variable to copy into. |
src |
Source variable to copy from. |
copyDepth |
Flags to specify how to copy the data inside the variable. If copyDepth is MPR_DEEP_COPY, the all data fields are completely copies. If the source variable is an object, then all its properties will also be copied. If these properties are themselves objects, they will also be copied recursively.
If copyDepth is MPR_SHALLOW_COPY, objects will not be copied. Rather the object's reference count will be incremented. Objects use reference counts to assist the garbage collection mechanism. When the reference count is zero, the object is discarded. For MPR_SHALLOW_COPY, string data will still be copied.
If copyDepth is 0 or MPR_NO_COPY, then no objects or strings are copied. Only primitive data and the string or object reference is copied. Object reference counts are not changed. Use care when using MPR_NO_COPY particularly when running multithreaded. |
- Returns:
- Returns zero if successful, otherwise a negative MPR error code is returned.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprDupVar, mprGetVarType, mprParseVar
|
MprVar mprCreateBoolVar |
( |
bool |
value |
) |
|
|
|
- Synopsis:
- Create an boolean variable
- Overview:
- This call creates a boolean variable and initializes it with the given value. MPR variables efficiently store primitive types such as booleans directly in the variable structure. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
value |
Initial value for the variable. |
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateCFunctionVar |
( |
MprCFunction
|
fn, |
|
|
void * |
thisPtr, |
|
|
int |
flags |
|
) |
|
|
|
- Synopsis:
- Create an MPR variable holding a C function variable
- Overview:
- This call creates an MPR variable and initializes it with the given function. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
fn |
C language function. See the MprCFunction propotype. |
thisPtr |
If you want to define C++ functions, you can store an object pointer by setting thisPtr. |
flags |
Bit mask of flags to modify how the fuction callback is invoked. Set to zero for the defaults. Otherwise, set to
- MPR_VAR_ALT_HANDLE - Use the alternate handle on function callbacks.
- MPR_VAR_SCRIPT_HANDLE - Use the script handle on function callbacks.
|
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateFloatVar |
( |
double |
value |
) |
|
|
|
- Synopsis:
- Create an floating point variable
- Overview:
- This call creates a floating point variable and initializes it with the given value. MPR variables efficiently store primitive types such as floats directly in the variable structure. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
value |
Initial value for the variable. |
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateFunctionVar |
( |
char * |
args, |
|
|
char * |
body, |
|
|
int |
flags |
|
) |
|
|
|
- Synopsis:
- Create an MPR variable holding a JavaScript function
- Overview:
- This call creates an MPR variable and initializes it with the given JavaScript function. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
args |
Formal arguments for the fucntion. This list is a comma separated string. For example: "name, address". Note: there are no type specifiers in the arguments list. |
body |
JavaScript body for the function. |
flags |
Bit mask of flags to modify how the fuction callback is invoked. Set to zero for the defaults. Otherwise, set to
- MPR_VAR_ALT_HANDLE - Use the alternate handle on function callbacks.
- MPR_VAR_SCRIPT_HANDLE - Use the script handle on function callbacks.
|
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateInteger64Var |
( |
int64 |
value |
) |
|
|
|
- Synopsis:
- Create a 64-bit integer variable
- Overview:
- This call creates a 64-bit integer variable and initializes it with the given value. MPR variables efficiently store primitive types such as 64-bit integers directly in the variable structure. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
value |
Initial value for the variable. |
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateIntegerVar |
( |
int |
value |
) |
|
|
|
- Synopsis:
- Create an integer variable
- Overview:
- This call creates a integer variable and initializes it with the given value. MPR variables efficiently store primitive types such as integers directly in the variable structure. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
value |
Initial value for the variable. |
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateNullVar |
( |
|
) |
|
|
|
- Synopsis:
- Create an null variable
- Overview:
- This call creates a null variable. This is a special MPR variable that is defined to the null value. Do not confuse this with an "undefined" variable which has no defined value. A Null variable has a defined value set to Null. When used in languages such as JavaScript, variables can be tested if they are either undefined or whether they are set to null by comparing with the "null" and "undefined" named variables.
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateNumberVar |
( |
MprNumber |
value |
) |
|
|
|
- Synopsis:
- Create an numeric variable
- Overview:
- This call creates a numeric variable and initializes it with the given value. When the MPR is configured, it defines a default numeric type. This may be integer, integer64 or float. This call will create a variable of the default numeric type.
MPR variables efficiently store primitive types such as numerics directly in the variable structure. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
value |
Initial value for the variable. |
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateObjVar |
( |
char * |
name, |
|
|
int |
hashSize |
|
) |
|
|
|
- Synopsis:
- Create an object variable
- Overview:
- This call creates an object and stores a reference to the object in the returned MPR variable. When finished using the variable, you must call mprDestroyVar to free allocated storage. Once created, the underlying object will have a reference count of 1. To destroy the object, call mprDestroyVar which will decrement the reference count and will destroy the object if no-one is still using the object (ie. ref count == 0).
An object is a collection of named properties. These properties can be data properties or function / methods that operate on the object. See mprCreateProperty to create new properties in an object. The given object name is only used for debugging. In languages such as JavaScript, all objects have references from other objects and eventually, a direct or indirect reference from the global object.
Objects keep access counts of the number of variables that reference the object. Calls to mprCopyVar will increment the reference count depending on how the copyDepth parameter is defined. mprDestroyVar will free the resources allocated in creating the variable. If the variable is an object, it will also decrement the reference count and if the count is zero, it will free the object.
- Parameters:
-
name |
Debugging name for the object. |
hashSize |
Size of the property hash table for the object. This should be a prime number and can be set higher to boost the performance of objects with a large number of properties. Set to zero to get the default hash table size. |
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateBoolVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
|
- Synopsis:
- Create an MPR variable holding a C function variable
- Overview:
- This call creates an MPR variable and initializes it with the given function that expects all arguments to be strings. Before invoking this function callback, script services such as Embedded JavaScript convert all arguments to strings. When finished using the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
fn |
C language function. See the MprStringCFunction propotype. |
thisPtr |
If you want to define C++ functions, you can store an object pointer by setting thisPtr. |
flags |
Bit mask of flags to modify how the fuction callback is invoked. Set to zero for the defaults. Otherwise, set to
- MPR_VAR_ALT_HANDLE - Use the alternate handle on function callbacks.
- MPR_VAR_SCRIPT_HANDLE - Use the script handle on function callbacks.
|
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateStringVar |
( |
char * |
value, |
|
|
bool |
allocate |
|
) |
|
|
|
- Synopsis:
- Create an string variable
- Overview:
- This call creates a string variable and initializes it with the given string value. Depending on the value of allocate, the string will be duplicated or not. the variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
value |
Initial string value for the variable. |
allocate |
If true, the string is duplicated. Otherwise, the value supplied is used. In this case, the string must be persistent and immutable. |
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprVar mprCreateUndefinedVar |
( |
|
) |
|
|
|
- Synopsis:
- Create an undefined variable
- Overview:
- This call creates a undefined variable. This is a special MPR variable that represents a variable with no value. Do not confuse this with an "null" variable which has a value equal to Null. When used in languages such as JavaScript, variables can be tested if they are either undefined or whether they are set to null by comparing with the "null" and "undefined" named variables.
- Returns:
- Returns the initialized MPR variable of the required type.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
bool mprDestroyVar |
( |
MprVar * |
vp |
) |
|
|
|
- Synopsis:
- Destroy an MPR variable
- Overview:
- This call destroys an MPR variable and frees allocated storage. If the variable represents an object, the object's reference count will be decremented and if zero, the object will be destroyed. If the object has properties that represent other objects, these too will be destroyed recursively if their refererence counts are zero. mprDestroyVar can intelligently handle circular references between objects.
mprDestroyVar intelligently destroys dynamicall allocated objects that have been created via mprDupVar and statically copied object that have been created using mprCreate or mprCopyVar.
- Parameters:
-
vp |
Pointer to an MPR variable to destroy |
- Returns:
- Returns TRUE if they underlying data was freed. This will be false for objects, if there are other users of the object. Otherwise, for all other types, it will be TRUE.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprGetVarType, mprParseVar,
|
MprVar* mprDupVar |
( |
MprVar * |
src, |
|
|
int |
copyDepth |
|
) |
|
|
|
- Synopsis:
- Duplicate a variable
- Overview:
- This call duplicates the src variable into a dynamically allocated dest variable. The data will be copied differently depending on copyDepth. If src stores a primitive data type, such as an integer, the data is always copied. This call is similar to mprCopyVar but the source variable is passed by "value". This allows you to use the mprCreate function calls as actual arguments.
When finished using the dest variable, you must call mprDestroyVar to free allocated storage.
- Parameters:
-
src |
Source variable to copy from. |
copyDepth |
Flags to specify how to copy the data inside the variable. If copyDepth is MPR_DEEP_COPY, the all data fields are completely copies. If the source variable is an object, then all its properties will also be copied. If these properties are themselves objects, they will also be copied recursively.
If copyDepth is MPR_SHALLOW_COPY, objects will not be copied. Rather the object's reference count will be incremented. Objects use reference counts to assist the garbage collection mechanism. When the reference count is zero, the object is discarded. For MPR_SHALLOW_COPY, string data will still be copied.
If copyDepth is 0 or MPR_NO_COPY, then no objects or strings are copied. Only primitive data and the string or object reference is copied. Object reference counts are not changed. Use care when using MPR_NO_COPY particularly when running multithreaded. |
- Returns:
- Returns a pointer to the dynamically created variable. If a memory allocation error occurs, then zero will be returned.
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar
|
int mprGetVarRefCount |
( |
MprVar * |
vp |
) |
|
|
|
- Synopsis:
- Return the reference count for an object
- Overview:
- This call returns the count of users of an object by returning the object's reference count.
- Parameters:
-
vp |
Pointer to an MPR variable containing an object type |
- Library:
- libmpr, libappWeb
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprGetVarType, mprParseVar,
|
MprType mprGetVarType |
( |
MprVar * |
vp |
) |
|
|
|
- Synopsis:
- Return the type of a variable.
- Overview:
- This call returns the MPR variable type of the given variable.
- Parameters:
-
vp |
Pointer to an MPR variable to destroy |
- Library:
- libmpr, libappWeb
- Returns:
- Returns the type of the variable.
- See also:
-
mprCopyVar, mprCreateObjVar, mprCreateCFunctionVar, mprCreateFloatVar, mprCreateIntegerVar, mprCreateInteger64Var, mprCreateFunctionVar, mprCreateNullVar, mprCreateNumberVar, mprCreateProperty, mprCreateStringCFunctionVar, mprCreateStringVar, mprCreateUndefinedVar, mprDestroyVar, mprParseVar,
|
|
|