diff options
author | gumi <mekolat@users.noreply.github.com> | 2017-06-21 14:12:48 -0400 |
---|---|---|
committer | gumi <mekolat@users.noreply.github.com> | 2017-07-11 09:34:19 -0400 |
commit | 77ac83970809d61a6b47b6626563f44f85b2ea48 (patch) | |
tree | 5985bdcddaf3941c7764bc2c449f1995bd0332a7 | |
parent | b9b9f885434f56d862078a896c440a772de55dc8 (diff) | |
download | hercules-77ac83970809d61a6b47b6626563f44f85b2ea48.tar.gz hercules-77ac83970809d61a6b47b6626563f44f85b2ea48.tar.bz2 hercules-77ac83970809d61a6b47b6626563f44f85b2ea48.tar.xz hercules-77ac83970809d61a6b47b6626563f44f85b2ea48.zip |
add getdatatype() buildins20170725
-rw-r--r-- | src/map/script.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/map/script.c b/src/map/script.c index 7d724d3f1..abe02c13f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -16210,6 +16210,60 @@ BUILDIN(isstr) return true; } +enum datatype { + DATATYPE_NIL = 1 << 7, // we don't start at 1, to leave room for primitives + DATATYPE_STR = 1 << 8, + DATATYPE_INT = 1 << 9, + DATATYPE_CONST = 1 << 10, + DATATYPE_PARAM = 1 << 11, + DATATYPE_VAR = 1 << 12, + DATATYPE_LABEL = 1 << 13, +}; + +BUILDIN(getdatatype) { + int type; + + if (script_hasdata(st, 2)) { + struct script_data *data = script_getdata(st, 2); + + if (data_isstring(data)) { + type = DATATYPE_STR; + if (data->type == C_CONSTSTR) { + type |= DATATYPE_CONST; + } + } else if (data_isint(data)) { + type = DATATYPE_INT; + } else if (data_islabel(data)) { + type = DATATYPE_LABEL; + } else if (data_isreference(data)) { + if (reference_toconstant(data)) { + type = DATATYPE_CONST | DATATYPE_INT; + } else if (reference_toparam(data)) { + type = DATATYPE_PARAM | DATATYPE_INT; + } else if (reference_tovariable(data)) { + type = DATATYPE_VAR; + if (is_string_variable(reference_getname(data))) { + type |= DATATYPE_STR; + } else { + type |= DATATYPE_INT; + } + } else { + ShowError("script:getdatatype: Unknown reference type!\n"); + script->reportdata(data); + st->state = END; + return false; + } + } else { + type = data->type; // fallback to primitive type if unknown + } + } else { + type = DATATYPE_NIL; // nothing was passed + } + + script_pushint(st, type); + return true; +} + //======================================================= // chr <int> //------------------------------------------------------- @@ -23654,6 +23708,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris] BUILDIN_DEF(charat,"si"), BUILDIN_DEF(isstr,"v"), + BUILDIN_DEF(getdatatype, "?"), BUILDIN_DEF(chr,"i"), BUILDIN_DEF(ord,"s"), BUILDIN_DEF(setchar,"ssi"), @@ -24127,6 +24182,15 @@ void script_hardcoded_constants(void) script->set_constant("PERM_DISABLE_EXP", PC_PERM_DISABLE_EXP, false, false); script->set_constant("PERM_DISABLE_SKILL_USAGE", PC_PERM_DISABLE_SKILL_USAGE, false, false); + script->constdb_comment("Data types"); + script->set_constant("DATATYPE_NIL", DATATYPE_NIL, false, false); + script->set_constant("DATATYPE_STR", DATATYPE_STR, false, false); + script->set_constant("DATATYPE_INT", DATATYPE_INT, false, false); + script->set_constant("DATATYPE_CONST", DATATYPE_CONST, false, false); + script->set_constant("DATATYPE_PARAM", DATATYPE_PARAM, false, false); + script->set_constant("DATATYPE_VAR", DATATYPE_VAR, false, false); + script->set_constant("DATATYPE_LABEL", DATATYPE_LABEL, false, false); + script->constdb_comment("Renewal"); #ifdef RENEWAL script->set_constant("RENEWAL", 1, false, false); |