From f085c1739a9fafd745492e9c424dd20b1615b7cf Mon Sep 17 00:00:00 2001 From: mekolat Date: Sun, 28 Jun 2015 17:05:36 -0400 Subject: add elif and else builtins --- src/map/script-fun.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/map/script-fun.cpp') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 5e55e53..2a50762 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -469,6 +469,64 @@ void builtin_if (ScriptState *st) int sel, i; sel = conv_num(st, &AARG(0)); + st->is_true = sel ? 2 : 1; + if (!sel) + return; + + // 関数名をコピー + push_copy(st->stack, st->start + 3); + // 間に引数マーカを入れて + push_int(st->stack, 0); + // 残りの引数をコピー + for (i = st->start + 4; i < st->end; i++) + { + push_copy(st->stack, i); + } + run_func(st); +} + +static +void builtin_else (ScriptState *st) +{ + int i; + + if (st->is_true < 1) + { + PRINTF("builtin_else: no if statement!\n"_fmt); + abort(); + } + + if (st->is_true > 1) + return; + + st->is_true = 0; + // 関数名をコピー + push_copy(st->stack, st->start + 2); + // 間に引数マーカを入れて + push_int(st->stack, 0); + // 残りの引数をコピー + for (i = st->start + 3; i < st->end; i++) + { + push_copy(st->stack, i); + } + run_func(st); +} + +static +void builtin_elif (ScriptState *st) +{ + int sel, i; + + if (st->is_true < 1) + { + PRINTF("builtin_elif: no if statement!\n"_fmt); + abort(); + } + if (st->is_true > 1) + return; + + sel = conv_num(st, &AARG(0)); + st->is_true = sel ? 2 : 1; if (!sel) return; @@ -3149,6 +3207,8 @@ BuiltinFunction builtin_functions[] = BUILTIN(heal, "ii?"_s, '\0'), BUILTIN(input, "N"_s, '\0'), BUILTIN(if, "iF*"_s, '\0'), + BUILTIN(elif, "iF*"_s, '\0'), + BUILTIN(else, "F*"_s, '\0'), BUILTIN(set, "Ne"_s, '\0'), BUILTIN(setarray, "Ne*"_s, '\0'), BUILTIN(cleararray, "Nei"_s, '\0'), -- cgit v1.2.3-70-g09d2