_Samples/Example_Scripting.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Security.Cryptography;
using System.Threading;
//<doc:using>
using ComLib;
using ComLib.Lang;
//</doc:using>
using ComLib.Application;
namespace ComLib.Samples
{
/// <summary>
/// Example for the Scheduling namespace.
/// </summary>
public class Example_Scripting : App
{
/// <summary>
/// Run the application.
/// </summary>
public override BoolMessageItem Execute()
{
//<doc:example>
var i = new Interpreter();
// 1. Execute script and get variable.
i.Execute(" var fullname = 'kishore' + ' reddy';");
string name = i.Memory.Get<string>("fullname");
// 2. Execute script with functions
i.Execute(" function min(a, b) { if(a < b) return a; return b; } var minval = min(2,3);");
double minval = i.Memory.Get<double>("minval");
// 3. Register custom type and execute script.
i.Context.Types.Register(typeof(User), null);
i.Execute("var user = new User('kishore', 'reddy'); var fullname = user.FullName();");
string fullname = i.Memory.Get<string>("fullname");
// 4. Get the result of the script execution.
i.Execute("var list1 = [1,2,3,4,5]; var total = list1[1] + list1[2];");
var total = i.Memory.Get<double>("total");
var result = i.Result;
Console.WriteLine(string.Format("Success: {0}, StartTime: {1}, EndTime: {2}", result.Success, result.StartTime.ToShortTimeString(), result.EndTime.ToShortTimeString()));
// 5. Set limits on the interpreter.
// This set the total number of loops that can be run to 5. ( just as an example ).
// An LimitException occurrs in the interpreter.
i.Context.Settings.MaxLoopLimit = 5;
i.Execute("var count = 0; for(var ndx = 1; ndx <= 6; ndx++) { count = ndx; }");
var count = i.Memory.Get<double>("count");
Console.WriteLine(string.Format("Success: {0}, Message: {1}", i.Result.Success, i.Result.Message));
// 6. Register plugins which extend the syntax and functionality
后面还有 40 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
