maxscript/foundation/functions.h File Reference
 
 
 
maxscript/foundation/functions.h File Reference
#include "arrays.h"
#include "../../ifnpub.h"
#include "../../GetCOREInterface.h"

Classes

struct  DumpValueData
class  CallContext
class  StructMethod
class  SMCallContext
class  PluginMethod
class  UserProp
class  UserGeneric
class  ValueConverter
class  InterfaceMethod
class  StaticInterfaceMethod

Defines

#define def_generic(fn, name)   ScripterExport Value* fn##_vf(Value** arglist, int arg_count)
#define FPS_CACHE_SIZE   512
#define is_function(v)   ((v)->_is_function())
#define is_maxscriptfunction(v)   ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(MAXScriptFunction))
#define FN_MAPPED_FN   0x0001
#define FN_BODY_FN   0x0002
#define FN_HAS_REFARGS   0x0004
#define FN_MAPPED_EVAL   0x0008
#define is_structMethod(v)   ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == INTERNAL_STRUCT_METHOD_TAG)
#define is_pluginMethod(v)   ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == INTERNAL_MSPLUGIN_METHOD_TAG)
#define def_user_prop(_prop, _cls, _getter, _setter)   _cls##_class.add_user_prop(_M(#_prop), _getter, _setter)
#define def_user_generic(_fn, _cls, _name)   _cls##_class.add_user_generic(#_name, _fn)
#define VALUECONVERTER_INTERFACE_ID   Interface_ID(0x19f37b9f, 0x39ed5680)
#define is_iobject(v)   ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(IObjectValue))
#define is_fpstaticinterface(v)   ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPInterfaceValue))
#define is_fpmixininterface(v)   ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPMixinInterfaceValue))
#define is_fpstaticmethodinterface(v)   ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPStaticMethodInterfaceValue))

Enumerations

enum  primitive_flag { LAZY_PRIMITIVE = 0x0001, DEBUGGER_SAFE = 0x0002 }

Functions

 visible_class (Function) class Function
 visible_class (Generic) class Generic
 visible_class (MappedGeneric) class MappedGeneric
 visible_class (NodeGeneric) class NodeGeneric
 visible_class (Primitive) class Primitive
 visible_class (MappedPrimitive) class MappedPrimitive
 visible_class (MAXScriptFunction) class MAXScriptFunction
 visible_class (UserGenericValue) class UserGenericValue
 visible_class (InterfaceFunction) class InterfaceFunction
 visible_class (ActionPredicate) class ActionPredicate
 visible_class (IObjectValue) class IObjectValue
 visible_class (FPInterfaceValue) class FPInterfaceValue
ScripterExport void print_FP_interface (CharStream *out, FPInterface *fpi, bool getPropNames=true, bool getMethodNames=true, bool getInterfaceNames=true, bool getActionTables=true)
 visible_class (FPMixinInterfaceValue) class FPMixinInterfaceValue
 visible_class (FPStaticMethodInterfaceValue) class FPStaticMethodInterfaceValue

Define Documentation

#define def_generic (   fn,
  name 
)    ScripterExport Value* fn##_vf(Value** arglist, int arg_count)
#define FPS_CACHE_SIZE   512
#define is_function (   v)    ((v)->_is_function())
#define is_maxscriptfunction (   v)    ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(MAXScriptFunction))
#define FN_MAPPED_FN   0x0001
#define FN_BODY_FN   0x0002
#define FN_HAS_REFARGS   0x0004
#define FN_MAPPED_EVAL   0x0008
#define is_structMethod (   v)    ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == INTERNAL_STRUCT_METHOD_TAG)
#define is_pluginMethod (   v)    ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == INTERNAL_MSPLUGIN_METHOD_TAG)
#define def_user_prop (   _prop,
  _cls,
  _getter,
  _setter 
)    _cls##_class.add_user_prop(_M(#_prop), _getter, _setter)
#define def_user_generic (   _fn,
  _cls,
  _name 
)    _cls##_class.add_user_generic(#_name, _fn)
#define VALUECONVERTER_INTERFACE_ID   Interface_ID(0x19f37b9f, 0x39ed5680)
#define is_iobject (   v)    ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(IObjectValue))
#define is_fpstaticinterface (   v)    ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPInterfaceValue))
#define is_fpmixininterface (   v)    ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPMixinInterfaceValue))
#define is_fpstaticmethodinterface (   v)    ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPStaticMethodInterfaceValue))

