DynaValues and LWValues

The DynaValue data type defined in lwdyna.h is a union of containers for values of various base types. DynaValues are used as function arguments, with commands and requesters, for example, when the function must accept values of multiple types. LWValues are a variation on DynaValues used by Panels and defined in lwpanel.h.

The DynaValue typedef looks like this.

   typedef union un_DynaValue {
      DynaType      type;
      DyValString   str;
      DyValInt      intv;
      DyValFloat    flt;
      DyValIVector  ivec;
      DyValFVector  fvec;
      DyValCustom   cust;
   } DynaValue;

The elements of this union each support a different base type, and each base type can underlie several DynaTypes. (Two DynaTypes, DY_NULL and DY_TEXT, have no underlying value.)


   typedef struct st_DyValString {           DY_STRING
      DynaType   type;                       DY_SURFACE
      char      *buf;
      int        bufLen;
   } DyValString;

bufLen is the size of buf in characters. For the DY_SURFACE type, buf contains the surface name.


   typedef struct st_DyValInt {              DY_INTEGER
      DynaType   type;                       DY_BOOLEAN
      int        value;                      DY_CHOICE
      int        defVal;                     DY_FONT
   } DyValInt;                               DY_LAYERS

The value in defVal is used by requesters to reset control values. The value for DY_CHOICE and DY_FONT is a 0-based index into a list. The value for DY_LAYERS is a set of bitfields corresponding to layer numbers.

Floating-Point Numbers

   typedef struct st_DyValFloat {            DY_FLOAT
      DynaType   type;                       DY_DISTANCE
      double     value;
      double     defVal;
   } DyValFloat;

DY_DIST values are distances in meters.

Integer Vectors

   typedef struct st_DyValIVector {          DY_VINT
      DynaType   type;
      int        val[3];
      int        defVal;
   } DyValIVector;

Floating-Point Vectors

   typedef struct st_DyValFVector {          DY_VFLOAT
      DynaType   type;                       DY_VDIST
      double     val[3];
      double     defVal;
   } DyValFVector;

Custom Values

   typedef struct st_DyValCustom {           DY_CUSTOM
      DynaType   type;
      int        val[4];
   } DyValCustom;

DY_CUSTOM is used to encode values that don't fit one of the standard types. The interpretation of the values in the val array will depend on the context in which this type is used.

The Dynamic Conversion global provides a facility for converting between DynaValues of different types.


Panels adds a generic pointer type to the list of types, but in all other respects, LWValues differ from DynaValues in name only. Structurally they're equivalent.

   typedef union un_LWValue {
      LWType        type;
      LWValString   str;
      LWValInt      intv;
      LWValFloat    flt;
      LWValIVector  ivec;
      LWValFVector  fvec;
      LWValPointer  ptr;
      LWValCustom   cust;
   } LWValue;

Although lwpanel.h defines others, only five LWTypes are needed to describe the values of all LWPanels controls.