本文整理汇总了C#中Table.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Table.Set方法的具体用法?C# Table.Set怎么用?C# Table.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: pack
public static DynValue pack(ScriptExecutionContext executionContext, CallbackArguments args)
{
var t = new Table(executionContext.GetScript());
var v = DynValue.NewTable(t);
for (var i = 0; i < args.Count; i++)
t.Set(i + 1, args[i]);
t.Set("n", DynValue.NewNumber(args.Count));
return v;
}
示例2: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generatorContext, CodeTypeMemberCollection members)
{
string className = "DVAL_" + Guid.NewGuid().ToString("N");
DynValue kval = table.Get("value");
DynValue vtype = table.Get("type");
DynValue vstaticType = table.Get("staticType");
string type = (vtype.Type == DataType.String) ? vtype.String : null;
string staticType = (vstaticType.Type == DataType.String) ? vstaticType.String : null;
CodeTypeDeclaration classCode = new CodeTypeDeclaration(className);
classCode.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate | System.Reflection.TypeAttributes.Sealed;
classCode.BaseTypes.Add(typeof(DynValueMemberDescriptor));
CodeConstructor ctor = new CodeConstructor();
ctor.Attributes = MemberAttributes.Assembly;
classCode.Members.Add(ctor);
if (type == null)
{
Table tbl = new Table(null);
tbl.Set(1, kval);
string str = tbl.Serialize();
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(table.Get("name").String));
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(str));
}
else if (type == "userdata")
{
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(table.Get("name").String));
CodeMemberProperty p = new CodeMemberProperty();
p.Name = "Value";
p.Type = new CodeTypeReference(typeof(DynValue));
p.Attributes = MemberAttributes.Override | MemberAttributes.Public;
p.GetStatements.Add(
new CodeMethodReturnStatement(
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(UserData)),
"CreateStatic", new CodeTypeOfExpression(staticType))));
classCode.Members.Add(p);
}
members.Add(classCode);
return new CodeExpression[] { new CodeObjectCreateExpression(className) };
}
示例3: PrepareForWiring
/// <summary>
/// Prepares the descriptor for hard-wiring.
/// The descriptor fills the passed table with all the needed data for hardwire generators to generate the appropriate code.
/// </summary>
/// <param name="t">The table to be filled</param>
public void PrepareForWiring(Table t)
{
t.Set("class", DynValue.NewString(this.GetType().FullName));
t.Set("name", DynValue.NewString(Name));
t.Set("setter", DynValue.NewBoolean(m_IsSetter));
if (this.Parameters != null)
{
var pars = DynValue.NewPrimeTable();
t.Set("params", pars);
int i = 0;
foreach (var p in Parameters)
{
DynValue pt = DynValue.NewPrimeTable();
pars.Table.Set(++i, pt);
p.PrepareForWiring(pt.Table);
}
}
}
示例4: MoonSharpInit
public static void MoonSharpInit(Table globalTable, Table ioTable)
{
UserData.RegisterType<FileUserDataBase>(InteropAccessMode.Default, "file");
Table meta = new Table(ioTable.OwnerScript);
DynValue __index = DynValue.NewCallback(new CallbackFunction(__index_callback, "__index_callback"));
meta.Set("__index", __index);
ioTable.MetaTable = meta;
SetStandardFile(globalTable.OwnerScript, StandardFileType.StdIn, globalTable.OwnerScript.Options.Stdin);
SetStandardFile(globalTable.OwnerScript, StandardFileType.StdOut, globalTable.OwnerScript.Options.Stdout);
SetStandardFile(globalTable.OwnerScript, StandardFileType.StdErr, globalTable.OwnerScript.Options.Stderr);
}
示例5: PrepareForWiring
/// <summary>
/// Prepares the descriptor for hard-wiring.
/// The descriptor fills the passed table with all the needed data for hardwire generators to generate the appropriate code.
/// </summary>
/// <param name="t">The table to be filled</param>
public void PrepareForWiring(Table t)
{
t.Set("class", DynValue.NewString(this.GetType().FullName));
t.Set("name", DynValue.NewString(this.Name));
switch (Value.Type)
{
case DataType.Nil:
case DataType.Void:
case DataType.Boolean:
case DataType.Number:
case DataType.String:
case DataType.Tuple:
t.Set("value", Value);
break;
case DataType.Table:
if (Value.Table.OwnerScript == null)
{
t.Set("value", Value);
}
else
{
t.Set("error", DynValue.NewString("Wiring of non-prime table value members not supported."));
}
break;
case DataType.UserData:
if (Value.UserData.Object == null)
{
t.Set("type", DynValue.NewString("userdata"));
t.Set("staticType", DynValue.NewString(Value.UserData.Descriptor.Type.FullName));
t.Set("visibility", DynValue.NewString(Value.UserData.Descriptor.Type.GetClrVisibility()));
}
else
{
t.Set("error", DynValue.NewString("Wiring of non-static userdata value members not supported."));
}
break;
default:
t.Set("error", DynValue.NewString(string.Format("Wiring of '{0}' value members not supported.", Value.Type.ToErrorTypeString())));
break;
}
}
示例6: PrepareForWiring
/// <summary>
/// Prepares the descriptor for hard-wiring.
/// The descriptor fills the passed table with all the needed data for hardwire generators to generate the appropriate code.
/// </summary>
/// <param name="t">The table to be filled</param>
public void PrepareForWiring(Table t)
{
t.Set("class", DynValue.NewString(this.GetType().FullName));
t.Set("visibility", DynValue.NewString(this.FieldInfo.GetClrVisibility()));
t.Set("name", DynValue.NewString(this.Name));
t.Set("static", DynValue.NewBoolean(this.IsStatic));
t.Set("const", DynValue.NewBoolean(this.IsConst));
t.Set("readonly", DynValue.NewBoolean(this.IsReadonly));
t.Set("decltype", DynValue.NewString(this.FieldInfo.DeclaringType.FullName));
t.Set("declvtype", DynValue.NewBoolean(Framework.Do.IsValueType(this.FieldInfo.DeclaringType)));
t.Set("type", DynValue.NewString(this.FieldInfo.FieldType.FullName));
t.Set("read", DynValue.NewBoolean(true));
t.Set("write", DynValue.NewBoolean(!(this.IsConst || this.IsReadonly)));
}
示例7: PrepareForWiring
/// <summary>
/// Prepares the descriptor for hard-wiring.
/// The descriptor fills the passed table with all the needed data for hardwire generators to generate the appropriate code.
/// </summary>
/// <param name="t">The table to be filled</param>
public void PrepareForWiring(Table t)
{
t.Set("class", DynValue.NewString(this.GetType().FullName));
t.Set("visibility", DynValue.NewString(this.PropertyInfo.GetClrVisibility()));
t.Set("name", DynValue.NewString(this.Name));
t.Set("static", DynValue.NewBoolean(this.IsStatic));
t.Set("read", DynValue.NewBoolean(this.CanRead));
t.Set("write", DynValue.NewBoolean(this.CanWrite));
t.Set("decltype", DynValue.NewString(this.PropertyInfo.DeclaringType.FullName));
t.Set("declvtype", DynValue.NewBoolean(this.PropertyInfo.DeclaringType.IsValueType));
t.Set("type", DynValue.NewString(this.PropertyInfo.PropertyType.FullName));
}
示例8: Serialize
private void Serialize(Table t, IEnumerable<KeyValuePair<string, IMemberDescriptor>> members)
{
foreach (var pair in members)
{
IWireableDescriptor sd = pair.Value as IWireableDescriptor;
if (sd != null)
{
DynValue mt = DynValue.NewPrimeTable();
t.Set(pair.Key, mt);
sd.PrepareForWiring(mt.Table);
}
else
{
t.Set(pair.Key, DynValue.NewString("unsupported member type : " + pair.Value.GetType().FullName));
}
}
}
示例9: PrepareForWiring
public void PrepareForWiring(Table t)
{
if (AccessMode == InteropAccessMode.HideMembers || Type.Assembly == this.GetType().Assembly)
{
t.Set("skip", DynValue.NewBoolean(true));
}
else
{
t.Set("visibility", DynValue.NewString(this.Type.GetClrVisibility()));
t.Set("class", DynValue.NewString(this.GetType().FullName));
DynValue tm = DynValue.NewPrimeTable();
t.Set("members", tm);
DynValue tmm = DynValue.NewPrimeTable();
t.Set("metamembers", tmm);
Serialize(tm.Table, Members);
Serialize(tmm.Table, MetaMembers);
}
}
示例10: MoonSharpInit
public static void MoonSharpInit(Table globalTable, Table stringTable)
{
var stringMetatable = new Table(globalTable.OwnerScript);
stringMetatable.Set("__index", DynValue.NewTable(stringTable));
globalTable.OwnerScript.SetTypeMetatable(DataType.String, stringMetatable);
}
示例11: PrepareForWiring
/// <summary>
/// Prepares the descriptor for hard-wiring.
/// The descriptor fills the passed table with all the needed data for hardwire generators to generate the appropriate code.
/// </summary>
/// <param name="t">The table to be filled</param>
public void PrepareForWiring(Table table)
{
table.Set("name", DynValue.NewString(Name));
if (Type.IsByRef)
table.Set("type", DynValue.NewString(Type.GetElementType().FullName));
else
table.Set("type", DynValue.NewString(Type.FullName));
if (OriginalType.IsByRef)
table.Set("origtype", DynValue.NewString(OriginalType.GetElementType().FullName));
else
table.Set("origtype", DynValue.NewString(OriginalType.FullName));
table.Set("default", DynValue.NewBoolean(HasDefaultValue));
table.Set("out", DynValue.NewBoolean(IsOut));
table.Set("ref", DynValue.NewBoolean(IsRef));
table.Set("varargs", DynValue.NewBoolean(IsVarArgs));
table.Set("restricted", DynValue.NewBoolean(HasBeenRestricted));
}
示例12: date
public static DynValue date(ScriptExecutionContext executionContext, CallbackArguments args)
{
DateTime reference = DateTime.UtcNow;
DynValue vformat = args.AsType(0, "date", DataType.String, true);
DynValue vtime = args.AsType(1, "date", DataType.Number, true);
string format = (vformat.IsNil()) ? "%c" : vformat.String;
if (vtime.IsNotNil())
reference = FromUnixTime(vtime.Number);
bool isDst = false;
if (format.StartsWith("!"))
{
format = format.Substring(1);
}
else
{
#if !PCL
try
{
reference = TimeZoneInfo.ConvertTimeFromUtc(reference, TimeZoneInfo.Local);
isDst = reference.IsDaylightSavingTime();
}
catch (TimeZoneNotFoundException)
{
// this catches a weird mono bug: https://bugzilla.xamarin.com/show_bug.cgi?id=11817
// however the behavior is definitely not correct. damn.
}
#endif
}
if (format == "*t")
{
Table t = new Table(executionContext.GetScript());
t.Set("year", DynValue.NewNumber(reference.Year));
t.Set("month", DynValue.NewNumber(reference.Month));
t.Set("day", DynValue.NewNumber(reference.Day));
t.Set("hour", DynValue.NewNumber(reference.Hour));
t.Set("min", DynValue.NewNumber(reference.Minute));
t.Set("sec", DynValue.NewNumber(reference.Second));
t.Set("wday", DynValue.NewNumber(((int)reference.DayOfWeek) + 1));
t.Set("yday", DynValue.NewNumber(reference.DayOfYear));
t.Set("isdst", DynValue.NewBoolean(isDst));
return DynValue.NewTable(t);
}
else return DynValue.NewString(StrFTime(format, reference));
}
示例13: DispatchTable
/// <summary>
/// Used by generators to dispatch a single table
/// </summary>
/// <param name="key">The key.</param>
/// <param name="table">The table.</param>
/// <param name="members">The members.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentException">table cannot be dispatched as it has no class or class of invalid type.</exception>
public CodeExpression[] DispatchTable(string key, Table table, CodeTypeMemberCollection members)
{
DynValue d = table.Get("class");
if (d.Type != DataType.String)
throw new ArgumentException("table cannot be dispatched as it has no class or class of invalid type.");
//m_NestStack.Push(string.Format("{0}[{1}]", key, d.String));
m_NestStack.Push((key ?? d.String) ?? "(null)");
table.Set("$key", DynValue.NewString(key));
var gen = HardwireGeneratorRegistry.GetGenerator(d.String);
var result = gen.Generate(table, this, members);
m_NestStack.Pop();
return result;
}
示例14: ParseJsonObject
private static Table ParseJsonObject(Lexer L, Script script)
{
Table t = new Table(script);
L.Next();
while (L.Current.Type != TokenType.Brk_Close_Curly)
{
AssertToken(L, TokenType.String);
string key = L.Current.Text;
L.Next();
AssertToken(L, TokenType.Colon);
L.Next();
DynValue v = ParseJsonValue(L, script);
t.Set(key, v);
L.Next();
if (L.Current.Type == TokenType.Comma)
L.Next();
}
return t;
}
示例15: PrepareForWiring
/// <summary>
/// Prepares the descriptor for hard-wiring.
/// The descriptor fills the passed table with all the needed data for hardwire generators to generate the appropriate code.
/// </summary>
/// <param name="t">The table to be filled</param>
public void PrepareForWiring(Table t)
{
t.Set("class", DynValue.NewString(this.GetType().FullName));
t.Set("type", DynValue.NewString(this.ValueTypeDefaultCtor.FullName));
t.Set("name", DynValue.NewString(this.Name));
}