Enumeration Type Documentation

Enumerator:
LAZY_PRIMITIVE 
DEBUGGER_SAFE 
{
        LAZY_PRIMITIVE  =       0x0001, // don't pre-evaluate args for lazy primitives
        DEBUGGER_SAFE   =       0x0002, // safe to call from debugger
};

Function Documentation

visible_class ( Function  )
               : public Value
{
// Whether the function can be called from debugger thread stored in Collectable::flags3 - bit 0. Default is false.
public:
        const MCHAR*            name;
        const MCHAR*            struct_name;    // packaged in a struct if non-null

                                   Function() { name = NULL; struct_name = NULL; }
        ScripterExport Function(const MCHAR* name, const MCHAR* struct_name=NULL);
        ScripterExport Function(const MCHAR* name, const MCHAR* struct_name, bool debuggerSafe);
        ScripterExport ~Function();

                                classof_methods (Function, Value);
#       define          is_function(v) ((v)->_is_function())
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }

        ScripterExport void sprin1(CharStream* s);
        ScripterExport void export_to_scripter();
};
visible_class ( Generic  )
              : public Function
{
public:
        value_vf        fn_ptr;

        Generic() { }
        ScripterExport Generic(const MCHAR* name, value_vf fn, const MCHAR* struct_name = NULL);
        ScripterExport Generic(const MCHAR* name, value_vf fn, const MCHAR* struct_name, short init_flags=0);
        Generic(const MCHAR* name) : Function(name) { }

        classof_methods (Generic, Function);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
        ScripterExport void     collect();

        ScripterExport Value* apply(Value** arglist, int count, CallContext* cc=NULL);
};
visible_class ( MappedGeneric  )
                    : public Generic
{
public:
        MappedGeneric() { }
        ScripterExport MappedGeneric(const MCHAR* name, value_vf fn);
        ScripterExport MappedGeneric(const MCHAR* name, value_vf fn, short init_flags);
        MappedGeneric(const MCHAR* name) : Generic(name) { }

        classof_methods (MappedGeneric, Generic);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
        void            collect();

        ScripterExport Value* apply(Value** arglist, int count, CallContext* cc=NULL);
};
visible_class ( NodeGeneric  )
                  : public MappedGeneric
{
public:
        ScripterExport NodeGeneric(const MCHAR* name, value_vf fn);
        ScripterExport NodeGeneric(const MCHAR* name, value_vf fn, short init_flags);
        NodeGeneric(const MCHAR* name) : MappedGeneric(name) { }

        classof_methods (NodeGeneric, MappedGeneric);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
        void            collect();

        ScripterExport Value* apply(Value** arglist, int count, CallContext* cc=NULL);
};
visible_class ( Primitive  )
                : public Function
{ 
public:
        short           flags;
        value_cf        fn_ptr;

                            Primitive() { flags=0; }
 ScripterExport Primitive(const MCHAR* name, value_cf fn, short init_flags=0);
 ScripterExport Primitive(const MCHAR* name, const MCHAR* structure, value_cf fn, short init_flags=0);
                            Primitive(const MCHAR* name) : Function(name) { flags=0; }

                                classof_methods (Primitive, Function);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
        void            collect();

        ScripterExport Value* apply(Value** arglist, int count, CallContext* cc=NULL);
};
visible_class ( MappedPrimitive  )
                      : public Primitive
{ 
public:
 ScripterExport MappedPrimitive(const MCHAR* name, value_cf fn);
 ScripterExport MappedPrimitive(const MCHAR* name, value_cf fn, short init_flags);

                                classof_methods (MappedPrimitive, Primitive);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return 1; }
        void            collect();

        ScripterExport Value* apply(Value** arglist, int count, CallContext* cc=NULL);
};
visible_class ( MAXScriptFunction  )
                        : public Function
{
public:
        short           parameter_count;
        short           local_count;
        short           keyparm_count;
        short           flags;
        Value**         keyparms;
        Value*          body;
        HashTable*      local_scope;
        value_cf        c_callable_fn;
        Array*          paramNames;
        Value*          owner;

 ScripterExport MAXScriptFunction(const MCHAR* name, int parm_count, int keyparm_count, Value** keyparms,
                                                                  int local_count, Value* body, HashTable* local_scope, short flags = 0);
 ScripterExport MAXScriptFunction(const MCHAR* name, int parm_count, int keyparm_count, Value** keyparms,
                                                                  int local_count, Value* body, HashTable* local_scope, Array* param_names, 
                                                                  Value* owner, short flags = 0);
                                ~MAXScriptFunction();
#       define          is_maxscriptfunction(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(MAXScriptFunction))

                                classof_methods (MAXScriptFunction, Function);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return TRUE; }
        void            collect();
        void            gc_trace();
        void            sprin1(CharStream* s);

        Value*          apply(Value** arglist, int count, CallContext* cc=NULL);
        Value*          apply_no_alloc_frame(Value** arglist, int count, CallContext* cc=NULL);

        value_cf        get_c_callable_fn();

        Value*          operator()(Value** arg_list, int count);

        // added 3/21/05. Used by debugger to dump locals, parms, and externals to standard out
        void            dump_local_vars_params_and_externals(Value** paramsFrame, Value** localsFrame, int indentLevel);

