Summary
NPVariant is a struct that holds a value and the type of that value. The value is held in a union, and the type is one of types defined in the NPVariantType enumeration.
Syntax
typedef struct _NPVariant {
NPVariantType type;
union {
bool boolValue;
int32_t intValue;
double_t doubleValue;
NPString stringValue;
NPObject *objectValue;
} value;
} NPVariant;
Fields
The data structure has the following fields:
type- A member of the
NPVariantTypeenumeration specifying the data type contained in theNPVariant. value- The value contained in the
NPVariantstructure. It may be a boolean, integer, double, string, or object, depending on the variant type.
JavaScript type to NPVariantType enumeration mapping
When using NPVariants to access JavaScript objects in the browser, or vise versa, the mapping of JavaScript values to NPVariants is as follows:
| JavaScript type | NPVariantType |
undefined |
NPVariantType_Void |
null |
NPVariantType_Null |
boolean |
NPVariantType_Bool |
number |
NPVariantType_Int32 or NPVariantType_Double |
string |
NPVariantType_String |
| All other types | NPVariantType_Object |
Functions
NPN_ReleaseVariantValue()NPN_GetStringIdentifier()NPN_GetStringIdentifiers()NPN_GetIntIdentifier()NPN_IdentifierIsString()NPN_UTF8FromIdentifier()NPN_IntFromIdentifier()
Macros
Plugin developers are not expected to directly manipulate or access the members of the NPVariant instance, instead, the function NPN_ReleaseVariantValue(), and the following macros are provided:
NPVARIANT_IS_VOID()- Evaluates to
trueifvis of typeNPVariantType_Void. NPVARIANT_IS_NULL()- Evaluates to
trueifvis of typeNPVariantType_Null. NPVARIANT_IS_BOOLEAN()- Evaluates to
trueifvis of typeNPVariantType_Bool. NPVARIANT_IS_INT32()- Evaluates to
trueifvis of typeNPVariantType_Int32. NPVARIANT_IS_DOUBLE()- Evaluates to
trueifvis of typeNPVariantType_Double. NPVARIANT_IS_STRING()- Evaluates to
trueifvis of typeNPVariantType_String. NPVARIANT_IS_OBJECT()- Evaluates to
trueifvis of typeNPVariantType_Object. NPVARIANT_TO_BOOLEAN()- Extracts the boolean value from
v. NPVARIANT_TO_INT32()- Extracts a signed 32-bit integer value from
v. NPVARIANT_TO_DOUBLE()- Extracts a double precision floating point value from
v. NPVARIANT_TO_STRING()- Extracts the NPString value from
v. NPVARIANT_TO_OBJECT()- Extracts the NPObject value from
v. VOID_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Void. NULL_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Null. BOOLEAN_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Boolwith the valueval. INT32_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Int32with the valueval. DOUBLE_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Doublewith the valueval. STRINGZ_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Stringwith the value being anNPStringholding the UTF-8 string valueval. STRINGN_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Stringwith the value being anNPStringholding the UTF-8 string valuevalwith the lengthlen. OBJECT_TO_NPVARIANT()- Initialize
vto a variant of typeNPVariantType_Objectwith the valueval.