예제 #1
0
        public static DynValue error(ScriptExecutionContext executionContext, CallbackArguments args)
        {
            DynValue message = args.AsType(0, "error", DataType.String, false);
            DynValue level   = args.AsType(1, "error", DataType.Number, true);

            Coroutine cor = executionContext.GetCallingCoroutine();

            WatchItem[] stacktrace = cor.GetStackTrace(0, executionContext.CallingLocation);

            var e = new ScriptRuntimeException(message.String);

            if (level.IsNil())
            {
                level = DynValue.NewNumber(1); // Default
            }

            if (level.Number > 0 && level.Number < stacktrace.Length)
            {
                // Lua allows levels up to max. value of a double, while this has to be cast to int
                // Probably never will be a problem, just leaving this note here
                WatchItem wi = stacktrace[(int)level.Number];

                e.DecorateMessage(executionContext.GetScript(), wi.Location);
            }
            else
            {
                e.DoNotDecorateMessage = true;
            }

            throw e;
        }