protected:
        Value*          wrap_arg(Value* arg);
};
visible_class ( UserGenericValue  )
                       : public Function
{
public:
        Value*          fn_name;
        Value*          old_fn;   // if non-NULL, the original global fn that this usergeneric replaced
                                
 ScripterExport UserGenericValue(Value* name, Value* old_fn);

                                classof_methods (UserGenericValue, Function);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return TRUE; }
        void            collect();
        void            gc_trace();

        Value*          apply(Value** arglist, int count, CallContext* cc=NULL);
};
visible_class ( InterfaceFunction  )
                        : public Function
{
public:
        FPInterfaceDesc* fpid;
        FPFunctionDef*   fd;

                                InterfaceFunction(FPInterface* fpi, FPFunctionDef* fd);
                                ~InterfaceFunction();

                                classof_methods (InterfaceFunction, Function);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return TRUE; }
        void            collect();
        void            gc_trace();
        void            sprin1(CharStream* s);

        Value*          apply(Value** arglist, int count, CallContext* cc=NULL);
        Value*          get_property(Value** arg_list, int count);

        // parameter conversion utilities
        ScripterExport static void        val_to_FPValue(Value* v, ParamType2 type, FPValue& fpv, FPEnum* e, Tab<void*> *stringStorage, Array* valueStore);
        ScripterExport static void        val_to_FPValue(Value* v, ParamType2 type, FPValue& fpv, FPEnum* e, Tab<void*> *stringStorage);
        ScripterExport static void        val_to_FPValue(Value* v, ParamType2 type, FPValue& fpv, FPEnum* e=NULL);
        ScripterExport static Value*  FPValue_to_val(FPValue& fpv, FPEnum* e=NULL);
        ScripterExport static void        release_param(FPValue& fpv, ParamType2 type, Value* v, FPEnum* e=NULL);
        ScripterExport static void        init_param(FPValue& fpv, ParamType2 type);
        ScripterExport static void        validate_params(FPInterface* fpi, FunctionID fid, FPParamDef* pd, ParamType2 type, int paramNum, FPValue& val, Value* v);
        ScripterExport static FPEnum* FindEnum(short id, FPInterfaceDesc* fpid);
};
visible_class ( ActionPredicate  )
                      : public InterfaceFunction
{
public:
        short           pred;

        ActionPredicate(FPInterface* fpi, FPFunctionDef* fd, short pred);

                                classof_methods (ActionPredicate, Function);
        BOOL            _is_function() { DbgAssert(!is_sourcepositionwrapper(this)); return TRUE; }
        void            collect();

        Value*          apply(Value** arglist, int count, CallContext* cc=NULL);
};
visible_class ( IObjectValue  )
                   : public Value
{
public:
        IObject* iobj;                                  // the IObject pointer

                        IObjectValue(IObject* io);
                   ~IObjectValue();
#       define  is_iobject(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(IObjectValue))

                        classof_methods (IObjectValue, Value);
        void    collect();
        void    sprin1(CharStream* s);

        MSTR    to_filename(); // returns guidstring if wraps AssetUser
        void    to_fpvalue(FPValue& v) { v.iobj = iobj; v.type = TYPE_IOBJECT; }

        def_generic (show_interfaces,  "showInterfaces"); 
        def_generic (get_interfaces, "getInterfaces");
        def_generic (get_interface, "getInterface");

// End of 3ds max 4.2 Extension

        BaseInterface* GetInterface(Interface_ID id) { return iobj->GetInterface(id); }

        //accesses interfaces on the IObject
        Value*  get_property(Value** arg_list, int count);
        Value*  set_property(Value** arg_list, int count);
};
visible_class ( FPInterfaceValue  )
                       : public Value, public InterfaceNotifyCallback
{
public:
        FPInterface* fpi;                       // interface
        HashTable*       fns;                   // interface fn lookup
        HashTable*       props;                 // interface prop lookup
        FPInterface::LifetimeType lifetime;     // interface lifetime control type
        static bool      enable_test_interfaces;  // test interface enable flag
        // Whether to call fpi->ReleaseInterface stored in Collectable::flags3 - bit 0

        ScripterExport FPInterfaceValue(FPInterface* fpi);   
        FPInterfaceValue(FPInterfaceProxy* proxy);
        ~FPInterfaceValue();
#pragma push_macro("new")
#undef new
        // Needed to solve ambiguity between Collectable's operators and MaxHeapOperators
        using Collectable::operator new;
        using Collectable::operator delete;
#pragma pop_macro("new")
#       define  is_fpstaticinterface(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPInterfaceValue))

                        classof_methods (FPInterfaceValue, Value);
                        def_generic ( show_interface,           "showInterface"); // LAM: 08/29/00
                        def_generic ( get_props,                        "getPropNames"); // LAM: added 2/1/02
                        def_generic ( isDeleted,                        "isDeleted");   // LAM: 11/23/01 - added - doesn't break SDK
                        use_generic( eq,                                        "=" );                  // LAM: 11/23/01 - added - doesn't break SDK
                        use_generic( ne,                                        "!=" );                 // LAM: 11/23/01 - added - doesn't break SDK
        void    collect();
        void    gc_trace();
        void    sprin1(CharStream* s);

// The following method has been added
// in 3ds max 4.2.  If your plugin utilizes this new
// mechanism, be sure that your clients are aware that they
// must run your plugin with 3ds max version 4.2 or higher.

        void    to_fpvalue(FPValue& v) { 
                resolve_proxy();
                v.fpi = fpi; 
                v.type = TYPE_INTERFACE; 
        }

// End of 3ds max 4.2 Extension

        // from InterfaceNotifyCallback
        void    InterfaceDeleted(BaseInterface* bi) { UNUSED_PARAM(bi); fpi = NULL; }  

        // accesses methods & props in the interface
        Value*  _get_property(Value* prop);
        Value*  _set_property(Value* prop, Value* val);

        Value*  get_property(Value** arg_list, int count);
        Value*  set_property(Value** arg_list, int count);

        static void UpdateEditorOnResolve(bool update = true);

private:
        void    resolve_proxy();
        void    set_interface(FPInterface* fpi);

        FPInterfaceProxy*       m_fpip;
        static bool                     s_updateEditorOnResolve;
};
ScripterExport void print_FP_interface ( CharStream *  out,
FPInterface fpi,
bool  getPropNames = true,
bool  getMethodNames = true,
bool  getInterfaceNames = true,
bool  getActionTables = true 
)
visible_class ( FPMixinInterfaceValue  )
                            : public Value, public InterfaceNotifyCallback
{
private:
                        FPMixinInterfaceValue(FPInterface* fpi);
                   ~FPMixinInterfaceValue();
        static  FPMixinInterfaceValue* FPMixinInterfaceValue::interface_cache[128];
        friend void Collectable::gc();
        friend void Collectable::mark();
public:
        FPInterface* fpi;                                               // interface
        FPInterface::LifetimeType lifetime;             // interface lifetime control type
        // Whether to call fpi->ReleaseInterface stored in Collectable::flags3 - bit 0
#pragma push_macro("new")
#undef new
        // Needed to solve ambiguity between Collectable's operators and MaxHeapOperators
        using Collectable::operator new;
        using Collectable::operator delete;
#pragma pop_macro("new")
        static  ScripterExport FPMixinInterfaceValue* intern(Value* prop_name, Value* target);
        static  ScripterExport FPMixinInterfaceValue* intern(FPInterface* fpi);
#       define  is_fpmixininterface(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPMixinInterfaceValue))

                        classof_methods (FPMixinInterfaceValue, Value);
                        def_generic ( show_interface,           "showInterface"); // LAM: 08/29/00
                        def_generic ( isDeleted,                        "isDeleted");   // LAM: 11/23/01 - added - doesn't break SDK
                        use_generic( eq,                                        "=" );                  // LAM: 11/23/01 - added - doesn't break SDK
                        use_generic( ne,                                        "!=" );                 // LAM: 11/23/01 - added - doesn't break SDK
                        def_generic ( get_props,                        "getPropNames"); // LAM: added 2/1/02
        void    collect();
        void    sprin1(CharStream* s);

// The following method has been added
// in 3ds max 4.2.  If your plugin utilizes this new
// mechanism, be sure that your clients are aware that they
// must run your plugin with 3ds max version 4.2 or higher.

        void    to_fpvalue(FPValue& v) { v.fpi = fpi; v.type = TYPE_INTERFACE; }

// End of 3ds max 4.2 Extension

        // from InterfaceNotifyCallback
        void    InterfaceDeleted(BaseInterface* bi); 

        // accesses methods & props in the interface
        Value*  _get_property(Value* prop);
        Value*  _set_property(Value* prop, Value* val);

        Value*  get_property(Value** arg_list, int count);
        Value*  set_property(Value** arg_list, int count);
};
visible_class ( FPStaticMethodInterfaceValue  )
                                   : public Value, public InterfaceNotifyCallback
{
private:
                        FPStaticMethodInterfaceValue(FPInterface* fpi, ParamType2 type, void* object);
                   ~FPStaticMethodInterfaceValue();
        static  FPStaticMethodInterfaceValue* interface_cache[FPS_CACHE_SIZE];
        friend void Collectable::gc();
        friend void Collectable::mark();
public:
        FPInterface* fpi;                       // interface
        FPValue          value;         // the target object as FPValue first argument
        FPInterface::LifetimeType lifetime;     // interface lifetime control type
        // Whether to call fpi->ReleaseInterface stored in Collectable::flags3 - bit 0
#pragma push_macro("new")
#undef new
        // Needed to solve ambiguity between Collectable's operators and MaxHeapOperators
        using Collectable::operator new;
        using Collectable::operator delete;
#pragma pop_macro("new")
        static  ScripterExport FPStaticMethodInterfaceValue* intern(FPInterface* fpi, ParamType2 type, void* object);
#       define  is_fpstaticmethodinterface(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(FPStaticMethodInterfaceValue))

                        classof_methods (FPStaticMethodInterfaceValue, Value);
                        def_generic ( show_interface,           "showInterface"); // LAM: 08/29/00
                        def_generic ( isDeleted,                        "isDeleted");   // LAM: 11/23/01 - added - doesn't break SDK
                        use_generic( eq,                                        "=" );                  // LAM: 11/23/01 - added - doesn't break SDK
                        use_generic( ne,                                        "!=" );                 // LAM: 11/23/01 - added - doesn't break SDK
                        def_generic ( get_props,                        "getPropNames"); // LAM: added 2/1/02
        void    collect();
        void    sprin1(CharStream* s);

        // from InterfaceNotifyCallback
        void    InterfaceDeleted(BaseInterface* bi) { UNUSED_PARAM(bi); fpi = NULL; }  

        // accesses methods & props in the interface
        Value*  _get_property(Value* prop);
        Value*  _set_property(Value* prop, Value* val);

        Value*  get_property(Value** arg_list, int count);
        Value*  set_property(Value** arg_list, int count);
};