summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Kowal <pkowal1982@gmail.com>2016-07-02 19:03:35 +0200
committerPawel Kowal <pkowal1982@gmail.com>2016-07-07 11:40:38 +0200
commit96eb97cbbf8acd38a44ecb914e12aeda322d0bd4 (patch)
tree45ec7a3d0001b891d120c186bc5b77c4a1459f9b
parent1b9433594ecc6c935c81e9030a6b52c7b56cb3a4 (diff)
Array has(var value) function
-rw-r--r--core/array.cpp4
-rw-r--r--core/array.h1
-rw-r--r--core/variant_call.cpp2
3 files changed, 7 insertions, 0 deletions
diff --git a/core/array.cpp b/core/array.cpp
index bb8e527304..23792f90fc 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -200,6 +200,10 @@ int Array::count(const Variant& p_value) const {
return amount;
}
+bool Array::has(const Variant& p_value) const {
+ return _p->array.find(p_value, 0) != -1;
+}
+
void Array::remove(int p_pos) {
_p->array.remove(p_pos);
diff --git a/core/array.h b/core/array.h
index 096660653e..dfc902525c 100644
--- a/core/array.h
+++ b/core/array.h
@@ -75,6 +75,7 @@ public:
int rfind(const Variant& p_value, int p_from=-1) const;
int find_last(const Variant& p_value) const;
int count(const Variant& p_value) const;
+ bool has(const Variant& p_value) const;
void erase(const Variant& p_value);
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index a5927bb6f8..a56627970b 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -474,6 +474,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM2R(Array,rfind);
VCALL_LOCALMEM1R(Array,find_last);
VCALL_LOCALMEM1R(Array,count);
+ VCALL_LOCALMEM1R(Array,has);
VCALL_LOCALMEM1(Array,erase);
VCALL_LOCALMEM0(Array,sort);
VCALL_LOCALMEM2(Array,sort_custom);
@@ -1516,6 +1517,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC2(ARRAY,INT,Array,rfind,NIL,"what",INT,"from",varray(-1));
ADDFUNC1(ARRAY,INT,Array,find_last,NIL,"value",varray());
ADDFUNC1(ARRAY,INT,Array,count,NIL,"value",varray());
+ ADDFUNC1(ARRAY,BOOL,Array,has,NIL,"value",varray());
ADDFUNC0(ARRAY,NIL,Array,pop_back,varray());
ADDFUNC0(ARRAY,NIL,Array,pop_front,varray());
ADDFUNC0(ARRAY,NIL,Array,sort,varray());