本文整理汇总了C#中SharpLua.LuaTypes.LuaTable.SetNameValue方法的典型用法代码示例。如果您正苦于以下问题:C# LuaTable.SetNameValue方法的具体用法?C# LuaTable.SetNameValue怎么用?C# LuaTable.SetNameValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpLua.LuaTypes.LuaTable
的用法示例。
在下文中一共展示了LuaTable.SetNameValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterFunctions
public static void RegisterFunctions(LuaTable module)
{
module.SetNameValue("huge", new LuaNumber(double.MaxValue));
module.SetNameValue("pi", new LuaNumber(Math.PI));
module.Register("abs", Abs);
module.Register("acos", Acos);
module.Register("asin", Asin);
module.Register("atan", Atan);
module.Register("atan2", Atan2);
module.Register("ceil", Ceil);
module.Register("cos", Cos);
module.Register("cosh", Cosh);
module.Register("deg", Deg);
module.Register("exp", Exp);
module.Register("floor", Floor);
module.Register("fmod", Fmod);
module.Register("log", Log);
module.Register("log10", Log10);
module.Register("max", Max);
module.Register("min", Min);
module.Register("modf", ModF);
module.Register("pow", Pow);
module.Register("rad", Rad);
module.Register("random", Random);
module.Register("randomseed", RandomSeed);
module.Register("sin", Sin);
module.Register("sinh", SinH);
module.Register("sqrt", Sqrt);
module.Register("tan", Tan);
module.Register("tanh", TanH);
}
示例2: Date
public static LuaValue Date(LuaValue[] values)
{
LuaString format = null;
if (values.Length > 0)
format = values[0] as LuaString;
if (format != null)
{
if (format.Text == "*t")
{
LuaTable table = new LuaTable();
DateTime now = DateTime.Now;
table.SetNameValue("year", new LuaNumber (now.Year));
table.SetNameValue("month", new LuaNumber (now.Month ));
table.SetNameValue("day", new LuaNumber (now.Day));
table.SetNameValue("hour", new LuaNumber (now.Hour));
table.SetNameValue("min", new LuaNumber (now.Minute));
table.SetNameValue("sec", new LuaNumber (now.Second));
table.SetNameValue("wday", new LuaNumber ((int)now.DayOfWeek));
table.SetNameValue("yday", new LuaNumber (now.DayOfYear));
table.SetNameValue("isdst", LuaBoolean.From(now.IsDaylightSavingTime()));
}
else
{
return new LuaString(DateTime.Now.ToString(format.Text));
}
}
return new LuaString(DateTime.Now.ToShortDateString());
}
示例3: Execute
/// <summary>
/// Executes the chunk
/// </summary>
/// <param name="enviroment">Runs in the given environment</param>
/// <param name="isBreak">whether to break execution</param>
/// <returns></returns>
public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
{
LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);
if (neatValues.Length < 3) //probably LuaUserdata. Literal will also fail...
{
return ExecuteAlternative(enviroment, out isBreak);
}
LuaFunction func = neatValues[0] as LuaFunction;
LuaValue state = neatValues[1];
LuaValue loopVar = neatValues[2];
var table = new LuaTable(enviroment);
this.Body.Enviroment = table;
while (true)
{
LuaValue result = func.Invoke(new LuaValue[] { state, loopVar });
LuaMultiValue multiValue = result as LuaMultiValue;
if (multiValue != null)
{
neatValues = LuaMultiValue.UnWrapLuaValues(multiValue.Values);
loopVar = neatValues[0];
for (int i = 0; i < Math.Min(this.NameList.Count, neatValues.Length); i++)
{
table.SetNameValue(this.NameList[i], neatValues[i]);
}
}
else
{
loopVar = result;
table.SetNameValue(this.NameList[0], result);
}
if (loopVar == LuaNil.Nil)
{
break;
}
var returnValue = this.Body.Execute(out isBreak);
if (returnValue != null || isBreak == true)
{
isBreak = false;
return returnValue;
}
}
isBreak = false;
return null;
}
示例4: Execute
/// <summary>
/// Executes the chunk
/// </summary>
/// <param name="enviroment">Runs in the given environment</param>
/// <param name="isBreak">whether to break execution</param>
/// <returns></returns>
public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
{
LuaNumber start = this.Start.Evaluate(enviroment) as LuaNumber;
LuaNumber end = this.End.Evaluate(enviroment) as LuaNumber;
double step = 1;
if (this.Step != null)
{
step = (this.Step.Evaluate(enviroment) as LuaNumber).Number;
}
var table = new LuaTable(enviroment);
table.SetNameValue(this.VarName, start);
this.Body.Enviroment = table;
while (step > 0 && start.Number <= end.Number ||
step <= 0 && start.Number >= end.Number)
{
var returnValue = this.Body.Execute(out isBreak);
if (returnValue != null || isBreak == true)
{
isBreak = false;
return returnValue;
}
start.Number += step;
}
isBreak = false;
return null;
}
示例5: Evaluate
public override LuaValue Evaluate(LuaTable enviroment)
{
LuaTable table = new LuaTable();
foreach (Field field in this.FieldList)
{
NameValue nameValue = field as NameValue;
if (nameValue != null)
{
table.SetNameValue(nameValue.Name, nameValue.Value.Evaluate(enviroment));
continue;
}
KeyValue keyValue = field as KeyValue;
if (keyValue != null)
{
table.SetKeyValue(
keyValue.Key.Evaluate(enviroment),
keyValue.Value.Evaluate(enviroment));
continue;
}
ItemValue itemValue = field as ItemValue;
if (itemValue != null)
{
table.AddValue(itemValue.Value.Evaluate(enviroment));
continue;
}
}
return table;
}
示例6: CreateMetaTable
public static LuaTable CreateMetaTable()
{
LuaTable metatable = new LuaTable();
RegisterFunctions(metatable);
metatable.SetNameValue("__index", metatable);
return metatable;
}
示例7: RegisterModule
public static void RegisterModule(LuaTable enviroment)
{
LuaTable module = new LuaTable();
RegisterFunctions(module);
enviroment.SetNameValue("WinForms", module);
module.SetNameValue("_G", enviroment);
currentModule = module;
}
示例8: Evaluate
public LuaValue Evaluate(LuaTable enviroment)
{
return new LuaFunction(
new LuaFunc(delegate(LuaValue[] args)
{
var table = new LuaTable(enviroment);
List<string> names = this.ParamList.NameList;
if (names.Count > 0)
{
int argCount = Math.Min(names.Count, args.Length);
for (int i = 0; i < argCount; i++)
{
table.SetNameValue(names[i], args[i]);
}
if (this.ParamList.HasVarArg)
{
if (argCount < args.Length)
{
LuaValue[] remainedArgs = new LuaValue[args.Length - argCount];
for (int i = 0; i < remainedArgs.Length; i++)
{
remainedArgs[i] = args[argCount + i];
}
table.SetNameValue("...", new LuaMultiValue(remainedArgs));
table.SetNameValue("arg", new LuaMultiValue(remainedArgs));
}
}
}
else if (this.ParamList.IsVarArg != null)
{
table.SetNameValue("...", new LuaMultiValue(args));
}
this.Chunk.Enviroment = table;
return this.Chunk.Execute();
})
);
}
示例9: GetControlMetaTable
public static LuaTable GetControlMetaTable()
{
if (controlMetaTable == null)
{
controlMetaTable = new LuaTable();
controlMetaTable.SetNameValue("__index", new LuaFunction((values) =>
{
LuaUserdata control = values[0] as LuaUserdata;
Type type = control.Value.GetType();
LuaString member = values[1] as LuaString;
if (member != null)
{
return GetMemberValue(control.Value, type, member.Text);
}
LuaNumber index = values[1] as LuaNumber;
if (index != null)
{
return GetIndexerValue(control.Value, type, index.Number);
}
return LuaNil.Nil;
}));
controlMetaTable.SetNameValue("__newindex", new LuaFunction((values) =>
{
LuaUserdata control = values[0] as LuaUserdata;
LuaString member = values[1] as LuaString;
LuaValue value = values[2];
Type type = control.Value.GetType();
SetMemberValue(control.Value, type, member.Text, value.Value);
return null;
}));
}
return controlMetaTable;
}
示例10: Attributes
public static LuaValue Attributes(LuaValue[] args)
{
string fn = args[0].ToString();
LuaTable ret = new LuaTable();
FileInfo f = new FileInfo(fn);
ret.SetNameValue("filename", new LuaString(fn));
ret.SetNameValue("dir", new LuaString(f.DirectoryName));
ret.SetNameValue("drive", new LuaString(Path.GetPathRoot(f.DirectoryName)));
ret.SetNameValue("attributes", new LuaString(f.Attributes.ToString()));
ret.SetNameValue("access", new LuaString(f.LastAccessTime.ToString()));
ret.SetNameValue("modification", new LuaString(f.LastWriteTime.ToString()));
ret.SetNameValue("ext", new LuaString(f.Extension));
ret.SetNameValue("size", new LuaString(f.Length.ToString()));
return ret;
}
示例11: MechJebModuleAutom8
public MechJebModuleAutom8(MechJebCore core)
: base(core)
{
instance = this;
luaEnv = LuaRuntime.CreateGlobalEnviroment();
mechjeb = new LuaTable();
core.registerLuaMembers(mechjeb);
luaEnv.SetNameValue("mechjeb", mechjeb);
luaEnv.SetNameValue("vessel", ObjectToLua.ToLuaValue(vesselState));
if (KSP.IO.File.Exists<MuMechJeb>("autorun.lua"))
{
try
{
LuaRuntime.GlobalEnvironment = luaEnv;
LuaRuntime.RunFile("autorun.lua", luaEnv);
}
catch (Exception e)
{
A8Console.WriteLine(e.GetType().Name + ": " + e.Message);
luaEnv.SetNameValue("lastError", ObjectToLua.ToLuaValue(e));
}
}
}
示例12: registerLuaMembers
public void registerLuaMembers(LuaTable index)
{
index.Register("getModule", proxyGetModule);
index.Register("controlClaim", proxyControlClaim);
index.Register("controlRelease", proxyControlRelease);
index.Register("attitudeGetReferenceRotation", proxyAttitudeGetReferenceRotation);
index.Register("attitudeWorldToReference", proxyAttitudeWorldToReference);
index.Register("attitudeReferenceToWorld", proxyAttitudeReferenceToWorld);
index.Register("attitudeTo", proxyAttitudeTo);
index.Register("attitudeDeactivate", proxyAttitudeDeactivate);
index.Register("attitudeAngleFromTarget", proxyAttitudeAngleFromTarget);
index.Register("distanceFromTarget", proxyDistanceFromTarget);
index.Register("relativeVelocityToTarget", proxyRelativeVelocityToTarget);
index.Register("targetName", proxyTargetName);
//index.Register("setTarget", proxySetTarget);
index.Register("landActivate", proxyLandActivate);
index.Register("landDeactivate", proxyLandDeactivate);
index.Register("thrustActivate", proxyThrustActivate);
index.Register("thrustDeactivate", proxyThrustDeactivate);
index.Register("warpIncrease", proxyWarpIncrease);
index.Register("warpDecrease", proxyWarpDecrease);
index.Register("warpMinimum", proxyWarpMinimum);
index.Register("warpPhysics", proxyWarpPhysics);
index.Register("autoStageActivate", proxyAutoStageActivate);
index.Register("autoStageDeactivate", proxyAutoStageDeactivate);
index.Register("launch", proxyLaunch);
index.Register("stage", proxyStage);
index.Register("getAttitudeActive", proxyGetAttitudeActive);
index.Register("getControlClaimed", proxyGetControlClaimed);
index.Register("busy", proxyBusy);
index.Register("free", proxyFree);
index.SetNameValue("core", ObjectToLua.ToLuaValue(this));
foreach (ComputerModule m in modules)
{
m.registerLuaMembers(index);
}
}
示例13: ExecuteAlternative
private LuaValue ExecuteAlternative(LuaTable enviroment, out bool isBreak)
{
LuaValue returnValue;
LuaValue[] values = this.ExprList.ConvertAll(expr => expr.Evaluate(enviroment)).ToArray();
LuaValue[] neatValues = LuaMultiValue.UnWrapLuaValues(values);
LuaValue state = neatValues[0];
LuaTable table = new LuaTable(enviroment);
this.Body.Enviroment = table;
System.Collections.IDictionary dict = state.Value as System.Collections.IDictionary;
System.Collections.IEnumerable ie = state.Value as System.Collections.IEnumerable;
if (dict != null)
{
foreach (object key in dict.Keys)
{
//for (int i = 0; i < this.NameList.Count; i++)
//{
//table.SetNameValue(this.NameList[i], ObjectToLua.ToLuaValue(key));
//}
table.SetNameValue(this.NameList[0], ObjectToLua.ToLuaValue(key));
table.SetNameValue(this.NameList[1], ObjectToLua.ToLuaValue(dict[key]));
returnValue = this.Body.Execute(out isBreak);
if (returnValue != null || isBreak == true)
{
isBreak = false;
return returnValue;
}
}
}
else if (ie != null)
{
foreach (object obj in ie)
{
for (int i = 0; i < this.NameList.Count; i++)
{
table.SetNameValue(this.NameList[i], ObjectToLua.ToLuaValue(obj));
}
returnValue = this.Body.Execute(out isBreak);
if (returnValue != null || isBreak == true)
{
isBreak = false;
return returnValue;
}
}
}
else
{
// its some other value...
for (int i = 0; i < this.NameList.Count; i++)
{
table.SetNameValue(this.NameList[i], ObjectToLua.ToLuaValue(state.Value));
}
returnValue = this.Body.Execute(out isBreak);
if (returnValue != null || isBreak == true)
{
isBreak = false;
return returnValue;
}
isBreak = false;
return null;
}
isBreak = false;
return null;
}
示例14: RegisterModule
public static void RegisterModule(LuaTable env)
{
LuaTable module = new LuaTable();
RegisterFunctions(module);
env.SetNameValue("filesystem", module); // TODO: better name
}
示例15: RegisterModule
public static void RegisterModule(LuaTable env)
{
LuaTable module = new LuaTable();
RegisterFunctions(module);
env.SetNameValue("class", module);
}