Exemple #1
0
int qasCreateScriptEngine( qboolean *as_max_portability )
{
    enginehandle_t *eh;
    asIScriptEngine *engine;

    // register the global memory allocation and deallocation functions
    asSetGlobalMemoryFunctions( qasAlloc, qasFree );

    // always new

    // ask for angelscript initialization and script engine creation
    engine = asCreateScriptEngine( ANGELSCRIPT_VERSION );
    if( !engine )
        return -1;

    eh = ( enginehandle_t * )QAS_Malloc( sizeof( enginehandle_t ) );
    eh->handle = numRegisteredEngines++;
    eh->next = engineHandlesHead;
    engineHandlesHead = eh;

    eh->engine = engine;
    eh->max_portability = qfalse;

    if( strstr( asGetLibraryOptions(), "AS_MAX_PORTABILITY" ) )
    {
        QAS_Printf( "* angelscript library with AS_MAX_PORTABILITY detected\n" );
        eh->max_portability = qtrue;
    }

    if( as_max_portability )
        *as_max_portability = eh->max_portability;

    // The script compiler will write any compiler messages to the callback.
    eh->engine->SetMessageCallback( asFUNCTION( qasGenericMessageCallback ), 0, asCALL_CDECL );

    PreRegisterMathAddon( engine );
    PreRegisterScriptArrayAddon( engine, true );
    PreRegisterStringAddon( engine );
    PreRegisterDictionaryAddon( engine );
    PreRegisterTimeAddon( engine );
    PreRegisterScriptAny( engine );
    PreRegisterVec3Addon( engine );
    PreRegisterCvarAddon( engine );
    PreRegisterStringUtilsAddon( engine );

    RegisterMathAddon( engine );
    RegisterScriptArrayAddon( engine, true );
    RegisterStringAddon( engine );
    RegisterDictionaryAddon( engine );
    RegisterTimeAddon( engine );
    RegisterScriptAny( engine );
    RegisterVec3Addon( engine );
    RegisterCvarAddon( engine );
    RegisterStringUtilsAddon( engine );

    return eh->handle;
}
Exemple #2
0
asIScriptEngine *qasCreateEngine( bool *asMaxPortability )
{
	asIScriptEngine *engine;

	// register the global memory allocation and deallocation functions
	asSetGlobalMemoryFunctions( qasAlloc, qasFree );

	// always new

	// ask for angelscript initialization and script engine creation
	engine = asCreateScriptEngine( ANGELSCRIPT_VERSION );
	if( !engine )
		return NULL;

	if( strstr( asGetLibraryOptions(), "AS_MAX_PORTABILITY" ) )
	{
		QAS_Printf( "* angelscript library with AS_MAX_PORTABILITY detected\n" );
		engine->Release();
		return NULL;
	}

	*asMaxPortability = false;

	// The script compiler will write any compiler messages to the callback.
	engine->SetMessageCallback( asFUNCTION( qasMessageCallback ), 0, asCALL_CDECL );
	engine->SetEngineProperty( asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT, 1 );

	PreRegisterMathAddon( engine );
	PreRegisterScriptArray( engine, true );
	PreRegisterStringAddon( engine );
	PreRegisterScriptDictionary( engine );
	PreRegisterTimeAddon( engine );
	PreRegisterScriptAny( engine );
	PreRegisterVec3Addon( engine );
	PreRegisterCvarAddon( engine );
	PreRegisterStringUtilsAddon( engine );

	RegisterMathAddon( engine );
	RegisterScriptArray( engine, true );
	RegisterStringAddon( engine );
	RegisterScriptDictionary( engine );
	RegisterTimeAddon( engine );
	RegisterScriptAny( engine );
	RegisterVec3Addon( engine );
	RegisterCvarAddon( engine );
	RegisterStringUtilsAddon( engine );

	return engine;
}