Using Edge Extensions with the ThingWorx Edge C SDK > Macros for the Edge Extensions > Macros to Create twPrimitives from C Primitives
Macros to Create twPrimitives from C Primitives
C has its primitive types such as int, bool, char*, and double. The ThingWorx C API has its own core data type as well, the twPrimitive. The twPrimitive is Variant Type (refer to https://en.wikipedia.org/wiki/Variant_type), which must be wrapped around a C primitive type before it can be used in a ThingWorx API call. This wrapping process involves the creation of a twPrimitive in the heap, which is then turned over to the API for management. The management includes releasing the twPrimitive back into free memory to prevent leakage. The ability to rapidly create twPrimitives from C primitives is important. The following is a list of macros to accomplish this for the most commonly used types:
TW_MAKE_NUMBER(<double>)
TW_MAKE_INT(<int>)
TW_MAKE_STRING(<char*>)
TW_MAKE_BOOL(<bool>)
TW_MAKE_DATETIME(<DATETIME>)
TW_MAKE_DATETIME_NOW
TW_MAKE_EMPTY—Produces a primitive of type TW_NOTHING
TW_MAKE_LOC(<double>latitude,<double>longitude,<double>elevation)
You can also use simple API calls to create other primitives that are less commonly used. All primitive-creation macros call the C API functions of the form twPrimitive_CreateFrom...() such as twPrimitive_CreateFromNumber(), twPrimitive_CreateFromInteger(), and twPrimitive_CreateFromString(). Their main benefit is that they are shorter to type.
Was this helpful?