home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Sylia / ScriptValue.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  3.0 KB  |  89 lines

  1. #ifndef f_SYLIA_SCRIPTVALUE_H
  2. #define f_SYLIA_SCRIPTVALUE_H
  3.  
  4. #include <vd2/system/vdtypes.h>
  5.  
  6. class VDScriptArray;
  7. struct VDScriptObject;
  8. class VDScriptValue;
  9. class IVDScriptInterpreter;
  10. class VariableTableEntry;
  11.  
  12. // Note: These objects must match the corresponding objects from the plugin interface.
  13.  
  14. typedef VDScriptValue (*VDScriptObjectLookupFuncPtr)(IVDScriptInterpreter *, const VDScriptObject *, void *lpVoid, char *szName);
  15. typedef void (*VDScriptFunction)(IVDScriptInterpreter *, VDScriptValue *, int);
  16.  
  17. struct VDScriptFunctionDef {
  18.     VDScriptFunction    func_ptr;
  19.     const char *name;
  20.     const char *arg_list;
  21. };
  22.  
  23. struct VDScriptObjectDef {
  24.     const char *name;
  25.     const VDScriptObject *obj;
  26. };
  27.  
  28. struct VDScriptObject {
  29.     const char *mpName;
  30.     VDScriptObjectLookupFuncPtr Lookup;
  31.     const VDScriptFunctionDef        *func_list;
  32.     const VDScriptObjectDef            *obj_list;
  33.     const VDScriptObject        *pNextObject;
  34.     const VDScriptFunctionDef    *prop_list;
  35. };
  36.  
  37. class VDScriptValue {
  38. public:
  39.     enum { T_VOID, T_INT, T_PINT, T_STR, T_ARRAY, T_OBJECT, T_FNAME, T_FUNCTION, T_VARLV, T_LONG, T_DOUBLE } type;
  40.     const VDScriptObject *thisPtr;
  41.     union {
  42.         int i;
  43.         char **s;
  44.         struct {
  45.             const VDScriptObject *def;
  46.             void *p;
  47.         } obj;
  48.         struct {
  49.             const VDScriptFunctionDef *pfn;
  50.             void *p;
  51.         } method;
  52.         VariableTableEntry *vte;
  53.         sint64 l;
  54.         double d;
  55.     } u;
  56.  
  57.     VDScriptValue()                        { type = T_VOID; }
  58.     explicit VDScriptValue(int i)                { type = T_INT;            u.i = i; }
  59.     explicit VDScriptValue(sint64 l)                { type = T_LONG;        u.l = l; }
  60.     explicit VDScriptValue(double d)                { type = T_DOUBLE;        u.d = d; }
  61.     explicit VDScriptValue(char **s)                { type = T_STR;            u.s = s; }
  62.     explicit VDScriptValue(void *p, const VDScriptObject *obj)    { type = T_OBJECT;        u.obj.def = obj; u.obj.p = p; }
  63.     explicit VDScriptValue(void *p, const VDScriptObject *obj, const VDScriptFunctionDef *pf)    { type = T_FNAME;        thisPtr = obj; u.method.pfn = pf; u.obj.p = p; }
  64.     explicit VDScriptValue(VariableTableEntry *vte) { type = T_VARLV;        u.vte = vte; }
  65.  
  66.     VDScriptValue& operator=(int i) { type = T_INT; u.i = i; return *this; }
  67.     VDScriptValue& operator=(sint64 l) { type = T_LONG; u.l = l; return *this; }
  68.     VDScriptValue& operator=(double d) { type = T_DOUBLE; u.d = d; return *this; }
  69.  
  70.     bool isVoid() const            { return type == T_VOID; }
  71.     bool isInt() const            { return type == T_INT; }
  72.     bool isLong() const            { return type == T_LONG; }
  73.     bool isDouble() const        { return type == T_DOUBLE; }
  74.     bool isString() const        { return type == T_STR; }
  75.     bool isObject() const        { return type == T_OBJECT; }
  76.     bool isVarLV() const        { return type == T_VARLV; }
  77.     bool isMethod() const        { return type == T_FNAME; }
  78.  
  79.     int                        asInt() const            { return u.i; }
  80.     sint64                    asLong() const            { return u.l; }
  81.     double                    asDouble() const        { return u.d; }
  82.     char **                    asString() const        { return u.s; }
  83.     const VDScriptObject *    asObjectDef() const        { return u.obj.def; }
  84.     void *                    asObjectPtr() const        { return u.obj.p; }
  85.     VariableTableEntry*        asVarLV() const        { return u.vte; }
  86. };
  87.  
  88. #endif
  89.