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

//========== Copyright © 2008, Valve Corporation, All rights reserved. ========
//
// Purpose:
//
//=============================================================================
#include "interface.h"
#include "vscript/ivscript.h"
#include "languages/gm/vgm/vgm.h"
#include "languages/squirrel/vsquirrel/vsquirrel.h"
#include "languages/lua/vlua/vlua.h"
#include "languages/python/vpython/vpython.h"
#include "vstdlib/random.h"
#include "tier1/tier1.h"
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
class CScriptManager : public CTier1AppSystem<IScriptManager>
{
public:
CScriptManager()
{
}
IScriptVM *CreateVM( ScriptLanguage_t language )
{
IScriptVM *pVM = NULL;
if ( language == SL_SQUIRREL )
{
pVM = ScriptCreateSquirrelVM();
}
#if !defined( _GAMECONSOLE ) && !defined( LINUX )
else if ( language == SL_LUA )
{
pVM = ScriptCreateLuaVM();
}
#endif
#if VPYTHON_ENABLED
else if ( language == SL_PYTHON )
{
pVM = ScriptCreatePythonVM();
}
#endif
#if VGM_ENABLED
else if ( language == SL_GAMEMONKEY )
{
pVM = ScriptCreateGameMonkeyVM();
}
#endif
AssertMsg( pVM, "Unknown script language\n" );
if ( pVM )
{
pVM->Init();
ScriptRegisterFunction( pVM, RandomFloat, "Generate a random floating point number within a range, inclusive" );
ScriptRegisterFunction( pVM, RandomInt, "Generate a random integer within a range, inclusive" );
}
return pVM;
}
void DestroyVM( IScriptVM *p )
{
if ( p )
{
p->Shutdown();
if ( p->GetLanguage() == SL_SQUIRREL )
{
ScriptDestroySquirrelVM( p );
}
#if !defined( _GAMECONSOLE ) && !defined( LINUX )
else if ( p->GetLanguage() == SL_LUA )
{
ScriptDestroyLuaVM( p );
}
#endif
#if VPYTHON_ENABLED
else if ( p->GetLanguage() == SL_PYTHON )
{
ScriptDestroyPythonVM( p );
}
#endif
#if VGM_ENABLED
else if ( p->GetLanguage() == SL_GAMEMONKEY )
{
ScriptDestroyGameMonkeyVM( p );
}
#endif
else
AssertMsg( 0, "Unknown script language\n" );
}
}
};
//-----------------------------------------------------------------------------
// Singleton
//-----------------------------------------------------------------------------
CScriptManager g_ScriptManager;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CScriptManager, IScriptManager, VSCRIPT_INTERFACE_VERSION, g_ScriptManager );