From b0257f021db382439c6f560e87cfbf1aefc732d2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 29 May 2017 19:02:00 -0400 Subject: add buildin isstr() --- src/map/script.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/map/script.c b/src/map/script.c index 75f747fb6..f83310187 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -16131,6 +16131,26 @@ BUILDIN(charat) { return true; } +//======================================================= +// isstr +// +// returns type: +// 0 - int +// 1 - string +// 2 - other +//------------------------------------------------------- +BUILDIN(isstr) +{ + if (script_isinttype(st, 2)) { + script_pushint(st, 0); + } else if (script_isstringtype(st, 2)) { + script_pushint(st, 1); + } else { + script_pushint(st, 2); + } + return true; +} + //======================================================= // chr //------------------------------------------------------- @@ -23529,6 +23549,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(getstrlen,"s"), //strlen [Valaris] BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris] BUILDIN_DEF(charat,"si"), + BUILDIN_DEF(isstr,"v"), BUILDIN_DEF(chr,"i"), BUILDIN_DEF(ord,"s"), BUILDIN_DEF(setchar,"ssi"), -- cgit v1.2.3-70-g09d2 From 66101aaf34c55b6928974b78355eea0593de44d2 Mon Sep 17 00:00:00 2001 From: gumi Date: Mon, 29 May 2017 19:05:20 -0400 Subject: add documentation for isstr() --- doc/script_commands.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 0ba350ad1..923fad96b 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -8247,6 +8247,18 @@ else. --------------------------------------- +*isstr() + +This command checks if the given is a string (1), +an integer (0) or something else (2). + +Example: + + isstr(69); // outputs 0 + isstr("69"); // outputs 1 + +--------------------------------------- + *charisalpha("", ) This function will return true if the character number Position in the given -- cgit v1.2.3-70-g09d2 From 0f18b10b7702d53e8dac866ffafb31097dbea5cc Mon Sep 17 00:00:00 2001 From: gumi Date: Wed, 31 May 2017 12:12:43 -0400 Subject: add buildin getarrayindex() --- src/map/script.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/map/script.c b/src/map/script.c index f83310187..075b980ca 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -7314,6 +7314,22 @@ int script_array_index_cmp(const void *a, const void *b) return (*(const unsigned int *)a - *(const unsigned int *)b); // FIXME: Is the unsigned difference really intended here? } +BUILDIN(getarrayindex) +{ + struct script_data *data = script_getdata(st, 2); + + if (!data_isreference(data) || reference_toconstant(data)) + { + ShowError("script:getarrayindex: not a variable\n"); + script->reportdata(data); + st->state = END; + return false;// not a variable + } + + script_pushint(st, reference_getindex(data)); + return true; +} + /// Deletes count or all the elements in an array, from the starting index. /// ex: deletearray arr[4],2; /// @@ -23297,6 +23313,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(cleararray,"rvi"), BUILDIN_DEF(copyarray,"rri"), BUILDIN_DEF(getarraysize,"r"), + BUILDIN_DEF(getarrayindex,"r"), BUILDIN_DEF(deletearray,"r?"), BUILDIN_DEF(getelementofarray,"ri"), BUILDIN_DEF(getitem,"vi?"), -- cgit v1.2.3-70-g09d2 From 7e521f026429f0ccfa9c95197c26453e7caef72b Mon Sep 17 00:00:00 2001 From: gumi Date: Wed, 31 May 2017 12:15:47 -0400 Subject: add documentation for getarrayindex() --- doc/script_commands.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 923fad96b..49db95153 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -2437,6 +2437,17 @@ If you do this: --------------------------------------- +*getarrayindex() + +This command returns the index of the passed array. This is useful when +used in combination with getarg() + +Example: + + getarrayindex(.@foo[42]) // 42 + +--------------------------------------- + *getelementofarray(, ) This command retrieves the value of the element of given array at given -- cgit v1.2.3-70-g09d2