diff options
| author | Juan Linietsky | 2017-08-07 18:34:18 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2017-08-07 18:38:47 -0300 |
| commit | c6120e77a8c1c7e946569453973629499673d414 (patch) | |
| tree | 7a43f26d5c61a1f1cc698b277c24836cb1e1cc9c /modules/gdscript/gd_functions.cpp | |
| parent | 0188ce5c80b141d0f8a5880d3253c0b5eeb91e4f (diff) | |
| download | godot-c6120e77a8c1c7e946569453973629499673d414.tar.gz godot-c6120e77a8c1c7e946569453973629499673d414.tar.zst godot-c6120e77a8c1c7e946569453973629499673d414.zip | |
Diffstat (limited to 'modules/gdscript/gd_functions.cpp')
| -rw-r--r-- | modules/gdscript/gd_functions.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 8bc3b24a5..209bdadd6 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -113,6 +113,7 @@ const char *GDFunctions::get_func_name(Function p_func) { "ColorN", "print_stack", "instance_from_id", + "len", }; return _names[p_func]; @@ -1154,6 +1155,62 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, r_ret = ObjectDB::get_instance(id); } break; + case LEN: { + + VALIDATE_ARG_COUNT(1); + switch (p_args[0]->get_type()) { + case Variant::DICTIONARY: { + Dictionary d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::ARRAY: { + Array d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_BYTE_ARRAY: { + PoolVector<uint8_t> d = *p_args[0]; + r_ret = d.size(); + + } break; + case Variant::POOL_INT_ARRAY: { + PoolVector<int> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_REAL_ARRAY: { + + PoolVector<real_t> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_STRING_ARRAY: { + PoolVector<String> d = *p_args[0]; + r_ret = d.size(); + + } break; + case Variant::POOL_VECTOR2_ARRAY: { + PoolVector<Vector2> d = *p_args[0]; + r_ret = d.size(); + + } break; + case Variant::POOL_VECTOR3_ARRAY: { + + PoolVector<Vector3> d = *p_args[0]; + r_ret = d.size(); + } break; + case Variant::POOL_COLOR_ARRAY: { + + PoolVector<Color> d = *p_args[0]; + r_ret = d.size(); + } break; + default: { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + r_ret = Variant(); + r_ret = RTR("Object can't provide a length."); + } + } + + } break; case FUNC_MAX: { ERR_FAIL(); @@ -1210,6 +1267,7 @@ bool GDFunctions::is_deterministic(Function p_func) { case TEXT_CHAR: case TEXT_STR: case COLOR8: + case LEN: // enable for debug only, otherwise not desirable - case GEN_RANGE: return true; default: @@ -1621,6 +1679,11 @@ MethodInfo GDFunctions::get_info(Function p_func) { mi.return_val.type = Variant::OBJECT; return mi; } break; + case LEN: { + MethodInfo mi("len", PropertyInfo(Variant::NIL, "var")); + mi.return_val.type = Variant::INT; + return mi; + } break; case FUNC_MAX: { |
