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
NPVariantType
enumeration specifying the data type contained in theNPVariant
. value
- The value contained in the
NPVariant
structure. It may be a boolean, integer, double, string, or object, depending on the variant type.
JavaScript type to NPVariantType
enumeration mapping
When using NPVariant
s to access JavaScript objects in the browser, or vise versa, the mapping of JavaScript values to NPVariant
s 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
true
ifv
is of typeNPVariantType_Void
. NPVARIANT_IS_NULL()
- Evaluates to
true
ifv
is of typeNPVariantType_Null
. NPVARIANT_IS_BOOLEAN()
- Evaluates to
true
ifv
is of typeNPVariantType_Bool
. NPVARIANT_IS_INT32()
- Evaluates to
true
ifv
is of typeNPVariantType_Int32
. NPVARIANT_IS_DOUBLE()
- Evaluates to
true
ifv
is of typeNPVariantType_Double
. NPVARIANT_IS_STRING()
- Evaluates to
true
ifv
is of typeNPVariantType_String
. NPVARIANT_IS_OBJECT()
- Evaluates to
true
ifv
is 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
v
to a variant of typeNPVariantType_Void
. NULL_TO_NPVARIANT()
- Initialize
v
to a variant of typeNPVariantType_Null
. BOOLEAN_TO_NPVARIANT()
- Initialize
v
to a variant of typeNPVariantType_Bool
with the valueval
. INT32_TO_NPVARIANT()
- Initialize
v
to a variant of typeNPVariantType_Int32
with the valueval
. DOUBLE_TO_NPVARIANT()
- Initialize
v
to a variant of typeNPVariantType_Double
with the valueval
. STRINGZ_TO_NPVARIANT()
- Initialize
v
to a variant of typeNPVariantType_String
with the value being anNPString
holding the UTF-8 string valueval
. STRINGN_TO_NPVARIANT()
- Initialize
v
to a variant of typeNPVariantType_String
with the value being anNPString
holding the UTF-8 string valueval
with the lengthlen
. OBJECT_TO_NPVARIANT()
- Initialize
v
to a variant of typeNPVariantType_Object
with the valueval
.