Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1467 lines
68 KiB

  1. //========== Copyright � 2008, Valve Corporation, All rights reserved. ========
  2. //
  3. // Purpose: VScript
  4. //
  5. // Overview
  6. // --------
  7. // VScript is an abstract binding layer that allows code to expose itself to
  8. // multiple scripting languages in a uniform format. Code can expose
  9. // functions, classes, and data to the scripting languages, and can also
  10. // call functions that reside in scripts.
  11. //
  12. // Initializing
  13. // ------------
  14. //
  15. // To create a script virtual machine (VM), grab the global instance of
  16. // IScriptManager, call CreateVM, then call Init on the returned VM. Right
  17. // now you can have multiple VMs, but only VMs for a specific language.
  18. //
  19. // Exposing functions and classes
  20. // ------------------------------
  21. //
  22. // To expose a C++ function to the scripting system, you just need to fill out a
  23. // description block. Using templates, the system will automatically deduce
  24. // all of the binding requirements (parameters and return values). Functions
  25. // are limited as to what the types of the parameters can be. See ScriptVariant_t.
  26. //
  27. // extern IScriptVM *pScriptVM;
  28. // bool Foo( int );
  29. // void Bar();
  30. // float FooBar( int, const char * );
  31. // float OverlyTechnicalName( bool );
  32. //
  33. // void RegisterFuncs()
  34. // {
  35. // ScriptRegisterFunction( pScriptVM, Foo );
  36. // ScriptRegisterFunction( pScriptVM, Bar );
  37. // ScriptRegisterFunction( pScriptVM, FooBar );
  38. // ScriptRegisterFunctionNamed( pScriptVM, OverlyTechnicalName, "SimpleName" );
  39. // }
  40. //
  41. // class CMyClass
  42. // {
  43. // public:
  44. // bool Foo( int );
  45. // void Bar();
  46. // float FooBar( int, const char * );
  47. // float OverlyTechnicalName( bool );
  48. // };
  49. //
  50. // BEGIN_SCRIPTDESC_ROOT( CMyClass )
  51. // DEFINE_SCRIPTFUNC( Foo )
  52. // DEFINE_SCRIPTFUNC( Bar )
  53. // DEFINE_SCRIPTFUNC( FooBar )
  54. // DEFINE_SCRIPTFUNC_NAMED( OverlyTechnicalName, "SimpleMemberName" )
  55. // END_SCRIPTDESC();
  56. //
  57. // class CMyDerivedClass : public CMyClass
  58. // {
  59. // public:
  60. // float DerivedFunc() const;
  61. // };
  62. //
  63. // BEGIN_SCRIPTDESC( CMyDerivedClass, CMyClass )
  64. // DEFINE_SCRIPTFUNC( DerivedFunc )
  65. // END_SCRIPTDESC();
  66. //
  67. // CMyDerivedClass derivedInstance;
  68. //
  69. // void AnotherFunction()
  70. // {
  71. // // Manual class exposure
  72. // pScriptVM->RegisterClass( GetScriptDescForClass( CMyClass ) );
  73. //
  74. // // Auto registration by instance
  75. // pScriptVM->RegisterInstance( &derivedInstance, "theInstance" );
  76. // }
  77. //
  78. // Classes with "DEFINE_SCRIPT_CONSTRUCTOR()" in their description can be instanced within scripts
  79. //
  80. // Scopes
  81. // ------
  82. // Scripts can either be run at the global scope, or in a user defined scope. In the latter case,
  83. // all "globals" within the script are actually in the scope. This can be used to bind private
  84. // data spaces with C++ objects.
  85. //
  86. // Calling a function on a script
  87. // ------------------------------
  88. // Generally, use the "Call" functions. This example is the equivalent of DoIt("Har", 6.0, 99).
  89. //
  90. // hFunction = pScriptVM->LookupFunction( "DoIt", hScope );
  91. // pScriptVM->Call( hFunction, hScope, true, NULL, "Har", 6.0, 99 );
  92. //
  93. //=============================================================================
  94. #ifndef IVSCRIPT_H
  95. #define IVSCRIPT_H
  96. #include "platform.h"
  97. #include "datamap.h"
  98. #include "appframework/iappsystem.h"
  99. #include "tier1/functors.h"
  100. #include "tier0/memdbgon.h"
  101. #if defined( _WIN32 )
  102. #pragma once
  103. #endif
  104. #ifdef VSCRIPT_DLL_EXPORT
  105. #define VSCRIPT_INTERFACE DLL_EXPORT
  106. #define VSCRIPT_OVERLOAD DLL_GLOBAL_EXPORT
  107. #define VSCRIPT_CLASS DLL_CLASS_EXPORT
  108. #else
  109. #define VSCRIPT_INTERFACE DLL_IMPORT
  110. #define VSCRIPT_OVERLOAD DLL_GLOBAL_IMPORT
  111. #define VSCRIPT_CLASS DLL_CLASS_IMPORT
  112. #endif
  113. class CUtlBuffer;
  114. //-----------------------------------------------------------------------------
  115. //
  116. //-----------------------------------------------------------------------------
  117. #define VSCRIPT_INTERFACE_VERSION "VScriptManager009"
  118. //-----------------------------------------------------------------------------
  119. //
  120. //-----------------------------------------------------------------------------
  121. class IScriptVM;
  122. enum ScriptLanguage_t
  123. {
  124. SL_NONE,
  125. SL_GAMEMONKEY,
  126. SL_SQUIRREL,
  127. SL_LUA,
  128. SL_PYTHON,
  129. SL_DEFAULT = SL_SQUIRREL
  130. };
  131. class IScriptManager : public IAppSystem
  132. {
  133. public:
  134. virtual IScriptVM *CreateVM( ScriptLanguage_t language = SL_DEFAULT ) = 0;
  135. virtual void DestroyVM( IScriptVM * ) = 0;
  136. };
  137. //-----------------------------------------------------------------------------
  138. //
  139. //-----------------------------------------------------------------------------
  140. DECLARE_POINTER_HANDLE( HSCRIPT );
  141. #define INVALID_HSCRIPT ((HSCRIPT)-1)
  142. //-----------------------------------------------------------------------------
  143. //
  144. //-----------------------------------------------------------------------------
  145. enum ExtendedFieldType
  146. {
  147. FIELD_TYPEUNKNOWN = FIELD_TYPECOUNT,
  148. FIELD_CSTRING,
  149. FIELD_HSCRIPT,
  150. FIELD_VARIANT,
  151. };
  152. typedef int ScriptDataType_t;
  153. struct ScriptVariant_t;
  154. template <typename T> struct ScriptDeducer { /*enum { FIELD_TYPE = FIELD_TYPEUNKNOWN };*/ };
  155. #define DECLARE_DEDUCE_FIELDTYPE( fieldType, type ) template<> struct ScriptDeducer<type> { enum { FIELD_TYPE = fieldType }; };
  156. DECLARE_DEDUCE_FIELDTYPE( FIELD_VOID, void );
  157. DECLARE_DEDUCE_FIELDTYPE( FIELD_FLOAT, float );
  158. DECLARE_DEDUCE_FIELDTYPE( FIELD_CSTRING, const char * );
  159. DECLARE_DEDUCE_FIELDTYPE( FIELD_CSTRING, char * );
  160. DECLARE_DEDUCE_FIELDTYPE( FIELD_VECTOR, Vector );
  161. DECLARE_DEDUCE_FIELDTYPE( FIELD_VECTOR, const Vector &);
  162. DECLARE_DEDUCE_FIELDTYPE( FIELD_INTEGER, int );
  163. DECLARE_DEDUCE_FIELDTYPE( FIELD_BOOLEAN, bool );
  164. DECLARE_DEDUCE_FIELDTYPE( FIELD_CHARACTER, char );
  165. DECLARE_DEDUCE_FIELDTYPE( FIELD_HSCRIPT, HSCRIPT );
  166. DECLARE_DEDUCE_FIELDTYPE( FIELD_VARIANT, ScriptVariant_t );
  167. #define ScriptDeduceType( T ) ScriptDeducer<T>::FIELD_TYPE
  168. template <typename T>
  169. inline const char * ScriptFieldTypeName()
  170. {
  171. T::using_unknown_script_type();
  172. return NULL;
  173. }
  174. #define DECLARE_NAMED_FIELDTYPE( fieldType, strName ) template <> inline const char * ScriptFieldTypeName<fieldType>() { return strName; }
  175. DECLARE_NAMED_FIELDTYPE( void, "void" );
  176. DECLARE_NAMED_FIELDTYPE( float, "float" );
  177. DECLARE_NAMED_FIELDTYPE( const char *, "cstring" );
  178. DECLARE_NAMED_FIELDTYPE( char *, "cstring" );
  179. DECLARE_NAMED_FIELDTYPE( Vector, "vector" );
  180. DECLARE_NAMED_FIELDTYPE( const Vector&, "vector" );
  181. DECLARE_NAMED_FIELDTYPE( int, "integer" );
  182. DECLARE_NAMED_FIELDTYPE( bool, "boolean" );
  183. DECLARE_NAMED_FIELDTYPE( char, "character" );
  184. DECLARE_NAMED_FIELDTYPE( HSCRIPT, "hscript" );
  185. DECLARE_NAMED_FIELDTYPE( ScriptVariant_t, "variant" );
  186. inline const char * ScriptFieldTypeName( int16 eType)
  187. {
  188. switch( eType )
  189. {
  190. case FIELD_VOID: return "void";
  191. case FIELD_FLOAT: return "float";
  192. case FIELD_CSTRING: return "cstring";
  193. case FIELD_VECTOR: return "vector";
  194. case FIELD_INTEGER: return "integer";
  195. case FIELD_BOOLEAN: return "boolean";
  196. case FIELD_CHARACTER: return "character";
  197. case FIELD_HSCRIPT: return "hscript";
  198. case FIELD_VARIANT: return "variant";
  199. default: return "unknown_script_type";
  200. }
  201. }
  202. //---------------------------------------------------------
  203. struct ScriptFuncDescriptor_t
  204. {
  205. ScriptFuncDescriptor_t()
  206. {
  207. m_pszFunction = NULL;
  208. m_ReturnType = FIELD_TYPEUNKNOWN;
  209. m_pszDescription = NULL;
  210. }
  211. const char *m_pszScriptName;
  212. const char *m_pszFunction;
  213. const char *m_pszDescription;
  214. ScriptDataType_t m_ReturnType;
  215. CUtlVector<ScriptDataType_t> m_Parameters;
  216. };
  217. //---------------------------------------------------------
  218. // Prefix a script description with this in order to not show the function or class in help
  219. #define SCRIPT_HIDE "@"
  220. // Prefix a script description of a class to indicate it is a singleton and the single instance should be in the help
  221. #define SCRIPT_SINGLETON "!"
  222. // Prefix a script description with this to indicate it should be represented using an alternate name
  223. #define SCRIPT_ALIAS( alias, description ) "#" alias ":" description
  224. //---------------------------------------------------------
  225. enum ScriptFuncBindingFlags_t
  226. {
  227. SF_MEMBER_FUNC = 0x01,
  228. };
  229. #ifdef _PS3
  230. typedef void* ScriptFunctionBindingStorageType_t; // Function descriptor is actually 64-bit
  231. #else
  232. typedef void* ScriptFunctionBindingStorageType_t;
  233. #endif
  234. typedef bool (*ScriptBindingFunc_t)( ScriptFunctionBindingStorageType_t pFunction, void *pContext, ScriptVariant_t *pArguments, int nArguments, ScriptVariant_t *pReturn );
  235. struct ScriptFunctionBinding_t
  236. {
  237. ScriptFuncDescriptor_t m_desc;
  238. ScriptBindingFunc_t m_pfnBinding;
  239. ScriptFunctionBindingStorageType_t m_pFunction;
  240. unsigned m_flags;
  241. };
  242. //---------------------------------------------------------
  243. class IScriptInstanceHelper
  244. {
  245. public:
  246. virtual void *GetProxied( void *p ) { return p; }
  247. virtual bool ToString( void *p, char *pBuf, int bufSize ) { return false; }
  248. virtual void *BindOnRead( HSCRIPT hInstance, void *pOld, const char *pszId ) { return NULL; }
  249. };
  250. //---------------------------------------------------------
  251. struct ScriptClassDesc_t
  252. {
  253. ScriptClassDesc_t( void (*pfnInitializer)() ) : m_pszScriptName( 0 ), m_pszClassname( 0 ), m_pszDescription( 0 ), m_pBaseDesc( 0 ), m_pfnConstruct( 0 ), m_pfnDestruct( 0 ), pHelper(NULL)
  254. {
  255. (*pfnInitializer)();
  256. ScriptClassDesc_t **ppHead = GetDescList();
  257. m_pNextDesc = *ppHead;
  258. *ppHead = this;
  259. }
  260. const char * m_pszScriptName;
  261. const char * m_pszClassname;
  262. const char * m_pszDescription;
  263. ScriptClassDesc_t * m_pBaseDesc;
  264. CUtlVector<ScriptFunctionBinding_t> m_FunctionBindings;
  265. void *(*m_pfnConstruct)();
  266. void (*m_pfnDestruct)( void *);
  267. IScriptInstanceHelper * pHelper; // optional helper
  268. ScriptClassDesc_t * m_pNextDesc;
  269. static ScriptClassDesc_t **GetDescList()
  270. {
  271. static ScriptClassDesc_t *pHead;
  272. return &pHead;
  273. }
  274. };
  275. //---------------------------------------------------------
  276. // A simple variant type. Intentionally not full featured (no implicit conversion, no memory management)
  277. //---------------------------------------------------------
  278. enum SVFlags_t
  279. {
  280. SV_FREE = 0x01,
  281. };
  282. #pragma warning(push)
  283. #pragma warning(disable:4800)
  284. struct ScriptVariant_t
  285. {
  286. ScriptVariant_t() : m_flags( 0 ), m_type( FIELD_VOID ) { m_pVector = 0; }
  287. ScriptVariant_t( int val ) : m_flags( 0 ), m_type( FIELD_INTEGER ) { m_int = val;}
  288. ScriptVariant_t( float val ) : m_flags( 0 ), m_type( FIELD_FLOAT ) { m_float = val; }
  289. ScriptVariant_t( double val ) : m_flags( 0 ), m_type( FIELD_FLOAT ) { m_float = (float)val; }
  290. ScriptVariant_t( char val ) : m_flags( 0 ), m_type( FIELD_CHARACTER ) { m_char = val; }
  291. ScriptVariant_t( bool val ) : m_flags( 0 ), m_type( FIELD_BOOLEAN ) { m_bool = val; }
  292. ScriptVariant_t( HSCRIPT val ) : m_flags( 0 ), m_type( FIELD_HSCRIPT ) { m_hScript = val; }
  293. ScriptVariant_t( const Vector &val, bool bCopy = false ) : m_flags( 0 ), m_type( FIELD_VECTOR ) { if ( !bCopy ) { m_pVector = &val; } else { m_pVector = new Vector( val ); m_flags |= SV_FREE; } }
  294. ScriptVariant_t( const Vector *val, bool bCopy = false ) : m_flags( 0 ), m_type( FIELD_VECTOR ) { if ( !bCopy ) { m_pVector = val; } else { m_pVector = new Vector( *val ); m_flags |= SV_FREE; } }
  295. ScriptVariant_t( const char *val , bool bCopy = false ) : m_flags( 0 ), m_type( FIELD_CSTRING ) { if ( !bCopy ) { m_pszString = val; } else { m_pszString = strdup( val ); m_flags |= SV_FREE; } }
  296. bool IsNull() const { return (m_type == FIELD_VOID ); }
  297. operator int() const { Assert( m_type == FIELD_INTEGER ); return m_int; }
  298. operator int64() const { Assert( m_type == FIELD_INTEGER ); return static_cast<int64>(m_int); }
  299. operator float() const { Assert( m_type == FIELD_FLOAT ); return m_float; }
  300. operator const char *() const { Assert( m_type == FIELD_CSTRING ); return ( m_pszString ) ? m_pszString : ""; }
  301. operator const Vector &() const { Assert( m_type == FIELD_VECTOR ); static Vector vecNull(0, 0, 0); return (m_pVector) ? *m_pVector : vecNull; }
  302. operator char() const { Assert( m_type == FIELD_CHARACTER ); return m_char; }
  303. operator bool() const { Assert( m_type == FIELD_BOOLEAN ); return m_bool; }
  304. operator HSCRIPT() const { Assert( m_type == FIELD_HSCRIPT ); return m_hScript; }
  305. void operator=( int i ) { m_type = FIELD_INTEGER; m_int = i; }
  306. void operator=( int64 i ) { m_type = FIELD_INTEGER; m_int = i; }
  307. void operator=( float f ) { m_type = FIELD_FLOAT; m_float = f; }
  308. void operator=( double f ) { m_type = FIELD_FLOAT; m_float = (float)f; }
  309. void operator=( const Vector &vec ) { m_type = FIELD_VECTOR; m_pVector = &vec; }
  310. void operator=( const Vector *vec ) { m_type = FIELD_VECTOR; m_pVector = vec; }
  311. void operator=( const char *psz ) { m_type = FIELD_CSTRING; m_pszString = psz; }
  312. void operator=( char c ) { m_type = FIELD_CHARACTER; m_char = c; }
  313. void operator=( bool b ) { m_type = FIELD_BOOLEAN; m_bool = b; }
  314. void operator=( HSCRIPT h ) { m_type = FIELD_HSCRIPT; m_hScript = h; }
  315. void Free() { if ( ( m_flags & SV_FREE ) && ( m_type == FIELD_HSCRIPT || m_type == FIELD_VECTOR || m_type == FIELD_CSTRING ) ) delete m_pszString; } // Generally only needed for return results
  316. template <typename T>
  317. T Get()
  318. {
  319. T value;
  320. AssignTo( &value );
  321. return value;
  322. }
  323. template <typename T>
  324. bool AssignTo( T *pDest )
  325. {
  326. ScriptDataType_t destType = ScriptDeduceType( T );
  327. if ( destType == FIELD_TYPEUNKNOWN )
  328. {
  329. DevWarning( "Unable to convert script variant to unknown type\n" );
  330. }
  331. if ( destType == m_type )
  332. {
  333. *pDest = *this;
  334. return true;
  335. }
  336. if ( m_type != FIELD_VECTOR && m_type != FIELD_CSTRING && destType != FIELD_VECTOR && destType != FIELD_CSTRING )
  337. {
  338. switch ( m_type )
  339. {
  340. case FIELD_VOID: *pDest = 0; break;
  341. case FIELD_INTEGER: *pDest = m_int; return true;
  342. case FIELD_FLOAT: *pDest = m_float; return true;
  343. case FIELD_CHARACTER: *pDest = m_char; return true;
  344. case FIELD_BOOLEAN: *pDest = m_bool; return true;
  345. case FIELD_HSCRIPT: *pDest = m_hScript; return true;
  346. }
  347. }
  348. else
  349. {
  350. DevWarning( "No free conversion of %s script variant to %s right now\n",
  351. ScriptFieldTypeName( m_type ), ScriptFieldTypeName<T>() );
  352. if ( destType != FIELD_VECTOR )
  353. {
  354. *pDest = 0;
  355. }
  356. }
  357. return false;
  358. }
  359. bool AssignTo( float *pDest )
  360. {
  361. switch( m_type )
  362. {
  363. case FIELD_VOID: *pDest = 0; return false;
  364. case FIELD_INTEGER: *pDest = m_int; return true;
  365. case FIELD_FLOAT: *pDest = m_float; return true;
  366. case FIELD_BOOLEAN: *pDest = m_bool; return true;
  367. default:
  368. DevWarning( "No conversion from %s to float now\n", ScriptFieldTypeName( m_type ) );
  369. return false;
  370. }
  371. }
  372. bool AssignTo( int *pDest )
  373. {
  374. switch( m_type )
  375. {
  376. case FIELD_VOID: *pDest = 0; return false;
  377. case FIELD_INTEGER: *pDest = m_int; return true;
  378. case FIELD_FLOAT: *pDest = ( int )m_float; return true;
  379. case FIELD_BOOLEAN: *pDest = m_bool; return true;
  380. default:
  381. DevWarning( "No conversion from %s to int now\n", ScriptFieldTypeName( m_type ) );
  382. return false;
  383. }
  384. }
  385. bool AssignTo( bool *pDest )
  386. {
  387. switch( m_type )
  388. {
  389. case FIELD_VOID: *pDest = 0; return false;
  390. case FIELD_INTEGER: *pDest = m_int; return true;
  391. case FIELD_FLOAT: *pDest = m_float; return true;
  392. case FIELD_BOOLEAN: *pDest = m_bool; return true;
  393. default:
  394. DevWarning( "No conversion from %s to bool now\n", ScriptFieldTypeName( m_type ) );
  395. return false;
  396. }
  397. }
  398. bool AssignTo( char **pDest )
  399. {
  400. DevWarning( "No free conversion of string or vector script variant right now\n" );
  401. // If want to support this, probably need to malloc string and require free on other side [3/24/2008 tom]
  402. *pDest = "";
  403. return false;
  404. }
  405. bool AssignTo( ScriptVariant_t *pDest )
  406. {
  407. pDest->m_type = m_type;
  408. if ( m_type == FIELD_VECTOR )
  409. {
  410. pDest->m_pVector = new Vector;
  411. ((Vector *)(pDest->m_pVector))->Init( m_pVector->x, m_pVector->y, m_pVector->z );
  412. pDest->m_flags |= SV_FREE;
  413. }
  414. else if ( m_type == FIELD_CSTRING )
  415. {
  416. pDest->m_pszString = strdup( m_pszString );
  417. pDest->m_flags |= SV_FREE;
  418. }
  419. else
  420. {
  421. pDest->m_int = m_int;
  422. }
  423. return false;
  424. }
  425. union
  426. {
  427. int m_int;
  428. float m_float;
  429. const char * m_pszString;
  430. const Vector * m_pVector;
  431. char m_char;
  432. bool m_bool;
  433. HSCRIPT m_hScript;
  434. };
  435. int16 m_type;
  436. int16 m_flags;
  437. private:
  438. };
  439. #define SCRIPT_VARIANT_NULL ScriptVariant_t()
  440. #pragma warning(pop)
  441. //-----------------------------------------------------------------------------
  442. //
  443. //-----------------------------------------------------------------------------
  444. #include "vscript_templates.h"
  445. // Lower level macro primitives
  446. #define ScriptInitFunctionBinding( pScriptFunction, func ) ScriptInitFunctionBindingNamed( pScriptFunction, func, #func )
  447. #define ScriptInitFunctionBindingNamed( pScriptFunction, func, scriptName ) do { ScriptInitFuncDescriptorNamed( (&(pScriptFunction)->m_desc), func, scriptName ); (pScriptFunction)->m_pfnBinding = ScriptCreateBinding( &func ); (pScriptFunction)->m_pFunction = ScriptConvertFreeFuncPtrToVoid( &func ); } while (0)
  448. #define ScriptInitMemberFunctionBinding( pScriptFunction, class, func ) ScriptInitMemberFunctionBinding_( pScriptFunction, class, func, #func )
  449. #define ScriptInitMemberFunctionBindingNamed( pScriptFunction, class, func, scriptName ) ScriptInitMemberFunctionBinding_( pScriptFunction, class, func, scriptName )
  450. #define ScriptInitMemberFunctionBinding_( pScriptFunction, class, func, scriptName ) do { ScriptInitMemberFuncDescriptor_( (&(pScriptFunction)->m_desc), class, func, scriptName ); (pScriptFunction)->m_pfnBinding = ScriptCreateBinding( ((class *)0), &class::func ); (pScriptFunction)->m_pFunction = ScriptConvertFuncPtrToVoid( &class::func ); (pScriptFunction)->m_flags = SF_MEMBER_FUNC; } while (0)
  451. #define ScriptInitClassDesc( pClassDesc, class, pBaseClassDesc ) ScriptInitClassDescNamed( pClassDesc, class, pBaseClassDesc, #class )
  452. #define ScriptInitClassDescNamed( pClassDesc, class, pBaseClassDesc, scriptName ) ScriptInitClassDescNamed_( pClassDesc, class, pBaseClassDesc, scriptName )
  453. #define ScriptInitClassDescNoBase( pClassDesc, class ) ScriptInitClassDescNoBaseNamed( pClassDesc, class, #class )
  454. #define ScriptInitClassDescNoBaseNamed( pClassDesc, class, scriptName ) ScriptInitClassDescNamed_( pClassDesc, class, NULL, scriptName )
  455. #define ScriptInitClassDescNamed_( pClassDesc, class, pBaseClassDesc, scriptName ) do { (pClassDesc)->m_pszScriptName = scriptName; (pClassDesc)->m_pszClassname = #class; (pClassDesc)->m_pBaseDesc = pBaseClassDesc; } while ( 0 )
  456. #define ScriptAddFunctionToClassDesc( pClassDesc, class, func, description ) ScriptAddFunctionToClassDescNamed( pClassDesc, class, func, #func, description )
  457. #define ScriptAddFunctionToClassDescNamed( pClassDesc, class, func, scriptName, description ) do { ScriptFunctionBinding_t *pBinding = &((pClassDesc)->m_FunctionBindings[(pClassDesc)->m_FunctionBindings.AddToTail()]); pBinding->m_desc.m_pszDescription = description; ScriptInitMemberFunctionBindingNamed( pBinding, class, func, scriptName ); } while (0)
  458. //-----------------------------------------------------------------------------
  459. //
  460. //-----------------------------------------------------------------------------
  461. #define ScriptRegisterFunction( pVM, func, description ) ScriptRegisterFunctionNamed( pVM, func, #func, description )
  462. #define ScriptRegisterFunctionNamed( pVM, func, scriptName, description ) do { static ScriptFunctionBinding_t binding; binding.m_desc.m_pszDescription = description; binding.m_desc.m_Parameters.RemoveAll(); ScriptInitFunctionBindingNamed( &binding, func, scriptName ); pVM->RegisterFunction( &binding ); } while (0)
  463. //-----------------------------------------------------------------------------
  464. //
  465. //-----------------------------------------------------------------------------
  466. #define ALLOW_SCRIPT_ACCESS() template <typename T> friend ScriptClassDesc_t *GetScriptDesc(T *);
  467. #define BEGIN_SCRIPTDESC( className, baseClass, description ) BEGIN_SCRIPTDESC_NAMED( className, baseClass, #className, description )
  468. #define BEGIN_SCRIPTDESC_ROOT( className, description ) BEGIN_SCRIPTDESC_ROOT_NAMED( className, #className, description )
  469. #if defined(_MSC_VER) && (_MSC_VER < 1800)
  470. #define DEFINE_SCRIPTDESC_FUNCTION( className, baseClass ) \
  471. ScriptClassDesc_t * GetScriptDesc( className * )
  472. #else
  473. #define DEFINE_SCRIPTDESC_FUNCTION( className, baseClass ) \
  474. template <> ScriptClassDesc_t * GetScriptDesc<baseClass>( baseClass *); \
  475. template <> ScriptClassDesc_t * GetScriptDesc<className>( className *)
  476. #endif
  477. struct ScriptNoBase_t;
  478. // We use template specialization to allow classes to optionally override this function.
  479. // For a given class, if this function is NOT overridden, the class' descriptor will use the base class'
  480. // IScriptInstanceHelper object.
  481. // If this function IS overridden, it will use the return value of the overridden function
  482. template < typename TScriptClass >
  483. IScriptInstanceHelper *GetScriptInstanceHelperOverride( IScriptInstanceHelper *pBaseClassHelper )
  484. {
  485. return pBaseClassHelper;
  486. }
  487. inline IScriptInstanceHelper *GetScriptInstanceHelper_ScriptNoBase_t()
  488. {
  489. return NULL;
  490. }
  491. #define BEGIN_SCRIPTDESC_NAMED( className, baseClass, scriptName, description ) \
  492. IScriptInstanceHelper *GetScriptInstanceHelper_##baseClass(); \
  493. IScriptInstanceHelper *GetScriptInstanceHelper_##className() \
  494. { \
  495. return GetScriptInstanceHelperOverride< className >( GetScriptInstanceHelper_##baseClass() ); \
  496. }; \
  497. extern void Init##className##ScriptDesc(); \
  498. ScriptClassDesc_t g_##className##_ScriptDesc( &Init##className##ScriptDesc ); \
  499. DEFINE_SCRIPTDESC_FUNCTION( className, baseClass ) \
  500. { \
  501. return &g_##className##_ScriptDesc; \
  502. } \
  503. \
  504. void Init##className##ScriptDesc() \
  505. { \
  506. static bool bInitialized; \
  507. if ( bInitialized ) \
  508. { \
  509. return; \
  510. } \
  511. \
  512. bInitialized = true; \
  513. \
  514. typedef className _className; \
  515. ScriptClassDesc_t *pDesc = &g_##className##_ScriptDesc; \
  516. pDesc->m_pszDescription = description; \
  517. ScriptInitClassDescNamed( pDesc, className, GetScriptDescForClass( baseClass ), scriptName ); \
  518. pDesc->pHelper = GetScriptInstanceHelper_##className();
  519. #define BEGIN_SCRIPTDESC_ROOT_NAMED( className, scriptName, description ) \
  520. BEGIN_SCRIPTDESC_NAMED( className, ScriptNoBase_t, scriptName, description )
  521. #define END_SCRIPTDESC() \
  522. return; \
  523. }
  524. #define DEFINE_SCRIPTFUNC( func, description ) DEFINE_SCRIPTFUNC_NAMED( func, #func, description )
  525. #define DEFINE_SCRIPTFUNC_NAMED( func, scriptName, description ) ScriptAddFunctionToClassDescNamed( pDesc, _className, func, scriptName, description );
  526. #define DEFINE_SCRIPT_CONSTRUCTOR() ScriptAddConstructorToClassDesc( pDesc, _className );
  527. #define DEFINE_SCRIPT_INSTANCE_HELPER( className, p ) template <> IScriptInstanceHelper *GetScriptInstanceHelperOverride< className >( IScriptInstanceHelper * ) { return p; }
  528. template <typename T> ScriptClassDesc_t *GetScriptDesc(T *);
  529. template <>
  530. #ifdef _PS3
  531. static
  532. #endif
  533. inline ScriptClassDesc_t *GetScriptDesc<ScriptNoBase_t>( ScriptNoBase_t *) { return NULL; }
  534. #define GetScriptDescForClass( className ) GetScriptDesc( ( className *)NULL )
  535. //-----------------------------------------------------------------------------
  536. //
  537. //-----------------------------------------------------------------------------
  538. template <typename T>
  539. class CScriptConstructor
  540. {
  541. public:
  542. static void *Construct() { return new T; }
  543. static void Destruct( void *p ) { delete (T *)p; }
  544. };
  545. #define ScriptAddConstructorToClassDesc( pClassDesc, class ) do { (pClassDesc)->m_pfnConstruct = &CScriptConstructor<class>::Construct; (pClassDesc)->m_pfnDestruct = &CScriptConstructor<class>::Destruct; } while (0)
  546. //-----------------------------------------------------------------------------
  547. //
  548. //-----------------------------------------------------------------------------
  549. enum ScriptErrorLevel_t
  550. {
  551. SCRIPT_LEVEL_WARNING = 0,
  552. SCRIPT_LEVEL_ERROR,
  553. };
  554. typedef void ( *ScriptOutputFunc_t )( const char *pszText );
  555. typedef bool ( *ScriptErrorFunc_t )( ScriptErrorLevel_t eLevel, const char *pszText );
  556. //-----------------------------------------------------------------------------
  557. //
  558. //-----------------------------------------------------------------------------
  559. #ifdef RegisterClass
  560. #undef RegisterClass
  561. #endif
  562. enum ScriptStatus_t
  563. {
  564. SCRIPT_ERROR = -1,
  565. SCRIPT_DONE,
  566. SCRIPT_RUNNING,
  567. };
  568. class IScriptVM
  569. {
  570. public:
  571. virtual bool Init() = 0;
  572. virtual void Shutdown() = 0;
  573. virtual bool ConnectDebugger() = 0;
  574. virtual void DisconnectDebugger() = 0;
  575. virtual ScriptLanguage_t GetLanguage() = 0;
  576. virtual const char *GetLanguageName() = 0;
  577. virtual void AddSearchPath( const char *pszSearchPath ) = 0;
  578. //--------------------------------------------------------
  579. virtual bool Frame( float simTime ) = 0;
  580. //--------------------------------------------------------
  581. // Simple script usage
  582. //--------------------------------------------------------
  583. virtual ScriptStatus_t Run( const char *pszScript, bool bWait = true ) = 0;
  584. inline ScriptStatus_t Run( const unsigned char *pszScript, bool bWait = true ) { return Run( (char *)pszScript, bWait ); }
  585. //--------------------------------------------------------
  586. // Compilation
  587. //--------------------------------------------------------
  588. virtual HSCRIPT CompileScript( const char *pszScript, const char *pszId = NULL ) = 0;
  589. inline HSCRIPT CompileScript( const unsigned char *pszScript, const char *pszId = NULL ) { return CompileScript( (char *)pszScript, pszId ); }
  590. virtual void ReleaseScript( HSCRIPT ) = 0;
  591. //--------------------------------------------------------
  592. // Execution of compiled
  593. //--------------------------------------------------------
  594. virtual ScriptStatus_t Run( HSCRIPT hScript, HSCRIPT hScope = NULL, bool bWait = true ) = 0;
  595. virtual ScriptStatus_t Run( HSCRIPT hScript, bool bWait ) = 0;
  596. //--------------------------------------------------------
  597. // Scope
  598. //--------------------------------------------------------
  599. virtual HSCRIPT CreateScope( const char *pszScope, HSCRIPT hParent = NULL ) = 0;
  600. virtual void ReleaseScope( HSCRIPT hScript ) = 0;
  601. //--------------------------------------------------------
  602. // Script functions
  603. //--------------------------------------------------------
  604. virtual HSCRIPT LookupFunction( const char *pszFunction, HSCRIPT hScope = NULL ) = 0;
  605. virtual void ReleaseFunction( HSCRIPT hScript ) = 0;
  606. //--------------------------------------------------------
  607. // Script functions (raw, use Call())
  608. //--------------------------------------------------------
  609. virtual ScriptStatus_t ExecuteFunction( HSCRIPT hFunction, ScriptVariant_t *pArgs, int nArgs, ScriptVariant_t *pReturn, HSCRIPT hScope, bool bWait ) = 0;
  610. //--------------------------------------------------------
  611. // External functions
  612. //--------------------------------------------------------
  613. virtual void RegisterFunction( ScriptFunctionBinding_t *pScriptFunction ) = 0;
  614. //--------------------------------------------------------
  615. // External classes
  616. //--------------------------------------------------------
  617. virtual bool RegisterClass( ScriptClassDesc_t *pClassDesc ) = 0;
  618. void RegisterAllClasses()
  619. {
  620. ScriptClassDesc_t *pCurrent = *ScriptClassDesc_t::GetDescList();
  621. while ( pCurrent )
  622. {
  623. RegisterClass( pCurrent );
  624. pCurrent = pCurrent->m_pNextDesc;
  625. }
  626. }
  627. //--------------------------------------------------------
  628. // External instances. Note class will be auto-registered.
  629. //--------------------------------------------------------
  630. virtual HSCRIPT RegisterInstance( ScriptClassDesc_t *pDesc, void *pInstance ) = 0;
  631. virtual void SetInstanceUniqeId( HSCRIPT hInstance, const char *pszId ) = 0;
  632. template <typename T> HSCRIPT RegisterInstance( T *pInstance ) { return RegisterInstance( GetScriptDesc( pInstance ), pInstance ); }
  633. template <typename T> HSCRIPT RegisterInstance( T *pInstance, const char *pszInstance, HSCRIPT hScope = NULL) { HSCRIPT hInstance = RegisterInstance( GetScriptDesc( pInstance ), pInstance ); SetValue( hScope, pszInstance, hInstance ); return hInstance; }
  634. virtual void RemoveInstance( HSCRIPT ) = 0;
  635. void RemoveInstance( HSCRIPT hInstance, const char *pszInstance, HSCRIPT hScope = NULL ) { ClearValue( hScope, pszInstance ); RemoveInstance( hInstance ); }
  636. void RemoveInstance( const char *pszInstance, HSCRIPT hScope = NULL ) { ScriptVariant_t val; if ( GetValue( hScope, pszInstance, &val ) ) { if ( val.m_type == FIELD_HSCRIPT ) { RemoveInstance( val, pszInstance, hScope ); } ReleaseValue( val ); } }
  637. virtual void *GetInstanceValue( HSCRIPT hInstance, ScriptClassDesc_t *pExpectedType = NULL ) = 0;
  638. //----------------------------------------------------------------------------
  639. virtual bool GenerateUniqueKey( const char *pszRoot, char *pBuf, int nBufSize ) = 0;
  640. //----------------------------------------------------------------------------
  641. virtual bool ValueExists( HSCRIPT hScope, const char *pszKey ) = 0;
  642. bool ValueExists( const char *pszKey ) { return ValueExists( NULL, pszKey ); }
  643. virtual bool SetValue( HSCRIPT hScope, const char *pszKey, const char *pszValue ) = 0;
  644. virtual bool SetValue( HSCRIPT hScope, const char *pszKey, const ScriptVariant_t &value ) = 0;
  645. bool SetValue( const char *pszKey, const ScriptVariant_t &value ) { return SetValue(NULL, pszKey, value ); }
  646. virtual void CreateTable( ScriptVariant_t &Table ) = 0;
  647. virtual int GetNumTableEntries( HSCRIPT hScope ) = 0;
  648. virtual int GetKeyValue( HSCRIPT hScope, int nIterator, ScriptVariant_t *pKey, ScriptVariant_t *pValue ) = 0;
  649. virtual bool GetValue( HSCRIPT hScope, const char *pszKey, ScriptVariant_t *pValue ) = 0;
  650. bool GetValue( const char *pszKey, ScriptVariant_t *pValue ) { return GetValue(NULL, pszKey, pValue ); }
  651. virtual void ReleaseValue( ScriptVariant_t &value ) = 0;
  652. virtual bool ClearValue( HSCRIPT hScope, const char *pszKey ) = 0;
  653. bool ClearValue( const char *pszKey) { return ClearValue( NULL, pszKey ); }
  654. //----------------------------------------------------------------------------
  655. virtual void WriteState( CUtlBuffer *pBuffer ) = 0;
  656. virtual void ReadState( CUtlBuffer *pBuffer ) = 0;
  657. virtual void RemoveOrphanInstances() = 0;
  658. virtual void DumpState() = 0;
  659. virtual void SetOutputCallback( ScriptOutputFunc_t pFunc ) = 0;
  660. virtual void SetErrorCallback( ScriptErrorFunc_t pFunc ) = 0;
  661. //----------------------------------------------------------------------------
  662. virtual bool RaiseException( const char *pszExceptionText ) = 0;
  663. //----------------------------------------------------------------------------
  664. // Call API
  665. //
  666. // Note for string and vector return types, the caller must delete the pointed to memory
  667. //----------------------------------------------------------------------------
  668. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope = NULL, bool bWait = true, ScriptVariant_t *pReturn = NULL )
  669. {
  670. return ExecuteFunction( hFunction, NULL, 0, pReturn, hScope, bWait );
  671. }
  672. template <typename ARG_TYPE_1>
  673. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1 )
  674. {
  675. ScriptVariant_t args[1]; args[0] = arg1;
  676. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  677. }
  678. template <typename ARG_TYPE_1, typename ARG_TYPE_2>
  679. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2 )
  680. {
  681. ScriptVariant_t args[2]; args[0] = arg1; args[1] = arg2;
  682. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  683. }
  684. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3>
  685. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3 )
  686. {
  687. ScriptVariant_t args[3]; args[0] = arg1; args[1] = arg2; args[2] = arg3;
  688. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  689. }
  690. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4>
  691. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4 )
  692. {
  693. ScriptVariant_t args[4]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4;
  694. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  695. }
  696. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5>
  697. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5 )
  698. {
  699. ScriptVariant_t args[5]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5;
  700. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  701. }
  702. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6>
  703. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6 )
  704. {
  705. ScriptVariant_t args[6]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6;
  706. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  707. }
  708. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7>
  709. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7 )
  710. {
  711. ScriptVariant_t args[7]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7;
  712. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  713. }
  714. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8>
  715. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8 )
  716. {
  717. ScriptVariant_t args[8]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8;
  718. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  719. }
  720. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9>
  721. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9 )
  722. {
  723. ScriptVariant_t args[9]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9;
  724. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  725. }
  726. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10>
  727. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10 )
  728. {
  729. ScriptVariant_t args[10]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10;
  730. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  731. }
  732. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11>
  733. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11 )
  734. {
  735. ScriptVariant_t args[11]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11;
  736. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  737. }
  738. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12>
  739. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12 )
  740. {
  741. ScriptVariant_t args[12]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12;
  742. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  743. }
  744. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12, typename ARG_TYPE_13>
  745. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12, ARG_TYPE_13 arg13 )
  746. {
  747. ScriptVariant_t args[13]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12; args[12] = arg13;
  748. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  749. }
  750. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12, typename ARG_TYPE_13, typename ARG_TYPE_14>
  751. ScriptStatus_t Call( HSCRIPT hFunction, HSCRIPT hScope, bool bWait, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12, ARG_TYPE_13 arg13, ARG_TYPE_14 arg14 )
  752. {
  753. ScriptVariant_t args[14]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12; args[12] = arg13; args[13] = arg14;
  754. return ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, hScope, bWait );
  755. }
  756. };
  757. //-----------------------------------------------------------------------------
  758. // Script scope helper class
  759. //-----------------------------------------------------------------------------
  760. class CDefScriptScopeBase
  761. {
  762. public:
  763. static IScriptVM *GetVM()
  764. {
  765. extern IScriptVM *g_pScriptVM;
  766. return g_pScriptVM;
  767. }
  768. };
  769. template <class BASE_CLASS = CDefScriptScopeBase>
  770. class CScriptScopeT : public CDefScriptScopeBase
  771. {
  772. public:
  773. CScriptScopeT() :
  774. m_hScope( INVALID_HSCRIPT ),
  775. m_flags( 0 )
  776. {
  777. }
  778. ~CScriptScopeT()
  779. {
  780. Term();
  781. }
  782. bool IsInitialized()
  783. {
  784. return m_hScope != INVALID_HSCRIPT;
  785. }
  786. bool Init( const char *pszName )
  787. {
  788. m_hScope = GetVM()->CreateScope( pszName );
  789. return ( m_hScope != NULL );
  790. }
  791. bool Init( HSCRIPT hScope, bool bExternal = true )
  792. {
  793. if ( bExternal )
  794. {
  795. m_flags |= EXTERNAL;
  796. }
  797. m_hScope = hScope;
  798. return ( m_hScope != NULL );
  799. }
  800. bool InitGlobal()
  801. {
  802. Assert( 0 ); // todo [3/24/2008 tom]
  803. m_hScope = GetVM()->CreateScope( "" );
  804. return ( m_hScope != NULL );
  805. }
  806. void Term()
  807. {
  808. if ( m_hScope != INVALID_HSCRIPT )
  809. {
  810. IScriptVM *pVM = GetVM();
  811. if ( pVM )
  812. {
  813. for ( int i = 0; i < m_FuncHandles.Count(); i++ )
  814. {
  815. pVM->ReleaseFunction( *m_FuncHandles[i] );
  816. }
  817. }
  818. m_FuncHandles.Purge();
  819. if ( m_hScope && pVM && !(m_flags & EXTERNAL) )
  820. {
  821. pVM->ReleaseScope( m_hScope );
  822. }
  823. m_hScope = INVALID_HSCRIPT;
  824. }
  825. m_flags = 0;
  826. }
  827. void InvalidateCachedValues()
  828. {
  829. IScriptVM *pVM = GetVM();
  830. for ( int i = 0; i < m_FuncHandles.Count(); i++ )
  831. {
  832. if ( *m_FuncHandles[i] )
  833. pVM->ReleaseFunction( *m_FuncHandles[i] );
  834. *m_FuncHandles[i] = INVALID_HSCRIPT;
  835. }
  836. m_FuncHandles.RemoveAll();
  837. }
  838. operator HSCRIPT()
  839. {
  840. return ( m_hScope != INVALID_HSCRIPT ) ? m_hScope : NULL;
  841. }
  842. bool ValueExists( const char *pszKey ) { return GetVM()->ValueExists( m_hScope, pszKey ); }
  843. bool SetValue( const char *pszKey, const ScriptVariant_t &value ) { return GetVM()->SetValue(m_hScope, pszKey, value ); }
  844. bool GetValue( const char *pszKey, ScriptVariant_t *pValue ) { return GetVM()->GetValue(m_hScope, pszKey, pValue ); }
  845. void ReleaseValue( ScriptVariant_t &value ) { GetVM()->ReleaseValue( value ); }
  846. bool ClearValue( const char *pszKey) { return GetVM()->ClearValue( m_hScope, pszKey ); }
  847. ScriptStatus_t Run( HSCRIPT hScript )
  848. {
  849. InvalidateCachedValues();
  850. return GetVM()->Run( hScript, m_hScope );
  851. }
  852. ScriptStatus_t Run( const char *pszScriptText, const char *pszScriptName = NULL )
  853. {
  854. InvalidateCachedValues();
  855. HSCRIPT hScript = GetVM()->CompileScript( pszScriptText, pszScriptName );
  856. if ( hScript )
  857. {
  858. ScriptStatus_t result = GetVM()->Run( hScript, m_hScope );
  859. GetVM()->ReleaseScript( hScript );
  860. return result;
  861. }
  862. return SCRIPT_ERROR;
  863. }
  864. ScriptStatus_t Run( const unsigned char *pszScriptText, const char *pszScriptName = NULL )
  865. {
  866. return Run( (const char *)pszScriptText, pszScriptName);
  867. }
  868. HSCRIPT LookupFunction( const char *pszFunction )
  869. {
  870. return GetVM()->LookupFunction( pszFunction, m_hScope );
  871. }
  872. void ReleaseFunction( HSCRIPT hScript )
  873. {
  874. GetVM()->ReleaseFunction( hScript );
  875. }
  876. bool FunctionExists( const char *pszFunction )
  877. {
  878. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  879. GetVM()->ReleaseFunction( hFunction );
  880. return ( hFunction != NULL ) ;
  881. }
  882. //-----------------------------------------------------
  883. enum Flags_t
  884. {
  885. EXTERNAL = 0x01,
  886. };
  887. //-----------------------------------------------------
  888. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn = NULL )
  889. {
  890. return GetVM()->ExecuteFunction( hFunction, NULL, 0, pReturn, m_hScope, true );
  891. }
  892. template <typename ARG_TYPE_1>
  893. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1 )
  894. {
  895. ScriptVariant_t args[1]; args[0] = arg1;
  896. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  897. }
  898. template <typename ARG_TYPE_1, typename ARG_TYPE_2>
  899. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2 )
  900. {
  901. ScriptVariant_t args[2]; args[0] = arg1; args[1] = arg2;
  902. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  903. }
  904. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3>
  905. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3 )
  906. {
  907. ScriptVariant_t args[3]; args[0] = arg1; args[1] = arg2; args[2] = arg3;
  908. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  909. }
  910. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4>
  911. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4 )
  912. {
  913. ScriptVariant_t args[4]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4;
  914. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  915. }
  916. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5>
  917. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5 )
  918. {
  919. ScriptVariant_t args[5]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5;
  920. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  921. }
  922. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6>
  923. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6 )
  924. {
  925. ScriptVariant_t args[6]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6;
  926. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  927. }
  928. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7>
  929. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7 )
  930. {
  931. ScriptVariant_t args[7]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7;
  932. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  933. }
  934. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8>
  935. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8 )
  936. {
  937. ScriptVariant_t args[8]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8;
  938. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  939. }
  940. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9>
  941. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9 )
  942. {
  943. ScriptVariant_t args[9]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9;
  944. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  945. }
  946. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10>
  947. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10 )
  948. {
  949. ScriptVariant_t args[10]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10;
  950. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  951. }
  952. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11>
  953. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11 )
  954. {
  955. ScriptVariant_t args[11]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11;
  956. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  957. }
  958. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12>
  959. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12 )
  960. {
  961. ScriptVariant_t args[12]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12;
  962. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  963. }
  964. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12, typename ARG_TYPE_13>
  965. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12, ARG_TYPE_13 arg13 )
  966. {
  967. ScriptVariant_t args[13]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12; args[12] = arg13;
  968. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  969. }
  970. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12, typename ARG_TYPE_13, typename ARG_TYPE_14>
  971. ScriptStatus_t Call( HSCRIPT hFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12, ARG_TYPE_13 arg13, ARG_TYPE_14 arg14 )
  972. {
  973. ScriptVariant_t args[14]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12; args[12] = arg13; args[13] = arg14;
  974. return GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  975. }
  976. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn = NULL )
  977. {
  978. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  979. if ( !hFunction )
  980. return SCRIPT_ERROR;
  981. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, NULL, 0, pReturn, m_hScope, true );
  982. GetVM()->ReleaseFunction( hFunction );
  983. return status;
  984. }
  985. template <typename ARG_TYPE_1>
  986. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1 )
  987. {
  988. ScriptVariant_t args[1]; args[0] = arg1;
  989. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  990. if ( !hFunction )
  991. return SCRIPT_ERROR;
  992. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  993. GetVM()->ReleaseFunction( hFunction );
  994. return status;
  995. }
  996. template <typename ARG_TYPE_1, typename ARG_TYPE_2>
  997. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2 )
  998. {
  999. ScriptVariant_t args[2]; args[0] = arg1; args[1] = arg2;
  1000. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1001. if ( !hFunction )
  1002. return SCRIPT_ERROR;
  1003. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1004. GetVM()->ReleaseFunction( hFunction );
  1005. return status;
  1006. }
  1007. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3>
  1008. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3 )
  1009. {
  1010. ScriptVariant_t args[3]; args[0] = arg1; args[1] = arg2; args[2] = arg3;
  1011. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1012. if ( !hFunction )
  1013. return SCRIPT_ERROR;
  1014. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1015. GetVM()->ReleaseFunction( hFunction );
  1016. return status;
  1017. }
  1018. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4>
  1019. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4 )
  1020. {
  1021. ScriptVariant_t args[4]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4;
  1022. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1023. if ( !hFunction )
  1024. return SCRIPT_ERROR;
  1025. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1026. GetVM()->ReleaseFunction( hFunction );
  1027. return status;
  1028. }
  1029. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5>
  1030. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5 )
  1031. {
  1032. ScriptVariant_t args[5]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5;
  1033. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1034. if ( !hFunction )
  1035. return SCRIPT_ERROR;
  1036. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1037. GetVM()->ReleaseFunction( hFunction );
  1038. return status;
  1039. }
  1040. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6>
  1041. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6 )
  1042. {
  1043. ScriptVariant_t args[6]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6;
  1044. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1045. if ( !hFunction )
  1046. return SCRIPT_ERROR;
  1047. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1048. GetVM()->ReleaseFunction( hFunction );
  1049. return status;
  1050. }
  1051. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7>
  1052. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7 )
  1053. {
  1054. ScriptVariant_t args[7]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7;
  1055. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1056. if ( !hFunction )
  1057. return SCRIPT_ERROR;
  1058. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1059. GetVM()->ReleaseFunction( hFunction );
  1060. return status;
  1061. }
  1062. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8>
  1063. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8 )
  1064. {
  1065. ScriptVariant_t args[8]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8;
  1066. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1067. if ( !hFunction )
  1068. return SCRIPT_ERROR;
  1069. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1070. GetVM()->ReleaseFunction( hFunction );
  1071. return status;
  1072. }
  1073. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9>
  1074. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9 )
  1075. {
  1076. ScriptVariant_t args[9]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9;
  1077. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1078. if ( !hFunction )
  1079. return SCRIPT_ERROR;
  1080. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1081. GetVM()->ReleaseFunction( hFunction );
  1082. return status;
  1083. }
  1084. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10>
  1085. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10 )
  1086. {
  1087. ScriptVariant_t args[10]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10;
  1088. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1089. if ( !hFunction )
  1090. return SCRIPT_ERROR;
  1091. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1092. GetVM()->ReleaseFunction( hFunction );
  1093. return status;
  1094. }
  1095. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11>
  1096. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11 )
  1097. {
  1098. ScriptVariant_t args[11]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11;
  1099. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1100. if ( !hFunction )
  1101. return SCRIPT_ERROR;
  1102. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1103. GetVM()->ReleaseFunction( hFunction );
  1104. return status;
  1105. }
  1106. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12>
  1107. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12 )
  1108. {
  1109. ScriptVariant_t args[12]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12;
  1110. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1111. if ( !hFunction )
  1112. return SCRIPT_ERROR;
  1113. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1114. GetVM()->ReleaseFunction( hFunction );
  1115. return status;
  1116. }
  1117. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12, typename ARG_TYPE_13>
  1118. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12, ARG_TYPE_13 arg13 )
  1119. {
  1120. ScriptVariant_t args[13]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12; args[12] = arg13;
  1121. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1122. if ( !hFunction )
  1123. return SCRIPT_ERROR;
  1124. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1125. GetVM()->ReleaseFunction( hFunction );
  1126. return status;
  1127. }
  1128. template <typename ARG_TYPE_1, typename ARG_TYPE_2, typename ARG_TYPE_3, typename ARG_TYPE_4, typename ARG_TYPE_5, typename ARG_TYPE_6, typename ARG_TYPE_7, typename ARG_TYPE_8, typename ARG_TYPE_9, typename ARG_TYPE_10, typename ARG_TYPE_11, typename ARG_TYPE_12, typename ARG_TYPE_13, typename ARG_TYPE_14>
  1129. ScriptStatus_t Call( const char *pszFunction, ScriptVariant_t *pReturn, ARG_TYPE_1 arg1, ARG_TYPE_2 arg2, ARG_TYPE_3 arg3, ARG_TYPE_4 arg4, ARG_TYPE_5 arg5, ARG_TYPE_6 arg6, ARG_TYPE_7 arg7, ARG_TYPE_8 arg8, ARG_TYPE_9 arg9, ARG_TYPE_10 arg10, ARG_TYPE_11 arg11, ARG_TYPE_12 arg12, ARG_TYPE_13 arg13, ARG_TYPE_14 arg14 )
  1130. {
  1131. ScriptVariant_t args[14]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; args[6] = arg7; args[7] = arg8; args[8] = arg9; args[9] = arg10; args[10] = arg11; args[11] = arg12; args[12] = arg13; args[13] = arg14;
  1132. HSCRIPT hFunction = GetVM()->LookupFunction( pszFunction, m_hScope );
  1133. if ( !hFunction )
  1134. return SCRIPT_ERROR;
  1135. ScriptStatus_t status = GetVM()->ExecuteFunction( hFunction, args, ARRAYSIZE(args), pReturn, m_hScope, true );
  1136. GetVM()->ReleaseFunction( hFunction );
  1137. return status;
  1138. }
  1139. protected:
  1140. HSCRIPT m_hScope;
  1141. int m_flags;
  1142. CUtlVectorConservative<HSCRIPT *> m_FuncHandles;
  1143. };
  1144. typedef CScriptScopeT<> CScriptScope;
  1145. #define VScriptAddEnumToScope_( scope, enumVal, scriptName ) (scope).SetValue( scriptName, (int)enumVal )
  1146. #define VScriptAddEnumToScope( scope, enumVal ) VScriptAddEnumToScope_( scope, enumVal, #enumVal )
  1147. #define VScriptAddEnumToRoot( enumVal ) g_pScriptVM->SetValue( #enumVal, (int)enumVal )
  1148. //-----------------------------------------------------------------------------
  1149. // Script function proxy support
  1150. //-----------------------------------------------------------------------------
  1151. class CScriptFuncHolder
  1152. {
  1153. public:
  1154. CScriptFuncHolder() : hFunction( INVALID_HSCRIPT ) {}
  1155. bool IsValid() { return ( hFunction != INVALID_HSCRIPT ); }
  1156. bool IsNull() { return ( !hFunction ); }
  1157. HSCRIPT hFunction;
  1158. };
  1159. #define DEFINE_SCRIPT_PROXY_GUTS( FuncName, N ) \
  1160. CScriptFuncHolder m_hScriptFunc_##FuncName; \
  1161. template < typename RET_TYPE FUNC_TEMPLATE_ARG_PARAMS_##N> \
  1162. bool FuncName( RET_TYPE *pRetVal FUNC_ARG_FORMAL_PARAMS_##N ) \
  1163. { \
  1164. if ( !m_hScriptFunc_##FuncName.IsValid() ) \
  1165. { \
  1166. m_hScriptFunc_##FuncName.hFunction = LookupFunction( #FuncName ); \
  1167. m_FuncHandles.AddToTail( &m_hScriptFunc_##FuncName.hFunction ); \
  1168. } \
  1169. \
  1170. if ( !m_hScriptFunc_##FuncName.IsNull() ) \
  1171. { \
  1172. ScriptVariant_t returnVal; \
  1173. ScriptStatus_t result = Call( m_hScriptFunc_##FuncName.hFunction, &returnVal, FUNC_CALL_ARGS_##N ); \
  1174. if ( result != SCRIPT_ERROR ) \
  1175. { \
  1176. returnVal.AssignTo( pRetVal ); \
  1177. returnVal.Free(); \
  1178. return true; \
  1179. } \
  1180. } \
  1181. return false; \
  1182. }
  1183. #define DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, N ) \
  1184. CScriptFuncHolder m_hScriptFunc_##FuncName; \
  1185. template < FUNC_SOLO_TEMPLATE_ARG_PARAMS_##N> \
  1186. bool FuncName( FUNC_PROXY_ARG_FORMAL_PARAMS_##N ) \
  1187. { \
  1188. if ( !m_hScriptFunc_##FuncName.IsValid() ) \
  1189. { \
  1190. m_hScriptFunc_##FuncName.hFunction = LookupFunction( #FuncName ); \
  1191. m_FuncHandles.AddToTail( &m_hScriptFunc_##FuncName.hFunction ); \
  1192. } \
  1193. \
  1194. if ( !m_hScriptFunc_##FuncName.IsNull() ) \
  1195. { \
  1196. ScriptStatus_t result = Call( m_hScriptFunc_##FuncName.hFunction, NULL, FUNC_CALL_ARGS_##N ); \
  1197. if ( result != SCRIPT_ERROR ) \
  1198. { \
  1199. return true; \
  1200. } \
  1201. } \
  1202. return false; \
  1203. }
  1204. #define DEFINE_SCRIPT_PROXY_0V( FuncName ) \
  1205. CScriptFuncHolder m_hScriptFunc_##FuncName; \
  1206. bool FuncName() \
  1207. { \
  1208. if ( !m_hScriptFunc_##FuncName.IsValid() ) \
  1209. { \
  1210. m_hScriptFunc_##FuncName.hFunction = LookupFunction( #FuncName ); \
  1211. m_FuncHandles.AddToTail( &m_hScriptFunc_##FuncName.hFunction ); \
  1212. } \
  1213. \
  1214. if ( !m_hScriptFunc_##FuncName.IsNull() ) \
  1215. { \
  1216. ScriptStatus_t result = Call( m_hScriptFunc_##FuncName.hFunction, NULL ); \
  1217. if ( result != SCRIPT_ERROR ) \
  1218. { \
  1219. return true; \
  1220. } \
  1221. } \
  1222. return false; \
  1223. }
  1224. #define DEFINE_SCRIPT_PROXY_0( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 0 )
  1225. #define DEFINE_SCRIPT_PROXY_1( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 1 )
  1226. #define DEFINE_SCRIPT_PROXY_2( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 2 )
  1227. #define DEFINE_SCRIPT_PROXY_3( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 3 )
  1228. #define DEFINE_SCRIPT_PROXY_4( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 4 )
  1229. #define DEFINE_SCRIPT_PROXY_5( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 5 )
  1230. #define DEFINE_SCRIPT_PROXY_6( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 6 )
  1231. #define DEFINE_SCRIPT_PROXY_7( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 7 )
  1232. #define DEFINE_SCRIPT_PROXY_8( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 8 )
  1233. #define DEFINE_SCRIPT_PROXY_9( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 9 )
  1234. #define DEFINE_SCRIPT_PROXY_10( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 10 )
  1235. #define DEFINE_SCRIPT_PROXY_11( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 11 )
  1236. #define DEFINE_SCRIPT_PROXY_12( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 12 )
  1237. #define DEFINE_SCRIPT_PROXY_13( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 13 )
  1238. #define DEFINE_SCRIPT_PROXY_14( FuncName ) DEFINE_SCRIPT_PROXY_GUTS( FuncName, 14 )
  1239. #define DEFINE_SCRIPT_PROXY_1V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 1 )
  1240. #define DEFINE_SCRIPT_PROXY_2V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 2 )
  1241. #define DEFINE_SCRIPT_PROXY_3V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 3 )
  1242. #define DEFINE_SCRIPT_PROXY_4V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 4 )
  1243. #define DEFINE_SCRIPT_PROXY_5V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 5 )
  1244. #define DEFINE_SCRIPT_PROXY_6V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 6 )
  1245. #define DEFINE_SCRIPT_PROXY_7V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 7 )
  1246. #define DEFINE_SCRIPT_PROXY_8V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 8 )
  1247. #define DEFINE_SCRIPT_PROXY_9V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 9 )
  1248. #define DEFINE_SCRIPT_PROXY_10V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 10 )
  1249. #define DEFINE_SCRIPT_PROXY_11V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 11 )
  1250. #define DEFINE_SCRIPT_PROXY_12V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 12 )
  1251. #define DEFINE_SCRIPT_PROXY_13V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 13 )
  1252. #define DEFINE_SCRIPT_PROXY_14V( FuncName ) DEFINE_SCRIPT_PROXY_GUTS_NO_RETVAL( FuncName, 14 )
  1253. //-----------------------------------------------------------------------------
  1254. #include "tier0/memdbgoff.h"
  1255. #endif // IVSCRIPT_H