From 1a7aae7443194f7d6137901af369c843b3911b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20Cosmin=20R=C4=83dulescu?= Date: Sat, 27 Aug 2016 17:33:45 +0200 Subject: [PATCH] (Array) pop_front, pop_back return values pop_front, pop_back now return values instead of `void`. Things I didn't know how to properly implement: 1. pop_front & pop_back shows in the help menu Object as return value. I know this is incorrect but if not Object than what? Cause it can't be void. It needs to be a generic type that includes all the Array types --- core/array.cpp | 20 +++++++++++++++----- core/array.h | 4 ++-- core/variant_call.cpp | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/array.cpp b/core/array.cpp index 23792f90fc4..683a43e3d02 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -276,16 +276,26 @@ void Array::push_front(const Variant& p_value) { _p->array.insert(0,p_value); } -void Array::pop_back(){ +Variant Array::pop_back(){ - if (!_p->array.empty()) - _p->array.resize( _p->array.size() -1 ); + if (!_p->array.empty()) { + int n = _p->array.size() - 1; + Variant ret = _p->array.get(n); + _p->array.resize(n); + return ret; + } + return Variant(); } -void Array::pop_front(){ - if (!_p->array.empty()) +Variant Array::pop_front(){ + + if (!_p->array.empty()) { + Variant ret = _p->array.get(0); _p->array.remove(0); + return ret; + } + return Variant(); } diff --git a/core/array.h b/core/array.h index dfc902525c9..eb79b0cf331 100644 --- a/core/array.h +++ b/core/array.h @@ -80,8 +80,8 @@ public: void erase(const Variant& p_value); void push_front(const Variant& p_value); - void pop_back(); - void pop_front(); + Variant pop_back(); + Variant pop_front(); Array(const Array& p_from); Array(bool p_shared=false); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 8473fdcd193..f7bc38ac064 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -464,8 +464,8 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0R(Array,hash); VCALL_LOCALMEM1(Array,push_back); VCALL_LOCALMEM1(Array,push_front); - VCALL_LOCALMEM0(Array,pop_back); - VCALL_LOCALMEM0(Array,pop_front); + VCALL_LOCALMEM0R(Array,pop_back); + VCALL_LOCALMEM0R(Array,pop_front); VCALL_LOCALMEM1(Array,append); VCALL_LOCALMEM1(Array,resize); VCALL_LOCALMEM2(Array,insert);