当前位置: 首页>>代码示例>>C#>>正文


C# ScriptExecutionContext.PerformMessageDecorationBeforeUnwind方法代码示例

本文整理汇总了C#中ScriptExecutionContext.PerformMessageDecorationBeforeUnwind方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptExecutionContext.PerformMessageDecorationBeforeUnwind方法的具体用法?C# ScriptExecutionContext.PerformMessageDecorationBeforeUnwind怎么用?C# ScriptExecutionContext.PerformMessageDecorationBeforeUnwind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptExecutionContext的用法示例。


在下文中一共展示了ScriptExecutionContext.PerformMessageDecorationBeforeUnwind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetErrorHandlerStrategy

        private static DynValue SetErrorHandlerStrategy(string funcName,
            ScriptExecutionContext executionContext,
            CallbackArguments args,
            DynValue handlerBeforeUnwind)
        {
            var v = args[0];
            var a = new DynValue[args.Count - 1];

            for (var i = 1; i < args.Count; i++)
                a[i - 1] = args[i];

            if (args[0].Type == DataType.ClrFunction)
            {
                try
                {
                    var ret = args[0].Callback.Invoke(executionContext, a);
                    if (ret.Type == DataType.TailCallRequest)
                    {
                        if (ret.TailCallData.Continuation != null || ret.TailCallData.ErrorHandler != null)
                            throw new ScriptRuntimeException(
                                "the function passed to {0} cannot be called directly by {0}. wrap in a script function instead.",
                                funcName);

                        return DynValue.NewTailCallReq(new TailCallData
                        {
                            Args = ret.TailCallData.Args,
                            Function = ret.TailCallData.Function,
                            Continuation = new CallbackFunction(pcall_continuation, funcName),
                            ErrorHandler = new CallbackFunction(pcall_onerror, funcName),
                            ErrorHandlerBeforeUnwind = handlerBeforeUnwind
                        });
                    }
                    if (ret.Type == DataType.YieldRequest)
                    {
                        throw new ScriptRuntimeException(
                            "the function passed to {0} cannot be called directly by {0}. wrap in a script function instead.",
                            funcName);
                    }
                    return DynValue.NewTupleNested(DynValue.True, ret);
                }
                catch (ScriptRuntimeException ex)
                {
                    executionContext.PerformMessageDecorationBeforeUnwind(handlerBeforeUnwind, ex);
                    return DynValue.NewTupleNested(DynValue.False, DynValue.NewString(ex.DecoratedMessage));
                }
            }
            if (args[0].Type != DataType.Function)
            {
                return DynValue.NewTupleNested(DynValue.False,
                    DynValue.NewString("attempt to " + funcName + " a non-function"));
            }
            return DynValue.NewTailCallReq(new TailCallData
            {
                Args = a,
                Function = v,
                Continuation = new CallbackFunction(pcall_continuation, funcName),
                ErrorHandler = new CallbackFunction(pcall_onerror, funcName),
                ErrorHandlerBeforeUnwind = handlerBeforeUnwind
            });
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:60,代码来源:ErrorHandlingModule.cs


注:本文中的ScriptExecutionContext.PerformMessageDecorationBeforeUnwind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。