本文整理汇总了C#中KecaknoahContext类的典型用法代码示例。如果您正苦于以下问题:C# KecaknoahContext类的具体用法?C# KecaknoahContext怎么用?C# KecaknoahContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KecaknoahContext类属于命名空间,在下文中一共展示了KecaknoahContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KecaknoahInstance
/// <summary>
/// 特定の<see cref="KecaknoahScriptClassInfo"/>を元にして、インスタンスを生成します。
/// コンストラクタがあった場合、呼び出します。
/// </summary>
/// <param name="klass">クラス</param>
/// <param name="ctx">コンテキスト</param>
/// <param name="ctorArgs">コンストラクタ引数</param>
public KecaknoahInstance(KecaknoahScriptClassInfo klass, KecaknoahContext ctx, KecaknoahObject[] ctorArgs)
{
Class = klass;
ExtraType = klass.Name;
LocalFieldReferences = localReferences;
InstanceMethodReferences = methodReferences;
foreach (var i in klass.LocalInfos)
{
localReferences[i.Name] = new KecaknoahReference() { IsLeftValue = true };
if (i.InitializeIL != null)
{
localReferences[i.Name].RawObject = ctx.ExecuteExpressionIL(i.InitializeIL);
}
}
foreach (var i in klass.methods)
methodReferences[i.Name] = new KecaknoahReference()
{
IsLeftValue = true,
RawObject = new KecaknoahScriptFunction(this, i)
};
var ctor = klass.classMethods.FirstOrDefault(p => p.Name == "new");
if (ctor != null)
{
new KecaknoahScriptFunction(this, ctor).Call(ctx, ctorArgs);
}
}
示例2: InstanceCreareInstance
private KecaknoahFunctionResult InstanceCreareInstance(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
List<object> ia = new List<object>();
foreach (var i in args)
{
switch (i.Type)
{
case TypeCode.Boolean:
ia.Add(i.ToBoolean());
break;
case TypeCode.Double:
ia.Add(i.ToDouble());
break;
case TypeCode.Int64:
ia.Add(i.ToInt32());
break;
case TypeCode.String:
ia.Add(i.ToString());
break;
case TypeCode.Empty:
ia.Add(null);
break;
default:
var t = i as KecaknoahDynamicLibraryObject;
ia.Add(t != null ? t.rawobj : null);
break;
}
}
var obj = Activator.CreateInstance(type, ia.ToArray());
return new KecaknoahDynamicLibraryObject(obj).NoResume();
}
示例3: Call
/// <summary>
/// 呼び出します。
/// </summary>
/// <param name="context"></param>
/// <param name="args">引数</param>
/// <returns>返り値</returns>
protected internal override KecaknoahFunctionResult Call(KecaknoahContext context, KecaknoahObject[] args)
{
var sf = new KecaknoahStackFrame(context, BaseMethod.Codes);
sf.Locals["self"] = KecaknoahReference.CreateRightReference(Instance);
sf.Arguments = args;
var r = sf.Resume();
return new KecaknoahFunctionResult(sf.ReturningObject, r);
}
示例4: ClassLoadFile
private static KecaknoahFunctionResult ClassLoadFile(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
var name = Path.GetFullPath(args[0].ToString());
var catalog = new DirectoryCatalog(Path.GetDirectoryName(name), Path.GetFileName(name));
var result = new KecaknoahExtensionLibrary();
var container = new CompositionContainer(catalog);
container.ComposeParts(result);
return result.NoResume();
}
示例5: Call
/// <summary>
/// 呼び出します。
/// </summary>
/// <param name="context"></param>
/// <param name="args">引数</param>
/// <returns>返り値</returns>
protected internal override KecaknoahFunctionResult Call(KecaknoahContext context, KecaknoahObject[] args)
{
if (args != null)
{
CurrentFrame = new KecaknoahStackFrame(context, BaseMethod.Codes);
CurrentFrame.Locals["self"] = KecaknoahReference.Right(Instance);
CurrentFrame.Arguments = args;
}
var r = CurrentFrame.Resume();
return new KecaknoahFunctionResult(CurrentFrame.ReturningObject, r);
}
示例6: InstanceGetInteger
private KecaknoahFunctionResult InstanceGetInteger(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
switch (args.Length)
{
case 0:
return random.Next().AsKecaknoahInteger().NoResume();
case 1:
var a = args.ExpectInt32(1, false);
return random.Next(a[0]).AsKecaknoahInteger().NoResume();
default:
var a2 = args.ExpectInt32(2, false);
return random.Next(a2[0], a2[1]).AsKecaknoahInteger().NoResume();
}
}
示例7: ToInteger
private static KecaknoahFunctionResult ToInteger(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
switch (args[0].Type)
{
case TypeCode.Boolean:
return Convert.ToInt64(args[0].ToBoolean()).AsKecaknoahInteger().NoResume();
case TypeCode.Int64:
return args[0].NoResume();
case TypeCode.Double:
return Convert.ToInt64(args[0].ToDouble()).AsKecaknoahInteger().NoResume();
case TypeCode.String:
return Convert.ToInt64(args[0].ToString()).AsKecaknoahInteger().NoResume();
default:
return 0.AsKecaknoahInteger().NoResume();
}
}
示例8: KecaknoahInstance
/// <summary>
/// 特定の<see cref="KecaknoahScriptClassInfo"/>を元にして、インスタンスを生成します。
/// コンストラクタがあった場合、呼び出します。
/// </summary>
/// <param name="klass">クラス</param>
/// <param name="ctx">コンテキスト</param>
/// <param name="ctorArgs">コンストラクタ引数</param>
public KecaknoahInstance(KecaknoahScriptClassInfo klass, KecaknoahContext ctx, KecaknoahObject[] ctorArgs)
{
Class = klass;
LocalFieldReferences = localReferences;
InstanceMethodReferences = methodReferences;
foreach (var i in klass.Locals) localReferences[i] = new KecaknoahReference() { IsLeftValue = true };
foreach (var i in klass.methods)
methodReferences[i.Name] = new KecaknoahReference()
{
IsLeftValue = true,
RawObject = new KecaknoahScriptFunction(this, i)
};
if (klass.classMethods.Any(p => p.Name == "new"))
{
var ctor = klass.classMethods.First(p => p.Name == "new");
new KecaknoahScriptFunction(this, ctor).Call(ctx, ctorArgs);
}
}
示例9: InstanceMatch
private KecaknoahFunctionResult InstanceMatch(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
Match result;
switch (args.Length)
{
case 1:
result = regex.Match(args[0].ToString());
break;
case 2:
result = regex.Match(args[0].ToString(), args[1].ToInt32());
break;
case 3:
result = regex.Match(args[0].ToString(), args[1].ToInt32(), args[2].ToInt32());
break;
default:
result = null;
break;
}
return new KecaknoahMatch(result).NoResume();
}
示例10: InstanceReduce
private KecaknoahFunctionResult InstanceReduce(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
var r = list.Select(p => p.RawObject).Aggregate((p, q) => args[0].Call(ctx, new[] { p, q }).ReturningObject);
return r.NoResume();
}
示例11: InstanceMap
private KecaknoahFunctionResult InstanceMap(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
var r = list.Select(p => args[0].Call(ctx, new[] { p.RawObject }).ReturningObject);
return new KecaknoahList(r).NoResume();
}
示例12: InstanceToLower
private KecaknoahFunctionResult InstanceToLower(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args) => raw.ToLower().AsKecaknoahString().NoResume();
示例13: InstanceEndsWith
private KecaknoahFunctionResult InstanceEndsWith(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args) => raw.EndsWith(args[0].ToString()).AsKecaknoahBoolean().NoResume();
示例14: InstanceReplace
private KecaknoahFunctionResult InstanceReplace(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args) => raw.Replace(args[0].ToString(), args[1].ToString()).AsKecaknoahString().NoResume();
示例15: ClassCosh
private static KecaknoahFunctionResult ClassCosh(KecaknoahContext ctx, KecaknoahObject self, KecaknoahObject[] args)
{
var result = Math.Cosh(args[0].ToDouble());
return result.AsKecaknoahFloat().NoResume();
}