From 966e3cdee651adb6bdf34a0d56c826d91aed14e8 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Wed, 20 Apr 2016 15:08:42 +0300 Subject: [PATCH] console: `(ConFuncVA va){}` will get unparsed command line --- console.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/console.d b/console.d index 6e24674..1a31a8c 100644 --- a/console.d +++ b/console.d @@ -685,6 +685,10 @@ public class ConFuncBase : ConCommand { } +public struct ConFuncVA { + const(char)[] cmdline; +} + // we have to make the class nested, so we can use `dg`, which keeps default args public void conRegFunc(alias fn) (string aname, string ahelp=null) if (isCallable!fn) { // hack for inline lambdas @@ -706,6 +710,9 @@ public void conRegFunc(alias fn) (string aname, string ahelp=null) if (isCallabl } else { dg(); } + } else static if (args.length == 1 && is(typeof(args[0]) == ConFuncVA)) { + args[0].cmdline = cmdline; + dg(args); } else { alias defaultArguments = ParameterDefaultValueTuple!fn; //pragma(msg, "defs: ", defaultArguments); @@ -787,6 +794,17 @@ version(contest_func) unittest { conRegFunc!({conwriteln("!!!");})("bang"); conExecute("bang"); + + conRegFunc!((ConFuncVA va) { + int idx = 1; + for (;;) { + auto w = ConCommand.getWord(va.cmdline); + if (w is null) break; + conwriteln("#", idx, ": [", w, "]"); + ++idx; + } + })("doo"); + conExecute("doo 1 2 ' 34 '"); } -- 2.11.4.GIT