Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

NPVariant

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 the NPVariant.
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 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

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 if v is of type NPVariantType_Void.
NPVARIANT_IS_NULL()
Evaluates to true if v is of type NPVariantType_Null.
NPVARIANT_IS_BOOLEAN()
Evaluates to true if v is of type NPVariantType_Bool.
NPVARIANT_IS_INT32()
Evaluates to true if v is of type NPVariantType_Int32.
NPVARIANT_IS_DOUBLE()
Evaluates to true if v is of type NPVariantType_Double.
NPVARIANT_IS_STRING()
Evaluates to true if v is of type NPVariantType_String.
NPVARIANT_IS_OBJECT()
Evaluates to true if v is of type NPVariantType_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 type NPVariantType_Void.
NULL_TO_NPVARIANT()
Initialize v to a variant of type NPVariantType_Null.
BOOLEAN_TO_NPVARIANT()
Initialize v to a variant of type NPVariantType_Bool with the value val.
INT32_TO_NPVARIANT()
Initialize v to a variant of type NPVariantType_Int32 with the value val.
DOUBLE_TO_NPVARIANT()
Initialize v to a variant of type NPVariantType_Double with the value val.
STRINGZ_TO_NPVARIANT()
Initialize v to a variant of type NPVariantType_String with the value being an NPString holding the UTF-8 string value val.
STRINGN_TO_NPVARIANT()
Initialize v to a variant of type NPVariantType_String with the value being an NPString holding the UTF-8 string value val with the length len.
OBJECT_TO_NPVARIANT()
Initialize v to a variant of type NPVariantType_Object with the value val.

Document Tags and Contributors

Tags: 
 Contributors to this page: teoli, ethertank, Josh, Sheppy
 Last updated by: ethertank,