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


C# ScriptContext.AttachGlobal方法代码示例

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


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

示例1: AppScope

 /// <summary>
 /// Constructs a new instance of an <see cref="AppScope"/>.
 /// </summary>
 /// <param name="application">The owner application.</param>
 /// <param name="context">The scripting context for this scope.</param>
 internal AppScope(App application, ScriptContext context)
     : base("app" + application.Key, null, context, context.GetPrototype("Application"))
 {
     context.AttachGlobal("app" + application.Key, this);
 }
开发者ID:mizzunet,项目名称:spike-box,代码行数:10,代码来源:AppScope.cs

示例2: Register


//.........这里部分代码省略.........
            context.CreateType<FileObject>(FileObject.TypeName, (o) => new FileObject(o),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("appendLines", FileObject.AppendLines),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("appendText", FileObject.AppendText),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("appendJson", FileObject.AppendJson),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("writeLines", FileObject.WriteLines),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("writeText", FileObject.WriteText),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("writeJson", FileObject.WriteJson),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("writeBuffer", FileObject.WriteBuffer),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("readLines", FileObject.ReadLines),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("readJson", FileObject.ReadJson),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("readText", FileObject.ReadText),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readBuffer", FileObject.ReadBuffer),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, BoxedValue>("copy", FileObject.Copy),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("move", FileObject.Move),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("replace", FileObject.Replace),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("exists", FileObject.Exists),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("delete", FileObject.Delete)
                );

            // Timer: Delay Call
            context.AttachFunction<FunctionObject, double, BoxedValue, BoxedValue, BoxedValue, ScriptObject>("setTimeout", Native.SetTimeout);
            context.AttachFunction<BoxedValue>("clearTimeout", Native.ClearTimeout);

            // Timer: Interval Call
            context.AttachFunction<FunctionObject, double, BoxedValue, BoxedValue, BoxedValue, ScriptObject>("setInterval", Native.SetInterval);
            context.AttachFunction<BoxedValue>("clearInterval", Native.ClearTimeout);

            // Encoding: Base64
            context.AttachFunction<BoxedValue, BoxedValue>("btoa", Native.BtoA);
            context.AttachFunction<BoxedValue, BoxedValue>("atob", Native.AtoB);

            // Network: Core
            context.AttachFunction<BoxedValue, double, BoxedValue, string, BoxedValue>("transmitEvent", Native.TransmitEvent);
            context.AttachFunction<BoxedValue, BoxedValue, string, BoxedValue>("transmitProperty", Native.TransmitProperty);
            context.AttachFunction<BoxedValue, string, BoxedValue>("transmitConsole", Native.TransmitConsole);

            // Buffer
            context.CreateType<BufferObject, BoxedValue, BoxedValue>("Buffer", (o, param, encoding) => new BufferObject(o, param, encoding),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue, string>("toString", BufferObject.ToString),
                context.CreateFunction<FunctionObject, ScriptObject, string>("toJSON", BufferObject.ToJSON),
                context.CreateFunction<FunctionObject, ScriptObject, string, BoxedValue, BoxedValue, BoxedValue, int>("write", BufferObject.Write),
                context.CreateFunction<FunctionObject, ScriptObject, BufferObject, BoxedValue, BoxedValue, BoxedValue>("copy", BufferObject.Copy),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BufferObject>("slice", BufferObject.Slice),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>("fill", BufferObject.Fill),

                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt8", BufferObject.WriteUInt8),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt8", BufferObject.WriteInt8),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt16BE", BufferObject.WriteUInt16BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt32BE", BufferObject.WriteUInt32BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt64BE", BufferObject.WriteUInt64BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt16BE", BufferObject.WriteInt16BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt32BE", BufferObject.WriteInt32BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt64BE", BufferObject.WriteInt64BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeFloatBE", BufferObject.WriteFloatBE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeDoubleBE", BufferObject.WriteDoubleBE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt16LE", BufferObject.WriteUInt16LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt32LE", BufferObject.WriteUInt32LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeUInt64LE", BufferObject.WriteUInt64LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt16LE", BufferObject.WriteInt16LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt32LE", BufferObject.WriteInt32LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeInt64LE", BufferObject.WriteInt64LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeFloatLE", BufferObject.WriteFloatLE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("writeDoubleLE", BufferObject.WriteDoubleLE),

                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readUInt8", BufferObject.ReadUInt8),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readInt8", BufferObject.ReadInt8),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readUInt16BE", BufferObject.ReadUInt16BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readUInt32BE", BufferObject.ReadUInt32BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readUInt64BE", BufferObject.ReadUInt64BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readInt16BE", BufferObject.ReadInt16BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readInt32BE", BufferObject.ReadInt32BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readInt64BE", BufferObject.ReadInt64BE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readFloatBE", BufferObject.ReadFloatBE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readDoubleBE", BufferObject.ReadDoubleBE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readUInt16LE", BufferObject.ReadUInt16LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readUInt32LE", BufferObject.ReadUInt32LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readUInt64LE", BufferObject.ReadUInt64LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readInt16LE", BufferObject.ReadInt16LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readInt32LE", BufferObject.ReadInt32LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readInt64LE", BufferObject.ReadInt64LE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readFloatLE", BufferObject.ReadFloatLE),
                context.CreateFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue>("readDoubleLE", BufferObject.ReadDoubleLE)
                );

            // Extend Native
            context.AttachFunction<FunctionObject, ScriptObject, ScriptObject, string, ScriptObject>(context.Environment.Prototypes.Object, "defineProperty", Native.DefineProperty);
            context.AttachFunction<FunctionObject, ScriptObject, FunctionObject, BoxedValue>(context.Environment.Prototypes.Array, "forEach", Native.Array_ForEach);
            context.AttachFunction<FunctionObject, ScriptObject, FunctionObject, BoxedValue>(context.Environment.Prototypes.Array, "removeAll", Native.Array_RemoveAll);
            context.AttachFunction<FunctionObject, ScriptObject, FunctionObject, BoxedValue, BoxedValue>(context.Environment.Prototypes.Array, "every", Native.Array_Every);
            context.AttachFunction<FunctionObject, ScriptObject, BoxedValue, BoxedValue, BoxedValue>(context.Environment.Prototypes.Array, "swap", Native.Array_Swap);
            context.AttachFunction<FunctionObject, ScriptObject>(context.Environment.Prototypes.Array, "clear", Native.Array_Clear);

            // Create global instances
            context.AttachGlobal("remote", new RemoteObject(context));
            context.AttachGlobal("console", new ConsoleObject(context));
            context.AttachGlobal("fs", new FileObject(context));

            // Hook the observation
            ScriptObject.PropertyChange += Native.OnPropertyChange;
        }
开发者ID:mizzunet,项目名称:spike-box,代码行数:101,代码来源:Native.cs


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