2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* gd_functions.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 14:16:55 +02:00
/* https://godotengine.org */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
2017-01-01 22:01:57 +01:00
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
2017-04-08 00:11:42 +02:00
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
2014-02-10 02:10:30 +01:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
# include "gd_functions.h"
2017-01-16 08:04:19 +01:00
# include "class_db.h"
2014-03-14 02:57:24 +01:00
# include "func_ref.h"
2017-03-05 16:44:50 +01:00
# include "gd_script.h"
# include "io/json.h"
# include "io/marshalls.h"
# include "math_funcs.h"
2014-02-10 02:10:30 +01:00
# include "os/os.h"
2017-03-05 16:44:50 +01:00
# include "reference.h"
2015-12-31 04:54:00 +01:00
# include "variant_parser.h"
2014-02-10 02:10:30 +01:00
const char * GDFunctions : : get_func_name ( Function p_func ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_func , FUNC_MAX , " " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
static const char * _names [ FUNC_MAX ] = {
2014-02-10 02:10:30 +01:00
" sin " ,
" cos " ,
" tan " ,
" sinh " ,
" cosh " ,
" tanh " ,
" asin " ,
" acos " ,
" atan " ,
" atan2 " ,
" sqrt " ,
" fmod " ,
" fposmod " ,
" floor " ,
" ceil " ,
" round " ,
" abs " ,
" sign " ,
" pow " ,
" log " ,
" exp " ,
" is_nan " ,
" is_inf " ,
" ease " ,
" decimals " ,
" stepify " ,
" lerp " ,
2017-08-10 16:06:10 +02:00
" inverse_lerp " ,
" range_lerp " ,
2014-02-10 02:10:30 +01:00
" dectime " ,
" randomize " ,
" randi " ,
" randf " ,
" rand_range " ,
2015-03-25 04:01:12 +01:00
" seed " ,
2014-02-10 02:10:30 +01:00
" rand_seed " ,
" deg2rad " ,
" rad2deg " ,
" linear2db " ,
" db2linear " ,
" max " ,
" min " ,
" clamp " ,
" nearest_po2 " ,
" weakref " ,
2014-03-14 02:57:24 +01:00
" funcref " ,
2014-02-10 02:10:30 +01:00
" convert " ,
" typeof " ,
2016-06-18 09:07:51 +02:00
" type_exists " ,
2016-10-03 18:17:54 +02:00
" char " ,
2014-02-10 02:10:30 +01:00
" str " ,
" print " ,
" printt " ,
2015-05-09 23:09:58 +02:00
" prints " ,
2014-02-10 02:10:30 +01:00
" printerr " ,
" printraw " ,
2015-02-15 05:19:46 +01:00
" var2str " ,
" str2var " ,
2016-01-03 01:07:03 +01:00
" var2bytes " ,
" bytes2var " ,
2014-02-10 02:10:30 +01:00
" range " ,
2014-02-16 01:16:33 +01:00
" load " ,
2014-02-10 02:10:30 +01:00
" inst2dict " ,
" dict2inst " ,
2017-01-09 02:40:00 +01:00
" validate_json " ,
" parse_json " ,
" to_json " ,
2014-06-16 15:22:26 +02:00
" hash " ,
2015-12-31 22:32:56 +01:00
" Color8 " ,
2016-11-10 22:06:00 +01:00
" ColorN " ,
2014-02-10 02:10:30 +01:00
" print_stack " ,
2015-04-18 19:00:15 +02:00
" instance_from_id " ,
2017-08-07 23:34:18 +02:00
" len " ,
2014-02-10 02:10:30 +01:00
} ;
return _names [ p_func ] ;
}
2017-03-05 16:44:50 +01:00
void GDFunctions : : call ( Function p_func , const Variant * * p_args , int p_arg_count , Variant & r_ret , Variant : : CallError & r_error ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_OK ;
2014-02-10 02:10:30 +01:00
# ifdef DEBUG_ENABLED
2017-03-05 16:44:50 +01:00
# define VALIDATE_ARG_COUNT(m_count) \
if ( p_arg_count < m_count ) { \
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ; \
r_error . argument = m_count ; \
r_ret = Variant ( ) ; \
return ; \
} \
if ( p_arg_count > m_count ) { \
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ; \
r_error . argument = m_count ; \
r_ret = Variant ( ) ; \
return ; \
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
# define VALIDATE_ARG_NUM(m_arg) \
if ( ! p_args [ m_arg ] - > is_num ( ) ) { \
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ; \
r_error . argument = m_arg ; \
r_error . expected = Variant : : REAL ; \
r_ret = Variant ( ) ; \
return ; \
2014-02-10 02:10:30 +01:00
}
# else
# define VALIDATE_ARG_COUNT(m_count)
# define VALIDATE_ARG_NUM(m_arg)
# endif
//using a switch, so the compiler generates a jumptable
2017-03-05 16:44:50 +01:00
switch ( p_func ) {
2014-02-10 02:10:30 +01:00
case MATH_SIN : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : sin ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_COS : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : cos ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_TAN : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : tan ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_SINH : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : sinh ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_COSH : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : cosh ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_TANH : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : tanh ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ASIN : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : asin ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ACOS : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : acos ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ATAN : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : atan ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ATAN2 : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : atan2 ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_SQRT : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : sqrt ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_FMOD : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : fmod ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_FPOSMOD : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : fposmod ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_FLOOR : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : floor ( ( double ) * p_args [ 0 ] ) ;
} break ;
2014-02-10 02:10:30 +01:00
case MATH_CEIL : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : ceil ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ROUND : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : round ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ABS : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) = = Variant : : INT ) {
2014-02-10 02:10:30 +01:00
int64_t i = * p_args [ 0 ] ;
2017-03-05 16:44:50 +01:00
r_ret = ABS ( i ) ;
} else if ( p_args [ 0 ] - > get_type ( ) = = Variant : : REAL ) {
2014-02-10 02:10:30 +01:00
2017-01-14 21:35:39 +01:00
double r = * p_args [ 0 ] ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : abs ( r ) ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : REAL ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
case MATH_SIGN : {
2017-03-05 16:44:50 +01:00
VALIDATE_ARG_COUNT ( 1 ) ;
if ( p_args [ 0 ] - > get_type ( ) = = Variant : : INT ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
int64_t i = * p_args [ 0 ] ;
r_ret = i < 0 ? - 1 : ( i > 0 ? + 1 : 0 ) ;
} else if ( p_args [ 0 ] - > get_type ( ) = = Variant : : REAL ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
real_t r = * p_args [ 0 ] ;
r_ret = r < 0.0 ? - 1.0 : ( r > 0.0 ? + 1.0 : 0.0 ) ;
} else {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : REAL ;
r_ret = Variant ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
case MATH_POW : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : pow ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_LOG : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : log ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_EXP : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : exp ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ISNAN : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : is_nan ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_ISINF : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : is_inf ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_EASE : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : ease ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_DECIMALS : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : step_decimals ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_STEPIFY : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : stepify ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_LERP : {
VALIDATE_ARG_COUNT ( 3 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
VALIDATE_ARG_NUM ( 2 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : lerp ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] , ( double ) * p_args [ 2 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
2017-08-10 16:06:10 +02:00
case MATH_INVERSE_LERP : {
VALIDATE_ARG_COUNT ( 3 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
VALIDATE_ARG_NUM ( 2 ) ;
r_ret = Math : : inverse_lerp ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] , ( double ) * p_args [ 2 ] ) ;
} break ;
case MATH_RANGE_LERP : {
VALIDATE_ARG_COUNT ( 5 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
VALIDATE_ARG_NUM ( 2 ) ;
VALIDATE_ARG_NUM ( 3 ) ;
VALIDATE_ARG_NUM ( 4 ) ;
r_ret = Math : : range_lerp ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] , ( double ) * p_args [ 2 ] , ( double ) * p_args [ 3 ] , ( double ) * p_args [ 4 ] ) ;
} break ;
2014-02-10 02:10:30 +01:00
case MATH_DECTIME : {
VALIDATE_ARG_COUNT ( 3 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
VALIDATE_ARG_NUM ( 2 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : dectime ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] , ( double ) * p_args [ 2 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_RANDOMIZE : {
Math : : randomize ( ) ;
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_RAND : {
2017-03-05 16:44:50 +01:00
r_ret = Math : : rand ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_RANDF : {
2017-03-05 16:44:50 +01:00
r_ret = Math : : randf ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_RANDOM : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : random ( ( double ) * p_args [ 0 ] , ( double ) * p_args [ 1 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
2015-03-25 04:01:12 +01:00
case MATH_SEED : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
uint64_t seed = * p_args [ 0 ] ;
2015-03-25 04:01:12 +01:00
Math : : seed ( seed ) ;
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2015-03-25 04:01:12 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case MATH_RANDSEED : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
uint64_t seed = * p_args [ 0 ] ;
2014-02-10 02:10:30 +01:00
int ret = Math : : rand_from_seed ( & seed ) ;
Array reta ;
reta . push_back ( ret ) ;
reta . push_back ( seed ) ;
2017-03-05 16:44:50 +01:00
r_ret = reta ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_DEG2RAD : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : deg2rad ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_RAD2DEG : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : rad2deg ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_LINEAR2DB : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : linear2db ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case MATH_DB2LINEAR : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
r_ret = Math : : db2linear ( ( double ) * p_args [ 0 ] ) ;
2014-02-10 02:10:30 +01:00
} break ;
case LOGIC_MAX : {
VALIDATE_ARG_COUNT ( 2 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) = = Variant : : INT & & p_args [ 1 ] - > get_type ( ) = = Variant : : INT ) {
2014-02-10 02:10:30 +01:00
int64_t a = * p_args [ 0 ] ;
int64_t b = * p_args [ 1 ] ;
2017-03-05 16:44:50 +01:00
r_ret = MAX ( a , b ) ;
2014-02-10 02:10:30 +01:00
} else {
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
real_t a = * p_args [ 0 ] ;
real_t b = * p_args [ 1 ] ;
2017-03-05 16:44:50 +01:00
r_ret = MAX ( a , b ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
case LOGIC_MIN : {
VALIDATE_ARG_COUNT ( 2 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) = = Variant : : INT & & p_args [ 1 ] - > get_type ( ) = = Variant : : INT ) {
2014-02-10 02:10:30 +01:00
int64_t a = * p_args [ 0 ] ;
int64_t b = * p_args [ 1 ] ;
2017-03-05 16:44:50 +01:00
r_ret = MIN ( a , b ) ;
2014-02-10 02:10:30 +01:00
} else {
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
real_t a = * p_args [ 0 ] ;
real_t b = * p_args [ 1 ] ;
2017-03-05 16:44:50 +01:00
r_ret = MIN ( a , b ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
case LOGIC_CLAMP : {
VALIDATE_ARG_COUNT ( 3 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) = = Variant : : INT & & p_args [ 1 ] - > get_type ( ) = = Variant : : INT & & p_args [ 2 ] - > get_type ( ) = = Variant : : INT ) {
2014-02-10 02:10:30 +01:00
int64_t a = * p_args [ 0 ] ;
int64_t b = * p_args [ 1 ] ;
int64_t c = * p_args [ 2 ] ;
2017-03-05 16:44:50 +01:00
r_ret = CLAMP ( a , b , c ) ;
2014-02-10 02:10:30 +01:00
} else {
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
VALIDATE_ARG_NUM ( 2 ) ;
real_t a = * p_args [ 0 ] ;
real_t b = * p_args [ 1 ] ;
real_t c = * p_args [ 2 ] ;
2017-03-05 16:44:50 +01:00
r_ret = CLAMP ( a , b , c ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
case LOGIC_NEAREST_PO2 : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
int64_t num = * p_args [ 0 ] ;
2017-08-17 23:35:55 +02:00
r_ret = next_power_of_2 ( num ) ;
2014-02-10 02:10:30 +01:00
} break ;
case OBJ_WEAKREF : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : OBJECT ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : OBJECT ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
if ( p_args [ 0 ] - > is_ref ( ) ) {
REF r = * p_args [ 0 ] ;
if ( ! r . is_valid ( ) ) {
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
Ref < WeakRef > wref = memnew ( WeakRef ) ;
2014-02-10 02:10:30 +01:00
wref - > set_ref ( r ) ;
2017-03-05 16:44:50 +01:00
r_ret = wref ;
2014-02-10 02:10:30 +01:00
} else {
Object * obj = * p_args [ 0 ] ;
if ( ! obj ) {
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
Ref < WeakRef > wref = memnew ( WeakRef ) ;
2014-02-10 02:10:30 +01:00
wref - > set_obj ( obj ) ;
2017-03-05 16:44:50 +01:00
r_ret = wref ;
2014-02-10 02:10:30 +01:00
}
2014-03-14 02:57:24 +01:00
} break ;
case FUNC_FUNCREF : {
VALIDATE_ARG_COUNT ( 2 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : OBJECT ) {
2014-03-14 02:57:24 +01:00
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : OBJECT ;
r_ret = Variant ( ) ;
2014-03-14 02:57:24 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( p_args [ 1 ] - > get_type ( ) ! = Variant : : STRING & & p_args [ 1 ] - > get_type ( ) ! = Variant : : NODE_PATH ) {
2014-03-14 02:57:24 +01:00
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 1 ;
r_error . expected = Variant : : STRING ;
r_ret = Variant ( ) ;
2014-03-14 02:57:24 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
Ref < FuncRef > fr = memnew ( FuncRef ) ;
2014-03-14 02:57:24 +01:00
fr - > set_instance ( * p_args [ 0 ] ) ;
fr - > set_function ( * p_args [ 1 ] ) ;
2017-03-05 16:44:50 +01:00
r_ret = fr ;
2014-03-14 02:57:24 +01:00
2014-02-10 02:10:30 +01:00
} break ;
case TYPE_CONVERT : {
VALIDATE_ARG_COUNT ( 2 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
int type = * p_args [ 1 ] ;
if ( type < 0 | | type > = Variant : : VARIANT_MAX ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
r_ret = RTR ( " Invalid type argument to convert(), use TYPE_* constants. " ) ;
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : INT ;
2016-06-12 00:43:38 +02:00
return ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
r_ret = Variant : : construct ( Variant : : Type ( type ) , p_args , 1 , r_error ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
case TYPE_OF : {
VALIDATE_ARG_COUNT ( 1 ) ;
r_ret = p_args [ 0 ] - > get_type ( ) ;
2016-06-18 09:07:51 +02:00
} break ;
case TYPE_EXISTS : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-01-03 03:03:46 +01:00
r_ret = ClassDB : : class_exists ( * p_args [ 0 ] ) ;
2016-06-18 09:07:51 +02:00
2014-02-10 02:10:30 +01:00
} break ;
2016-10-03 18:17:54 +02:00
case TEXT_CHAR : {
VALIDATE_ARG_COUNT ( 1 ) ;
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
CharType result [ 2 ] = { * p_args [ 0 ] , 0 } ;
r_ret = String ( result ) ;
2016-10-03 18:17:54 +02:00
} break ;
2014-02-10 02:10:30 +01:00
case TEXT_STR : {
String str ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_arg_count ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-01-14 18:03:38 +01:00
String os = p_args [ i ] - > operator String ( ) ;
2015-12-31 20:24:27 +01:00
2017-03-05 16:44:50 +01:00
if ( i = = 0 )
str = os ;
2014-02-10 02:10:30 +01:00
else
2017-03-05 16:44:50 +01:00
str + = os ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
r_ret = str ;
2014-02-10 02:10:30 +01:00
} break ;
case TEXT_PRINT : {
String str ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_arg_count ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
str + = p_args [ i ] - > operator String ( ) ;
2014-02-10 02:10:30 +01:00
}
//str+="\n";
print_line ( str ) ;
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case TEXT_PRINT_TABBED : {
String str ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_arg_count ; i + + ) {
2014-02-10 02:10:30 +01:00
if ( i )
2017-03-05 16:44:50 +01:00
str + = " \t " ;
str + = p_args [ i ] - > operator String ( ) ;
2014-02-10 02:10:30 +01:00
}
//str+="\n";
print_line ( str ) ;
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
2015-05-09 23:09:58 +02:00
} break ;
case TEXT_PRINT_SPACED : {
String str ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_arg_count ; i + + ) {
2015-05-09 23:09:58 +02:00
if ( i )
2017-03-05 16:44:50 +01:00
str + = " " ;
str + = p_args [ i ] - > operator String ( ) ;
2015-05-09 23:09:58 +02:00
}
//str+="\n";
print_line ( str ) ;
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2015-05-09 23:09:58 +02:00
2014-02-10 02:10:30 +01:00
} break ;
case TEXT_PRINTERR : {
String str ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_arg_count ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
str + = p_args [ i ] - > operator String ( ) ;
2014-02-10 02:10:30 +01:00
}
//str+="\n";
2017-03-05 16:44:50 +01:00
OS : : get_singleton ( ) - > printerr ( " %s \n " , str . utf8 ( ) . get_data ( ) ) ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case TEXT_PRINTRAW : {
String str ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < p_arg_count ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
str + = p_args [ i ] - > operator String ( ) ;
2014-02-10 02:10:30 +01:00
}
//str+="\n";
2017-03-05 16:44:50 +01:00
OS : : get_singleton ( ) - > print ( " %s " , str . utf8 ( ) . get_data ( ) ) ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
2015-02-15 05:19:46 +01:00
case VAR_TO_STR : {
VALIDATE_ARG_COUNT ( 1 ) ;
2015-12-31 04:54:00 +01:00
String vars ;
2017-03-05 16:44:50 +01:00
VariantWriter : : write_to_string ( * p_args [ 0 ] , vars ) ;
r_ret = vars ;
2015-02-15 05:19:46 +01:00
} break ;
case STR_TO_VAR : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : STRING ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : STRING ;
r_ret = Variant ( ) ;
2015-02-15 05:19:46 +01:00
return ;
}
2015-12-31 04:54:00 +01:00
VariantParser : : StreamString ss ;
2017-03-05 16:44:50 +01:00
ss . s = * p_args [ 0 ] ;
2015-12-31 04:54:00 +01:00
String errs ;
int line ;
2017-03-05 16:44:50 +01:00
Error err = VariantParser : : parse ( & ss , r_ret , errs , line ) ;
2015-12-31 04:54:00 +01:00
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : STRING ;
r_ret = " Parse error at line " + itos ( line ) + " : " + errs ;
2016-06-12 00:43:38 +02:00
return ;
2015-12-31 04:54:00 +01:00
}
2016-01-03 01:07:03 +01:00
} break ;
case VAR_TO_BYTES : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-01-11 04:52:51 +01:00
PoolByteArray barr ;
2016-01-03 01:07:03 +01:00
int len ;
2017-03-05 16:44:50 +01:00
Error err = encode_variant ( * p_args [ 0 ] , NULL , len ) ;
2016-01-03 01:07:03 +01:00
if ( err ) {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : NIL ;
r_ret = " Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID). " ;
2016-01-03 01:07:03 +01:00
return ;
}
barr . resize ( len ) ;
{
2017-01-11 04:52:51 +01:00
PoolByteArray : : Write w = barr . write ( ) ;
2017-03-05 16:44:50 +01:00
encode_variant ( * p_args [ 0 ] , w . ptr ( ) , len ) ;
2016-01-03 01:07:03 +01:00
}
2017-03-05 16:44:50 +01:00
r_ret = barr ;
2016-01-03 01:07:03 +01:00
} break ;
case BYTES_TO_VAR : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : POOL_BYTE_ARRAY ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : POOL_BYTE_ARRAY ;
r_ret = Variant ( ) ;
2016-01-03 01:07:03 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
PoolByteArray varr = * p_args [ 0 ] ;
2016-01-03 01:07:03 +01:00
Variant ret ;
{
2017-03-05 16:44:50 +01:00
PoolByteArray : : Read r = varr . read ( ) ;
Error err = decode_variant ( ret , r . ptr ( ) , varr . size ( ) , NULL ) ;
if ( err ! = OK ) {
r_ret = RTR ( " Not enough bytes for decoding bytes, or invalid format. " ) ;
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : POOL_BYTE_ARRAY ;
2016-01-03 01:07:03 +01:00
return ;
}
}
2017-03-05 16:44:50 +01:00
r_ret = ret ;
2016-01-03 01:07:03 +01:00
2015-02-15 05:19:46 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case GEN_RANGE : {
2017-03-05 16:44:50 +01:00
switch ( p_arg_count ) {
2014-02-10 02:10:30 +01:00
case 0 : {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ;
r_error . argument = 1 ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
case 1 : {
VALIDATE_ARG_NUM ( 0 ) ;
2017-03-05 16:44:50 +01:00
int count = * p_args [ 0 ] ;
2017-01-11 12:53:31 +01:00
Array arr ;
2017-03-05 16:44:50 +01:00
if ( count < = 0 ) {
r_ret = arr ;
2014-02-10 02:10:30 +01:00
return ;
}
Error err = arr . resize ( count ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_METHOD ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < count ; i + + ) {
arr [ i ] = i ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
r_ret = arr ;
2014-02-10 02:10:30 +01:00
} break ;
case 2 : {
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
int from = * p_args [ 0 ] ;
int to = * p_args [ 1 ] ;
2014-02-10 02:10:30 +01:00
2017-01-11 12:53:31 +01:00
Array arr ;
2017-03-05 16:44:50 +01:00
if ( from > = to ) {
r_ret = arr ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
Error err = arr . resize ( to - from ) ;
if ( err ! = OK ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_METHOD ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
for ( int i = from ; i < to ; i + + )
arr [ i - from ] = i ;
r_ret = arr ;
2014-02-10 02:10:30 +01:00
} break ;
case 3 : {
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
VALIDATE_ARG_NUM ( 2 ) ;
2017-03-05 16:44:50 +01:00
int from = * p_args [ 0 ] ;
int to = * p_args [ 1 ] ;
int incr = * p_args [ 2 ] ;
if ( incr = = 0 ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
r_ret = RTR ( " step argument is zero! " ) ;
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_METHOD ;
2016-06-12 00:43:38 +02:00
return ;
2014-02-10 02:10:30 +01:00
}
2017-01-11 12:53:31 +01:00
Array arr ;
2017-03-05 16:44:50 +01:00
if ( from > = to & & incr > 0 ) {
r_ret = arr ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( from < = to & & incr < 0 ) {
r_ret = arr ;
2014-02-10 02:10:30 +01:00
return ;
}
//calculate how many
2017-03-05 16:44:50 +01:00
int count = 0 ;
if ( incr > 0 ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
count = ( ( to - from - 1 ) / incr ) + 1 ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
count = ( ( from - to - 1 ) / - incr ) + 1 ;
2014-02-10 02:10:30 +01:00
}
Error err = arr . resize ( count ) ;
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_METHOD ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( incr > 0 ) {
int idx = 0 ;
for ( int i = from ; i < to ; i + = incr ) {
arr [ idx + + ] = i ;
2014-02-10 02:10:30 +01:00
}
} else {
2017-03-05 16:44:50 +01:00
int idx = 0 ;
for ( int i = from ; i > to ; i + = incr ) {
arr [ idx + + ] = i ;
2014-02-10 02:10:30 +01:00
}
}
2017-03-05 16:44:50 +01:00
r_ret = arr ;
2014-02-10 02:10:30 +01:00
} break ;
default : {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ;
r_error . argument = 3 ;
r_ret = Variant ( ) ;
2016-06-12 00:43:38 +02:00
2014-02-10 02:10:30 +01:00
} break ;
}
} break ;
2014-02-16 01:16:33 +01:00
case RESOURCE_LOAD : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : STRING ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : STRING ;
r_ret = Variant ( ) ;
2016-10-04 15:02:36 +02:00
} else {
2017-03-05 16:44:50 +01:00
r_ret = ResourceLoader : : load ( * p_args [ 0 ] ) ;
2014-02-16 01:16:33 +01:00
}
2014-03-14 02:57:24 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case INST2DICT : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) = = Variant : : NIL ) {
r_ret = Variant ( ) ;
} else if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : OBJECT ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
} else {
Object * obj = * p_args [ 0 ] ;
if ( ! obj ) {
2017-03-05 16:44:50 +01:00
r_ret = Variant ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
} else if ( ! obj - > get_script_instance ( ) | | obj - > get_script_instance ( ) - > get_language ( ) ! = GDScriptLanguage : : get_singleton ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : DICTIONARY ;
r_ret = RTR ( " Not a script with an instance " ) ;
2016-06-12 00:43:38 +02:00
return ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
GDInstance * ins = static_cast < GDInstance * > ( obj - > get_script_instance ( ) ) ;
2014-02-10 02:10:30 +01:00
Ref < GDScript > base = ins - > get_script ( ) ;
if ( base . is_null ( ) ) {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : DICTIONARY ;
r_ret = RTR ( " Not based on a script " ) ;
2014-02-10 02:10:30 +01:00
return ;
}
GDScript * p = base . ptr ( ) ;
Vector < StringName > sname ;
2017-03-05 16:44:50 +01:00
while ( p - > _owner ) {
2014-02-10 02:10:30 +01:00
sname . push_back ( p - > name ) ;
2017-03-05 16:44:50 +01:00
p = p - > _owner ;
2014-02-10 02:10:30 +01:00
}
sname . invert ( ) ;
if ( ! p - > path . is_resource_file ( ) ) {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : DICTIONARY ;
r_ret = Variant ( ) ;
2016-06-12 00:43:38 +02:00
2017-03-05 16:44:50 +01:00
r_ret = RTR ( " Not based on a resource file " ) ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
NodePath cp ( sname , Vector < StringName > ( ) , false ) ;
2014-02-10 02:10:30 +01:00
2017-01-11 12:53:31 +01:00
Dictionary d ;
2017-03-05 16:44:50 +01:00
d [ " @subpath " ] = cp ;
d [ " @path " ] = p - > path ;
2014-02-10 02:10:30 +01:00
p = base . ptr ( ) ;
2017-03-05 16:44:50 +01:00
while ( p ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( Set < StringName > : : Element * E = p - > members . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 02:10:30 +01:00
Variant value ;
2017-03-05 16:44:50 +01:00
if ( ins - > get ( E - > get ( ) , value ) ) {
2014-02-10 02:10:30 +01:00
String k = E - > get ( ) ;
if ( ! d . has ( k ) ) {
2017-03-05 16:44:50 +01:00
d [ k ] = value ;
2014-02-10 02:10:30 +01:00
}
}
}
2017-03-05 16:44:50 +01:00
p = p - > _base ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
r_ret = d ;
2014-02-10 02:10:30 +01:00
}
}
} break ;
case DICT2INST : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : DICTIONARY ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : DICTIONARY ;
r_ret = Variant ( ) ;
2016-06-12 00:43:38 +02:00
2014-02-10 02:10:30 +01:00
return ;
}
Dictionary d = * p_args [ 0 ] ;
if ( ! d . has ( " @path " ) ) {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : OBJECT ;
r_ret = RTR ( " Invalid instance dictionary format (missing @path) " ) ;
2016-06-12 00:43:38 +02:00
2014-02-10 02:10:30 +01:00
return ;
}
Ref < Script > scr = ResourceLoader : : load ( d [ " @path " ] ) ;
if ( ! scr . is_valid ( ) ) {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : OBJECT ;
r_ret = RTR ( " Invalid instance dictionary format (can't load script at @path) " ) ;
2014-02-10 02:10:30 +01:00
return ;
}
Ref < GDScript > gdscr = scr ;
if ( ! gdscr . is_valid ( ) ) {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : OBJECT ;
r_ret = Variant ( ) ;
r_ret = RTR ( " Invalid instance dictionary format (invalid script at @path) " ) ;
2014-02-10 02:10:30 +01:00
return ;
}
NodePath sub ;
if ( d . has ( " @subpath " ) ) {
2017-03-05 16:44:50 +01:00
sub = d [ " @subpath " ] ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < sub . get_name_count ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
gdscr = gdscr - > subclasses [ sub . get_name ( i ) ] ;
2014-02-10 02:10:30 +01:00
if ( ! gdscr . is_valid ( ) ) {
2017-03-05 16:44:50 +01:00
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : OBJECT ;
r_ret = Variant ( ) ;
r_ret = RTR ( " Invalid instance dictionary (invalid subclasses) " ) ;
2014-02-10 02:10:30 +01:00
return ;
}
}
2017-03-05 16:44:50 +01:00
r_ret = gdscr - > _new ( NULL , 0 , r_error ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
GDInstance * ins = static_cast < GDInstance * > ( static_cast < Object * > ( r_ret ) - > get_script_instance ( ) ) ;
2016-06-12 00:43:38 +02:00
Ref < GDScript > gd_ref = ins - > get_script ( ) ;
2015-09-20 21:17:30 +02:00
2017-03-05 16:44:50 +01:00
for ( Map < StringName , GDScript : : MemberInfo > : : Element * E = gd_ref - > member_indices . front ( ) ; E ; E = E - > next ( ) ) {
if ( d . has ( E - > key ( ) ) ) {
2016-06-12 00:43:38 +02:00
ins - > members [ E - > get ( ) . index ] = d [ E - > key ( ) ] ;
}
}
2015-09-20 21:17:30 +02:00
2014-06-16 15:22:26 +02:00
} break ;
2017-01-09 02:40:00 +01:00
case VALIDATE_JSON : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : STRING ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : STRING ;
r_ret = Variant ( ) ;
2017-01-09 02:40:00 +01:00
return ;
}
String errs ;
int errl ;
2017-03-05 16:44:50 +01:00
Error err = JSON : : parse ( * p_args [ 0 ] , r_ret , errs , errl ) ;
2017-01-09 02:40:00 +01:00
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
r_ret = itos ( errl ) + " : " + errs ;
2017-01-09 02:40:00 +01:00
} else {
2017-03-05 16:44:50 +01:00
r_ret = " " ;
2017-01-09 02:40:00 +01:00
}
} break ;
case PARSE_JSON : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : STRING ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : STRING ;
r_ret = Variant ( ) ;
2017-01-09 02:40:00 +01:00
return ;
}
String errs ;
int errl ;
2017-03-05 16:44:50 +01:00
Error err = JSON : : parse ( * p_args [ 0 ] , r_ret , errs , errl ) ;
2017-01-09 02:40:00 +01:00
2017-03-05 16:44:50 +01:00
if ( err ! = OK ) {
r_ret = Variant ( ) ;
2017-01-09 02:40:00 +01:00
}
} break ;
case TO_JSON : {
VALIDATE_ARG_COUNT ( 1 ) ;
r_ret = JSON : : print ( * p_args [ 0 ] ) ;
} break ;
2014-06-16 15:22:26 +02:00
case HASH : {
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
r_ret = p_args [ 0 ] - > hash ( ) ;
2014-06-16 15:22:26 +02:00
2015-12-31 22:26:49 +01:00
} break ;
case COLOR8 : {
2017-03-05 16:44:50 +01:00
if ( p_arg_count < 3 ) {
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ;
r_error . argument = 3 ;
r_ret = Variant ( ) ;
2016-06-12 00:43:38 +02:00
2015-12-31 22:26:49 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( p_arg_count > 4 ) {
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ;
r_error . argument = 4 ;
r_ret = Variant ( ) ;
2016-06-12 00:43:38 +02:00
2015-12-31 22:26:49 +01:00
return ;
}
VALIDATE_ARG_NUM ( 0 ) ;
VALIDATE_ARG_NUM ( 1 ) ;
VALIDATE_ARG_NUM ( 2 ) ;
2017-03-05 16:44:50 +01:00
Color color ( ( float ) * p_args [ 0 ] / 255.0f , ( float ) * p_args [ 1 ] / 255.0f , ( float ) * p_args [ 2 ] / 255.0f ) ;
2015-12-31 22:26:49 +01:00
2017-03-05 16:44:50 +01:00
if ( p_arg_count = = 4 ) {
2015-12-31 22:26:49 +01:00
VALIDATE_ARG_NUM ( 3 ) ;
2017-03-05 16:44:50 +01:00
color . a = ( float ) * p_args [ 3 ] / 255.0f ;
2015-12-31 22:26:49 +01:00
}
2017-03-05 16:44:50 +01:00
r_ret = color ;
2015-12-31 22:26:49 +01:00
2016-11-10 22:06:00 +01:00
} break ;
case COLORN : {
2017-03-05 16:44:50 +01:00
if ( p_arg_count < 1 ) {
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ;
r_error . argument = 1 ;
r_ret = Variant ( ) ;
2016-11-10 22:06:00 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( p_arg_count > 2 ) {
r_error . error = Variant : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ;
r_error . argument = 2 ;
r_ret = Variant ( ) ;
2016-11-10 22:06:00 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : STRING ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_ret = Variant ( ) ;
2016-11-10 22:06:00 +01:00
} else {
Color color = Color : : named ( * p_args [ 0 ] ) ;
2017-03-05 16:44:50 +01:00
if ( p_arg_count = = 2 ) {
2016-11-10 22:06:00 +01:00
VALIDATE_ARG_NUM ( 1 ) ;
2017-03-05 16:44:50 +01:00
color . a = * p_args [ 1 ] ;
2016-11-10 22:06:00 +01:00
}
2017-03-05 16:44:50 +01:00
r_ret = color ;
2016-11-10 22:06:00 +01:00
}
2014-02-10 02:10:30 +01:00
} break ;
case PRINT_STACK : {
2017-03-05 16:44:50 +01:00
ScriptLanguage * script = GDScriptLanguage : : get_singleton ( ) ;
for ( int i = 0 ; i < script - > debug_get_stack_level_count ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
print_line ( " Frame " + itos ( i ) + " - " + script - > debug_get_stack_level_source ( i ) + " : " + itos ( script - > debug_get_stack_level_line ( i ) ) + " in function ' " + script - > debug_get_stack_level_function ( i ) + " ' " ) ;
2014-02-10 02:10:30 +01:00
} ;
} break ;
2015-04-18 19:00:15 +02:00
case INSTANCE_FROM_ID : {
2015-03-25 04:01:12 +01:00
VALIDATE_ARG_COUNT ( 1 ) ;
2017-03-05 16:44:50 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : INT & & p_args [ 0 ] - > get_type ( ) ! = Variant : : REAL ) {
r_error . error = Variant : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
r_error . argument = 0 ;
r_error . expected = Variant : : INT ;
r_ret = Variant ( ) ;
2015-03-25 04:01:12 +01:00
break ;
}
2017-03-05 16:44:50 +01:00
uint32_t id = * p_args [ 0 ] ;
r_ret = ObjectDB : : get_instance ( id ) ;
2015-03-25 04:01:12 +01:00
2017-08-07 23:34:18 +02:00
} 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. " ) ;
}
}
2015-03-25 04:01:12 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case FUNC_MAX : {
2016-05-12 01:57:52 +02:00
ERR_FAIL ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
}
}
bool GDFunctions : : is_deterministic ( Function p_func ) {
//man i couldn't have chosen a worse function name,
//way too controversial..
2017-03-05 16:44:50 +01:00
switch ( p_func ) {
2014-02-10 02:10:30 +01:00
case MATH_SIN :
case MATH_COS :
case MATH_TAN :
case MATH_SINH :
case MATH_COSH :
case MATH_TANH :
case MATH_ASIN :
case MATH_ACOS :
case MATH_ATAN :
case MATH_ATAN2 :
case MATH_SQRT :
case MATH_FMOD :
case MATH_FPOSMOD :
case MATH_FLOOR :
case MATH_CEIL :
case MATH_ROUND :
case MATH_ABS :
case MATH_SIGN :
case MATH_POW :
case MATH_LOG :
case MATH_EXP :
case MATH_ISNAN :
case MATH_ISINF :
case MATH_EASE :
case MATH_DECIMALS :
case MATH_STEPIFY :
case MATH_LERP :
2017-08-10 16:06:10 +02:00
case MATH_INVERSE_LERP :
case MATH_RANGE_LERP :
2014-02-10 02:10:30 +01:00
case MATH_DECTIME :
case MATH_DEG2RAD :
case MATH_RAD2DEG :
case MATH_LINEAR2DB :
case MATH_DB2LINEAR :
case LOGIC_MAX :
case LOGIC_MIN :
case LOGIC_CLAMP :
case LOGIC_NEAREST_PO2 :
case TYPE_CONVERT :
case TYPE_OF :
2016-06-18 09:07:51 +02:00
case TYPE_EXISTS :
2016-10-03 18:17:54 +02:00
case TEXT_CHAR :
2014-02-10 02:10:30 +01:00
case TEXT_STR :
2015-12-31 22:26:49 +01:00
case COLOR8 :
2017-08-07 23:34:18 +02:00
case LEN :
2017-03-05 16:44:50 +01:00
// enable for debug only, otherwise not desirable - case GEN_RANGE:
2014-02-10 02:10:30 +01:00
return true ;
default :
return false ;
}
return false ;
}
MethodInfo GDFunctions : : get_info ( Function p_func ) {
# ifdef TOOLS_ENABLED
//using a switch, so the compiler generates a jumptable
2017-03-05 16:44:50 +01:00
switch ( p_func ) {
2014-02-10 02:10:30 +01:00
case MATH_SIN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " sin " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_COS : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " cos " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_TAN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " tan " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_SINH : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " sinh " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_COSH : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " cosh " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_TANH : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " tanh " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ASIN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " asin " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ACOS : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " acos " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ATAN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " atan " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ATAN2 : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " atan2 " , PropertyInfo ( Variant : : REAL , " x " ) , PropertyInfo ( Variant : : REAL , " y " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_SQRT : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " sqrt " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_FMOD : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " fmod " , PropertyInfo ( Variant : : REAL , " x " ) , PropertyInfo ( Variant : : REAL , " y " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_FPOSMOD : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " fposmod " , PropertyInfo ( Variant : : REAL , " x " ) , PropertyInfo ( Variant : : REAL , " y " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_FLOOR : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " floor " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
2017-03-05 16:44:50 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case MATH_CEIL : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " ceil " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ROUND : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " round " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ABS : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " abs " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_SIGN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " sign " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_POW : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " pow " , PropertyInfo ( Variant : : REAL , " x " ) , PropertyInfo ( Variant : : REAL , " y " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_LOG : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " log " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_EXP : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " exp " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ISNAN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " is_nan " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_ISINF : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " is_inf " , PropertyInfo ( Variant : : REAL , " s " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_EASE : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " ease " , PropertyInfo ( Variant : : REAL , " s " ) , PropertyInfo ( Variant : : REAL , " curve " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_DECIMALS : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " decimals " , PropertyInfo ( Variant : : REAL , " step " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_STEPIFY : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " stepify " , PropertyInfo ( Variant : : REAL , " s " ) , PropertyInfo ( Variant : : REAL , " step " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_LERP : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " lerp " , PropertyInfo ( Variant : : REAL , " from " ) , PropertyInfo ( Variant : : REAL , " to " ) , PropertyInfo ( Variant : : REAL , " weight " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
2017-08-10 16:06:10 +02:00
case MATH_INVERSE_LERP : {
MethodInfo mi ( " inverse_lerp " , PropertyInfo ( Variant : : REAL , " from " ) , PropertyInfo ( Variant : : REAL , " to " ) , PropertyInfo ( Variant : : REAL , " value " ) ) ;
mi . return_val . type = Variant : : REAL ;
return mi ;
} break ;
case MATH_RANGE_LERP : {
MethodInfo mi ( " range_lerp " , PropertyInfo ( Variant : : REAL , " value " ) , PropertyInfo ( Variant : : REAL , " istart " ) , PropertyInfo ( Variant : : REAL , " istop " ) , PropertyInfo ( Variant : : REAL , " ostart " ) , PropertyInfo ( Variant : : REAL , " ostop " ) ) ;
mi . return_val . type = Variant : : REAL ;
return mi ;
} break ;
2014-02-10 02:10:30 +01:00
case MATH_DECTIME : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " dectime " , PropertyInfo ( Variant : : REAL , " value " ) , PropertyInfo ( Variant : : REAL , " amount " ) , PropertyInfo ( Variant : : REAL , " step " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_RANDOMIZE : {
MethodInfo mi ( " randomize " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_RAND : {
2014-04-05 17:39:30 +02:00
MethodInfo mi ( " randi " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : INT ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_RANDF : {
MethodInfo mi ( " randf " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_RANDOM : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " rand_range " , PropertyInfo ( Variant : : REAL , " from " ) , PropertyInfo ( Variant : : REAL , " to " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
2015-03-25 04:01:12 +01:00
case MATH_SEED : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " seed " , PropertyInfo ( Variant : : INT , " seed " ) ) ;
mi . return_val . type = Variant : : NIL ;
2015-03-25 04:01:12 +01:00
return mi ;
} break ;
2014-02-10 02:10:30 +01:00
case MATH_RANDSEED : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " rand_seed " , PropertyInfo ( Variant : : INT , " seed " ) ) ;
mi . return_val . type = Variant : : ARRAY ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_DEG2RAD : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " deg2rad " , PropertyInfo ( Variant : : REAL , " deg " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_RAD2DEG : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " rad2deg " , PropertyInfo ( Variant : : REAL , " rad " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_LINEAR2DB : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " linear2db " , PropertyInfo ( Variant : : REAL , " nrg " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case MATH_DB2LINEAR : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " db2linear " , PropertyInfo ( Variant : : REAL , " db " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case LOGIC_MAX : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " max " , PropertyInfo ( Variant : : REAL , " a " ) , PropertyInfo ( Variant : : REAL , " b " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case LOGIC_MIN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " min " , PropertyInfo ( Variant : : REAL , " a " ) , PropertyInfo ( Variant : : REAL , " b " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case LOGIC_CLAMP : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " clamp " , PropertyInfo ( Variant : : REAL , " val " ) , PropertyInfo ( Variant : : REAL , " min " ) , PropertyInfo ( Variant : : REAL , " max " ) ) ;
mi . return_val . type = Variant : : REAL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case LOGIC_NEAREST_PO2 : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " nearest_po2 " , PropertyInfo ( Variant : : INT , " val " ) ) ;
mi . return_val . type = Variant : : INT ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case OBJ_WEAKREF : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " weakref " , PropertyInfo ( Variant : : OBJECT , " obj " ) ) ;
mi . return_val . type = Variant : : OBJECT ;
mi . return_val . name = " WeakRef " ;
2015-01-03 20:52:37 +01:00
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
2014-03-14 02:57:24 +01:00
case FUNC_FUNCREF : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " funcref " , PropertyInfo ( Variant : : OBJECT , " instance " ) , PropertyInfo ( Variant : : STRING , " funcname " ) ) ;
mi . return_val . type = Variant : : OBJECT ;
mi . return_val . name = " FuncRef " ;
2014-03-14 02:57:24 +01:00
return mi ;
} break ;
2014-02-10 02:10:30 +01:00
case TYPE_CONVERT : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " convert " , PropertyInfo ( Variant : : NIL , " what " ) , PropertyInfo ( Variant : : INT , " type " ) ) ;
mi . return_val . type = Variant : : OBJECT ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case TYPE_OF : {
2016-01-25 10:55:50 +01:00
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " typeof " , PropertyInfo ( Variant : : NIL , " what " ) ) ;
mi . return_val . type = Variant : : INT ;
2016-01-25 10:55:50 +01:00
return mi ;
2016-06-18 09:07:51 +02:00
} break ;
case TYPE_EXISTS : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " type_exists " , PropertyInfo ( Variant : : STRING , " type " ) ) ;
mi . return_val . type = Variant : : BOOL ;
2016-06-18 09:07:51 +02:00
return mi ;
2016-10-03 18:17:54 +02:00
} break ;
case TEXT_CHAR : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " char " , PropertyInfo ( Variant : : INT , " ascii " ) ) ;
mi . return_val . type = Variant : : STRING ;
2016-10-03 18:17:54 +02:00
return mi ;
2016-01-25 10:55:50 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case TEXT_STR : {
2017-08-29 18:16:03 +02:00
MethodInfo mi ( " str " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : STRING ;
2017-08-29 18:16:03 +02:00
mi . flags | = METHOD_FLAG_VARARG ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case TEXT_PRINT : {
2017-08-29 18:16:03 +02:00
MethodInfo mi ( " print " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 18:16:03 +02:00
mi . flags | = METHOD_FLAG_VARARG ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case TEXT_PRINT_TABBED : {
2017-08-29 18:16:03 +02:00
MethodInfo mi ( " printt " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 18:16:03 +02:00
mi . flags | = METHOD_FLAG_VARARG ;
2014-02-10 02:10:30 +01:00
return mi ;
2015-05-09 23:09:58 +02:00
} break ;
case TEXT_PRINT_SPACED : {
2017-08-29 18:16:03 +02:00
MethodInfo mi ( " prints " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 18:16:03 +02:00
mi . flags | = METHOD_FLAG_VARARG ;
2015-05-09 23:09:58 +02:00
return mi ;
2014-02-10 02:10:30 +01:00
} break ;
case TEXT_PRINTERR : {
2017-08-29 18:16:03 +02:00
MethodInfo mi ( " printerr " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 18:16:03 +02:00
mi . flags | = METHOD_FLAG_VARARG ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case TEXT_PRINTRAW : {
2017-08-29 18:16:03 +02:00
MethodInfo mi ( " printraw " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 18:16:03 +02:00
mi . flags | = METHOD_FLAG_VARARG ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
2015-02-15 05:19:46 +01:00
case VAR_TO_STR : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " var2str " , PropertyInfo ( Variant : : NIL , " var " ) ) ;
mi . return_val . type = Variant : : STRING ;
2015-02-15 05:19:46 +01:00
return mi ;
} break ;
case STR_TO_VAR : {
2017-08-29 07:15:46 +02:00
MethodInfo mi ( Variant : : NIL , " str2var " , PropertyInfo ( Variant : : STRING , " string " ) ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 07:15:46 +02:00
mi . return_val . usage | = PROPERTY_USAGE_NIL_IS_VARIANT ;
2015-02-15 05:19:46 +01:00
return mi ;
} break ;
2016-01-03 01:07:03 +01:00
case VAR_TO_BYTES : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " var2bytes " , PropertyInfo ( Variant : : NIL , " var " ) ) ;
mi . return_val . type = Variant : : POOL_BYTE_ARRAY ;
2016-01-03 01:07:03 +01:00
return mi ;
} break ;
case BYTES_TO_VAR : {
2017-08-29 07:15:46 +02:00
MethodInfo mi ( Variant : : NIL , " bytes2var " , PropertyInfo ( Variant : : POOL_BYTE_ARRAY , " bytes " ) ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 07:15:46 +02:00
mi . return_val . usage | = PROPERTY_USAGE_NIL_IS_VARIANT ;
2016-01-03 01:07:03 +01:00
return mi ;
} break ;
2014-02-10 02:10:30 +01:00
case GEN_RANGE : {
2017-08-29 18:16:03 +02:00
MethodInfo mi ( " range " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : ARRAY ;
2017-08-29 18:16:03 +02:00
mi . flags | = METHOD_FLAG_VARARG ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
2014-02-16 01:16:33 +01:00
case RESOURCE_LOAD : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " load " , PropertyInfo ( Variant : : STRING , " path " ) ) ;
mi . return_val . type = Variant : : OBJECT ;
mi . return_val . name = " Resource " ;
2014-02-16 01:16:33 +01:00
return mi ;
} break ;
2014-02-10 02:10:30 +01:00
case INST2DICT : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " inst2dict " , PropertyInfo ( Variant : : OBJECT , " inst " ) ) ;
mi . return_val . type = Variant : : DICTIONARY ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
case DICT2INST : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " dict2inst " , PropertyInfo ( Variant : : DICTIONARY , " dict " ) ) ;
mi . return_val . type = Variant : : OBJECT ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
2017-01-09 02:40:00 +01:00
case VALIDATE_JSON : {
2017-08-29 07:15:46 +02:00
MethodInfo mi ( " validate_json " , PropertyInfo ( Variant : : STRING , " json " ) ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : STRING ;
2017-01-09 02:40:00 +01:00
return mi ;
} break ;
case PARSE_JSON : {
2017-08-29 07:15:46 +02:00
MethodInfo mi ( Variant : : NIL , " parse_json " , PropertyInfo ( Variant : : STRING , " json " ) ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2017-08-29 07:15:46 +02:00
mi . return_val . usage | = PROPERTY_USAGE_NIL_IS_VARIANT ;
2017-01-09 02:40:00 +01:00
return mi ;
} break ;
case TO_JSON : {
2017-07-18 21:03:34 +02:00
MethodInfo mi ( " to_json " , PropertyInfo ( Variant : : NIL , " var " ) ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : STRING ;
2017-01-09 02:40:00 +01:00
return mi ;
} break ;
2014-06-16 15:22:26 +02:00
case HASH : {
2017-07-18 21:03:34 +02:00
MethodInfo mi ( " hash " , PropertyInfo ( Variant : : NIL , " var " ) ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : INT ;
2014-06-16 15:22:26 +02:00
return mi ;
} break ;
2015-12-31 22:26:49 +01:00
case COLOR8 : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " Color8 " , PropertyInfo ( Variant : : INT , " r8 " ) , PropertyInfo ( Variant : : INT , " g8 " ) , PropertyInfo ( Variant : : INT , " b8 " ) , PropertyInfo ( Variant : : INT , " a8 " ) ) ;
mi . return_val . type = Variant : : COLOR ;
2015-12-31 22:26:49 +01:00
return mi ;
} break ;
2016-11-10 22:06:00 +01:00
case COLORN : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " ColorN " , PropertyInfo ( Variant : : STRING , " name " ) , PropertyInfo ( Variant : : REAL , " alpha " ) ) ;
mi . return_val . type = Variant : : COLOR ;
2016-11-10 22:06:00 +01:00
return mi ;
} break ;
2014-02-10 02:10:30 +01:00
case PRINT_STACK : {
MethodInfo mi ( " print_stack " ) ;
2017-03-05 16:44:50 +01:00
mi . return_val . type = Variant : : NIL ;
2014-02-10 02:10:30 +01:00
return mi ;
} break ;
2015-04-18 19:00:15 +02:00
case INSTANCE_FROM_ID : {
2017-03-05 16:44:50 +01:00
MethodInfo mi ( " instance_from_id " , PropertyInfo ( Variant : : INT , " instance_id " ) ) ;
mi . return_val . type = Variant : : OBJECT ;
2015-03-25 04:01:12 +01:00
return mi ;
} break ;
2017-08-07 23:34:18 +02:00
case LEN : {
MethodInfo mi ( " len " , PropertyInfo ( Variant : : NIL , " var " ) ) ;
mi . return_val . type = Variant : : INT ;
return mi ;
} break ;
2015-03-25 04:01:12 +01:00
2014-02-10 02:10:30 +01:00
case FUNC_MAX : {
ERR_FAIL_V ( MethodInfo ( ) ) ;
} break ;
}
# endif
return MethodInfo ( ) ;
}