本文整理汇总了C#中Kecaknoah.Type.KecaknoahObject类的典型用法代码示例。如果您正苦于以下问题:C# KecaknoahObject类的具体用法?C# KecaknoahObject怎么用?C# KecaknoahObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KecaknoahObject类属于Kecaknoah.Type命名空间,在下文中一共展示了KecaknoahObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: ExpressionOperation
protected internal override KecaknoahObject ExpressionOperation(KecaknoahILCodeType op, KecaknoahObject target)
{
if (target.ExtraType == "TimeSpan")
{
var t = ((KecaknoahTimeSpan)target).timespan;
switch (op)
{
case KecaknoahILCodeType.Plus:
return new KecaknoahTimeSpan(timespan + t);
case KecaknoahILCodeType.Minus:
return new KecaknoahTimeSpan(timespan - t);
default:
return KecaknoahNil.Instance;
}
}
else
{
switch (op)
{
case KecaknoahILCodeType.Equal:
return KecaknoahBoolean.False;
case KecaknoahILCodeType.NotEqual:
return KecaknoahBoolean.True;
default:
return KecaknoahNil.Instance;
}
}
}
示例3: 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);
}
}
示例4: 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);
}
示例5: CreateArray
private static KecaknoahFunctionResult CreateArray(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
{
if (args.Length == 0) throw new ArgumentException("次元数が不正です");
if (args.Length >= 5) throw new ArgumentException("次元数が多すぎます");
var dq = args.Select(p => (int)p.ToInt64()).ToArray();
var result = new KecaknoahArray(dq);
return result.NoResume();
}
示例6: GetIndexerReference
/// <summary>
/// インデクサーの参照を得ます。
/// <see cref="GetMemberReference(string)"/>と<see cref="KecaknoahObject.Call(KecaknoahContext, KecaknoahObject[])"/>の
/// 中間のような存在です。
/// </summary>
/// <param name="indices">インデックス</param>
/// <returns>返す参照</returns>
protected internal override KecaknoahReference GetIndexerReference(KecaknoahObject[] indices)
{
if (!dict.ContainsKey(indices[0]))
{
dict[indices[0]] = KecaknoahReference.Left(KecaknoahNil.Instance);
}
return dict[indices[0]];
}
示例7: GetIndexerReference
/// <summary>
/// インデクサーの参照を得ます。
/// <see cref="GetMemberReference(string)"/>と<see cref="KecaknoahObject.Call(KecaknoahContext, KecaknoahObject[])"/>の
/// 中間のような存在です。
/// </summary>
/// <param name="indices">インデックス</param>
/// <returns>返す参照</returns>
protected internal override KecaknoahReference GetIndexerReference(KecaknoahObject[] indices)
{
if (!dict.ContainsKey(indices[0]))
{
dict[indices[0]] = new KecaknoahReference { IsLeftValue = true };
}
return dict[indices[0]];
}
示例8: 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();
}
示例9: 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);
}
示例10: ExpressionOperation
/// <summary>
/// このオブジェクトに対して二項式としての演算をします。
/// </summary>
/// <param name="op">演算子</param>
/// <param name="target">2項目の<see cref="KecaknoahObject"/></param>
/// <returns></returns>
protected internal virtual KecaknoahObject ExpressionOperation(KecaknoahILCodeType op, KecaknoahObject target)
{
switch(op)
{
case KecaknoahILCodeType.Equal:
return Equals(target).AsKecaknoahBoolean();
case KecaknoahILCodeType.NotEqual:
return (!Equals(target)).AsKecaknoahBoolean();
default:
throw new InvalidOperationException($"この{nameof(KecaknoahObject)}に対して式操作は出来ません。");
}
}
示例11: ExpressionOperation
/// <summary>
/// このオブジェクトに対して二項式としての演算をしようとしても大体nilです。
/// </summary>
/// <param name="op">演算子</param>
/// <param name="target">2項目の<see cref="KecaknoahObject"/></param>
/// <returns></returns>
protected internal override KecaknoahObject ExpressionOperation(KecaknoahILCodeType op, KecaknoahObject target)
{
switch (op)
{
case KecaknoahILCodeType.Equal:
return (dynamic)this == (dynamic)target;
case KecaknoahILCodeType.NotEqual:
return (dynamic)this != (dynamic)target;
default:
return KecaknoahNil.Instance;
}
}
示例12: ExpressionOperation
/// <summary>
/// このオブジェクトに対して二項式としての演算をしようとしても大体nilです。
/// </summary>
/// <param name="op">演算子</param>
/// <param name="target">2項目の<see cref="KecaknoahObject"/></param>
/// <returns></returns>
protected internal override KecaknoahObject ExpressionOperation(KecaknoahILCodeType op, KecaknoahObject target)
{
switch (op)
{
case KecaknoahILCodeType.Equal:
return (ExtraType == target.ExtraType).AsKecaknoahBoolean();
case KecaknoahILCodeType.NotEqual:
return (ExtraType != target.ExtraType).AsKecaknoahBoolean();
default:
return Instance;
}
}
示例13: WriteLine
private static KecaknoahFunctionResult WriteLine(KecaknoahContext context, KecaknoahObject self, KecaknoahObject[] args)
{
if (args.Length == 0)
{
Console.WriteLine();
}
else
{
Console.WriteLine(args[0].ToString());
}
return KecaknoahNil.Instance.NoResume();
}
示例14: 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();
}
}
示例15: 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();
}
}