Ejemplo n.º 1
0
static inline asstring_t *objectString_Alloc( void )
{
	static asstring_t *object;

	object = (asstring_t *)QAS_Malloc( sizeof( asstring_t ) );
	object->asRefCount = 1;
	return object;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
asstring_t *objectString_FactoryBuffer( const char *buffer, unsigned int length )
{
	asstring_t *object;

	object = objectString_Alloc();
	object->buffer = (char *)QAS_Malloc( sizeof( char ) * ( length + 1 ) );
	object->len = length;
	object->buffer[length] = 0;
	object->size = length + 1;
	if( buffer )
		Q_strncpyz( object->buffer, buffer, object->size );

	return object;
}
Ejemplo n.º 4
0
asstring_t *objectString_AssignString( asstring_t *self, const char *string, size_t strlen )
{
	if( strlen >= self->size )
	{
		QAS_Free( self->buffer );

		self->size = strlen + 1;
		self->buffer = (char *)QAS_Malloc( self->size );
	}

	self->len = strlen;
	Q_strncpyz( self->buffer, string, self->size );

	return self;
}
Ejemplo n.º 5
0
static asstring_t *objectString_AddAssignString( asstring_t *self, const char *string, size_t strlen )
{
	if( strlen )
	{
		char *tem = self->buffer;

		self->len = strlen + self->len;
		self->size = self->len + 1;
		self->buffer = (char *)QAS_Malloc( self->size );

		Q_snprintfz( self->buffer, self->size, "%s%s", tem, string );
		QAS_Free( tem );
	}

	return self;
}
Ejemplo n.º 6
0
int qasCreateContext( int engineHandle )
{
    asIScriptContext *ctx;
    contexthandle_t *ch;
    enginehandle_t *eh;
    int error;

    eh = qasGetEngineHandle( engineHandle );
    if( !eh )
        return QASINVALIDHANDLE;

    // always new

    ctx = eh->engine->CreateContext();
    if( !ctx )
        return -1;

    ch = ( contexthandle_t * )QAS_Malloc( sizeof( contexthandle_t ) );

    // We don't want to allow the script to hang the application, e.g. with an
    // infinite loop, so we'll use the line callback function to set a timeout
    // that will abort the script after a certain time. Before executing the
    // script the timeOut variable will be set to the time when the script must
    // stop executing.

    error = ctx->SetLineCallback( asFUNCTION(qasGenericLineCallback), &ch->timeOut, asCALL_CDECL );
    if( error < 0 )
    {
        QAS_Free( ch );
        return -1;
    }

    ch->ctx = ctx;
    ch->handle = numRegisteredContexts++;
    ch->owner = eh->handle;
    ch->next = contextHandlesHead;
    contextHandlesHead = ch;

    return ch->handle;
}
Ejemplo n.º 7
0
static void *qasAlloc( size_t size )
{
	return QAS_Malloc( size );
}