summaryrefslogtreecommitdiff
path: root/src
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 /src
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
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c38
1 files changed, 38 insertions, 0 deletions
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"),