From c41894ef2fd51dcc17e030536272fbf03f17f1a8 Mon Sep 17 00:00:00 2001 From: Fate Date: Sat, 29 Nov 2008 12:26:36 -0700 Subject: Added bitwise negation operator `neg' --- doc/spell-language | 3 +++ src/map/magic-expr.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/doc/spell-language b/doc/spell-language index d5a798a..5ce5520 100644 --- a/doc/spell-language +++ b/doc/spell-language @@ -422,6 +422,9 @@ The following functions are available: + not : int -> int Logical negation. (NOT bitwise negation.) + + neg : int -> int + Bitwise negation. + + name_of : entity -> string | spell -> string Retrieves the name either of an entity or of a spell. diff --git a/src/map/magic-expr.c b/src/map/magic-expr.c index 04e5e60..d22e596 100644 --- a/src/map/magic-expr.c +++ b/src/map/magic-expr.c @@ -311,6 +311,13 @@ fun_not(env_t *env, int args_nr, val_t *result, val_t *args) return 0; } +static int +fun_neg(env_t *env, int args_nr, val_t *result, val_t *args) +{ + RESULTINT = ~ARGINT(0); + return 0; +} + static int fun_gte(env_t *env, int args_nr, val_t *result, val_t *args) { @@ -1028,6 +1035,7 @@ static fun_t functions[] = { { "<<", "ii", 'i', fun_bitshl }, { ">>", "ii", 'i', fun_bitshr }, { "not", "i", 'i', fun_not }, + { "neg", "i", 'i', fun_neg }, { "max", "ii", 'i', fun_max }, { "min", "ii", 'i', fun_min }, { "is_in", "la", 'i', fun_is_in }, -- cgit v1.2.3-70-g09d2