예제 #1
0
    public static Stack <object> Eval(string script)
    {
        if (string.IsNullOrEmpty(script))
        {
            throw new InvalidScriptException("Script is empty");
        }

        var interpreter = new CsInterpreter();
        var lineNo      = 0;
        var lines       = script.Split("\n");

        try
        {
            for (; lineNo < lines.Length; lineNo++)
            {
                if (string.IsNullOrEmpty(lines[lineNo]) || string.IsNullOrWhiteSpace(lines[lineNo]))
                {
                    continue;
                }
                interpreter.EvalLine(lines[lineNo].Trim());
            }
        }
        catch (Exception e)
        {
            throw new InvalidScriptException(string.Format("Error in #{0} \n{1}", lineNo, e));
        }

        return(interpreter.stack);
    }
예제 #2
0
    static void Main(string[] args)
    {
        var script = @"
PushString:MAKI
PushInt:114514
PushFloat:99.99
PushNull:

PushNew:Hoge
PeekToGlobal:this
PushFromGlobal:this
PushFloat:2.70
PopField:Hoge.ff


PushFromGlobal:this
PushInt:8
Call:Hoge.m

// PushField:
// SetProp:
// Call:
        ";

        var lastStack = CsInterpreter.Eval(script);

        Console.WriteLine(string.Join("\n", lastStack));
    }