summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2017-06-03 18:36:40 +0200
committerGitHub <noreply@github.com>2017-06-03 18:36:40 +0200
commitcaebdf44507fcd345b63211588fbe607fefd0d78 (patch)
tree15e01308be0ab89bb49aaeac5d723d2629ac5cd9
parent968a0b5cf3d016bf929e27f02f0dd124ac7c5a3d (diff)
parent7e521f026429f0ccfa9c95197c26453e7caef72b (diff)
downloadhercules-caebdf44507fcd345b63211588fbe607fefd0d78.tar.gz
hercules-caebdf44507fcd345b63211588fbe607fefd0d78.tar.bz2
hercules-caebdf44507fcd345b63211588fbe607fefd0d78.tar.xz
hercules-caebdf44507fcd345b63211588fbe607fefd0d78.zip
Merge pull request #1753 from mekolat/string2
new buildins: isstr, getarrayindex
-rw-r--r--doc/script_commands.txt23
-rw-r--r--src/map/script.c38
2 files changed, 61 insertions, 0 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index f1b7f14dc..e4f7e24a1 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -2441,6 +2441,17 @@ If you do this:
---------------------------------------
+*getarrayindex(<array name>)
+
+This command returns the index of the passed array. This is useful when
+used in combination with getarg()
+
+Example:
+
+ getarrayindex(.@foo[42]) // 42
+
+---------------------------------------
+
*getelementofarray(<array name>, <index>)
This command retrieves the value of the element of given array at given
@@ -8275,6 +8286,18 @@ else.
---------------------------------------
+*isstr(<argument>)
+
+This command checks if the given <argument> is a string (1),
+an integer (0) or something else (2).
+
+Example:
+
+ isstr(69); // outputs 0
+ isstr("69"); // outputs 1
+
+---------------------------------------
+
*charisalpha("<string>", <position>)
This function will return true if the character number Position in the given
diff --git a/src/map/script.c b/src/map/script.c
index ecb053fdc..5ef54ed2e 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -7320,6 +7320,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;
///
@@ -16138,6 +16154,26 @@ BUILDIN(charat) {
}
//=======================================================
+// isstr <argument>
+//
+// 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 <int>
//-------------------------------------------------------
BUILDIN(chr)
@@ -23322,6 +23358,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?"),
@@ -23574,6 +23611,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"),