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.

104 lines
2.4 KiB

  1. //========== Copyright � 2008, Valve Corporation, All rights reserved. ========
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "interface.h"
  7. #include "vscript/ivscript.h"
  8. #include "languages/gm/vgm/vgm.h"
  9. #include "languages/squirrel/vsquirrel/vsquirrel.h"
  10. #include "languages/lua/vlua/vlua.h"
  11. #include "languages/python/vpython/vpython.h"
  12. #include "vstdlib/random.h"
  13. #include "tier1/tier1.h"
  14. //-----------------------------------------------------------------------------
  15. //
  16. //-----------------------------------------------------------------------------
  17. class CScriptManager : public CTier1AppSystem<IScriptManager>
  18. {
  19. public:
  20. CScriptManager()
  21. {
  22. }
  23. IScriptVM *CreateVM( ScriptLanguage_t language )
  24. {
  25. IScriptVM *pVM = NULL;
  26. if ( language == SL_SQUIRREL )
  27. {
  28. pVM = ScriptCreateSquirrelVM();
  29. }
  30. #if !defined( _GAMECONSOLE ) && !defined( LINUX )
  31. else if ( language == SL_LUA )
  32. {
  33. pVM = ScriptCreateLuaVM();
  34. }
  35. #endif
  36. #if VPYTHON_ENABLED
  37. else if ( language == SL_PYTHON )
  38. {
  39. pVM = ScriptCreatePythonVM();
  40. }
  41. #endif
  42. #if VGM_ENABLED
  43. else if ( language == SL_GAMEMONKEY )
  44. {
  45. pVM = ScriptCreateGameMonkeyVM();
  46. }
  47. #endif
  48. AssertMsg( pVM, "Unknown script language\n" );
  49. if ( pVM )
  50. {
  51. pVM->Init();
  52. ScriptRegisterFunction( pVM, RandomFloat, "Generate a random floating point number within a range, inclusive" );
  53. ScriptRegisterFunction( pVM, RandomInt, "Generate a random integer within a range, inclusive" );
  54. }
  55. return pVM;
  56. }
  57. void DestroyVM( IScriptVM *p )
  58. {
  59. if ( p )
  60. {
  61. p->Shutdown();
  62. if ( p->GetLanguage() == SL_SQUIRREL )
  63. {
  64. ScriptDestroySquirrelVM( p );
  65. }
  66. #if !defined( _GAMECONSOLE ) && !defined( LINUX )
  67. else if ( p->GetLanguage() == SL_LUA )
  68. {
  69. ScriptDestroyLuaVM( p );
  70. }
  71. #endif
  72. #if VPYTHON_ENABLED
  73. else if ( p->GetLanguage() == SL_PYTHON )
  74. {
  75. ScriptDestroyPythonVM( p );
  76. }
  77. #endif
  78. #if VGM_ENABLED
  79. else if ( p->GetLanguage() == SL_GAMEMONKEY )
  80. {
  81. ScriptDestroyGameMonkeyVM( p );
  82. }
  83. #endif
  84. else
  85. AssertMsg( 0, "Unknown script language\n" );
  86. }
  87. }
  88. };
  89. //-----------------------------------------------------------------------------
  90. // Singleton
  91. //-----------------------------------------------------------------------------
  92. CScriptManager g_ScriptManager;
  93. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CScriptManager, IScriptManager, VSCRIPT_INTERFACE_VERSION, g_ScriptManager );