diff --git a/sp/src/public/vscript/ivscript.h b/sp/src/public/vscript/ivscript.h index 58f981e0..88f4771a 100644 --- a/sp/src/public/vscript/ivscript.h +++ b/sp/src/public/vscript/ivscript.h @@ -396,6 +396,9 @@ struct ScriptVariant_t #ifdef MAPBASE_VSCRIPT ScriptVariant_t( const QAngle &val, bool bCopy = false ) : m_flags( 0 ), m_type( FIELD_VECTOR ) { if ( !bCopy ) { m_pAngle = &val; } else { m_pAngle = new QAngle( val ); m_flags |= SV_FREE; } } ScriptVariant_t( const QAngle *val, bool bCopy = false ) : m_flags( 0 ), m_type( FIELD_VECTOR ) { if ( !bCopy ) { m_pAngle = val; } else { m_pAngle = new QAngle( *val ); m_flags |= SV_FREE; } } + + ScriptVariant_t( Vector &&val ) : ScriptVariant_t( val, true ) { } + ScriptVariant_t( QAngle &&val ) : ScriptVariant_t( val, true ) { } #endif bool IsNull() const { return (m_type == FIELD_VOID ); } @@ -423,6 +426,9 @@ struct ScriptVariant_t #ifdef MAPBASE_VSCRIPT void operator=( const QAngle &vec ) { m_type = FIELD_VECTOR; m_pAngle = &vec; } void operator=( const QAngle *vec ) { m_type = FIELD_VECTOR; m_pAngle = vec; } + + void operator=( Vector &&vec ) { m_type = FIELD_VECTOR; m_pVector = new Vector( vec ); m_flags |= SV_FREE; } + void operator=( QAngle &&vec ) { m_type = FIELD_VECTOR; m_pAngle = new QAngle( vec ); m_flags |= SV_FREE; } #endif 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 diff --git a/sp/src/public/vscript/vscript_templates.h b/sp/src/public/vscript/vscript_templates.h index 2d7058a3..af020fe6 100644 --- a/sp/src/public/vscript/vscript_templates.h +++ b/sp/src/public/vscript/vscript_templates.h @@ -337,8 +337,6 @@ inline FUNCPTR_TYPE ScriptConvertFuncPtrFromVoid( void *p ) return false; \ } \ *pReturn = ((FUNC_TYPE)pFunction)( SCRIPT_BINDING_ARGS_##N ); \ - if ( pReturn->m_type == FIELD_VECTOR ) \ - pReturn->m_pVector = new Vector(*pReturn->m_pVector); \ return true; \ } \ }; \ @@ -377,8 +375,6 @@ inline FUNCPTR_TYPE ScriptConvertFuncPtrFromVoid( void *p ) return false; \ } \ *pReturn = (((OBJECT_TYPE_PTR)(pContext))->*ScriptConvertFuncPtrFromVoid(pFunction))( SCRIPT_BINDING_ARGS_##N ); \ - if ( pReturn->m_type == FIELD_VECTOR ) \ - pReturn->m_pVector = new Vector(*pReturn->m_pVector); \ return true; \ } \ }; \ diff --git a/sp/src/vscript/vscript_squirrel.cpp b/sp/src/vscript/vscript_squirrel.cpp index 5efb2314..aff21075 100644 --- a/sp/src/vscript/vscript_squirrel.cpp +++ b/sp/src/vscript/vscript_squirrel.cpp @@ -1415,8 +1415,7 @@ SQInteger function_stub(HSQUIRRELVM vm) PushVariant(vm, retval); - if (retval.m_type == FIELD_VECTOR) - delete retval.m_pVector; + retval.Free(); return pFunc->m_desc.m_ReturnType != FIELD_VOID; }