本文整理汇总了C#中SharpLua.LuaTypes.LuaTable.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# LuaTable.GetValue方法的具体用法?C# LuaTable.GetValue怎么用?C# LuaTable.GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpLua.LuaTypes.LuaTable
的用法示例。
在下文中一共展示了LuaTable.GetValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes the chunk
/// </summary>
/// <param name="enviroment">The environment to run in</param>
/// <param name="isBreak">whether to break execution</param>
/// <returns></returns>
public override LuaValue Execute(LuaTable enviroment, out bool isBreak)
{
LuaTable table = enviroment;
if (this.Name.MethodName == null)
{
for (int i = 0; i < this.Name.FullName.Count - 1; i++)
{
LuaValue obj = enviroment.GetValue(this.Name.FullName[i]);
table = obj as LuaTable;
if (table == null)
{
throw new Exception("Not a table: " + this.Name.FullName[i]);
}
}
table.SetNameValue(
this.Name.FullName[this.Name.FullName.Count - 1],
this.Body.Evaluate(enviroment));
}
else
{
for (int i = 0; i < this.Name.FullName.Count; i++)
{
LuaValue obj = enviroment.GetValue(this.Name.FullName[i]);
if ((obj as LuaClass) != null)
table = (obj as LuaClass).Self;
else
table = obj as LuaTable;
if (table == null)
{
throw new Exception("Not a table: " + this.Name.FullName[i]);
}
}
this.Body.ParamList.NameList.Insert(0, "self");
table.SetNameValue(
this.Name.MethodName,
this.Body.Evaluate(enviroment));
}
isBreak = false;
return null;
}
示例2: PrintTable
private static void PrintTable(LuaTable tbl, string indent, LuaValue _key = null)
{
/* sample output:
table: 002CCBA8
{
field = value
X = 10
y = function: 002CCBA8
}
*/
string i = indent;
A8Console.Write(i);
if (_key != null)
A8Console.Write(_key.ToString() + " = ");
A8Console.WriteLine(tbl.ToString() + "\n" + i + "{");
foreach (LuaValue key in tbl.Keys)
{
LuaValue v = tbl.GetValue(key);
if (v.GetTypeCode() == "table")
{
// check that its not a reference of itself
if (!scanned.ContainsKey(key))
{
scanned.SetKeyValue(key, v);
PrintTable(v as LuaTable, i + " ", key);
}
else
{
A8Console.WriteLine(i + " " + key.ToString() + " = " + v.ToString());
}
}
else
{
scanned.SetKeyValue(key, v);
A8Console.WriteLine(i + " " + key.ToString() + " = " + v.ToString());
}
}/*
foreach (LuaValue key in tbl.MetaTable.Keys)
{
A8Console.WriteLine(i + "(MetaTable): " + key.ToString() + " = " + tbl.MetaTable.GetValue(key).ToString());
}*/
A8Console.WriteLine(i + "}");
}
示例3: REPL
//.........这里部分代码省略.........
#else
GlobalEnvironment.SetNameValue("DEBUG", LuaBoolean.False);
#endif
Prompt = "> ";
// load startup scripts
LoadFiles();
// check command line args
if (args.Length > 0)
{
string file = args[0];
if (File.Exists(file))
{
try
{
GlobalEnvironment.SetNameValue("_WORKDIR", new LuaString(Path.GetDirectoryName(file)));
if (file.EndsWith(".out") || file.EndsWith(".luac") || file.EndsWith(".sluac"))
{
Chunk c = Serializer.Deserialize(file) as Chunk;
c.Enviroment = GlobalEnvironment;
bool isBreak;
c.Execute(GlobalEnvironment, out isBreak).ToString();
}
else
{
LuaRuntime.RunFile(file, GlobalEnvironment);
}
// it loaded successfully
if (args.Length > 1) // possibly interactive mode after
Console.WriteLine("Loaded file '" + Path.GetFileName(file) + "'");
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
//Console.ReadKey(true);
//return;
// instead, go to interactive
}
else
{
Console.WriteLine(file + " not found.");
}
}
// check for interactive mode
foreach (string arg in args)
if (arg.ToUpper() == "-I")
GoInteractive = true;
if (args.Length == 0)
GoInteractive = true;
if (GoInteractive)
{
while (true)
{
Console.Write(Prompt);
string line = Console.ReadLine();
if (line == "quit" || line == "exit" || line == "bye")
{
break;
}
else
{
try
{
LuaValue v = Run(line, GlobalEnvironment);
if (v == null)
Console.WriteLine("=> [no returned value]");
else
Console.WriteLine("=> " + v.ToString());
}
catch (Parser.ParserException error)
{
// create spacing
StringBuilder sb = new StringBuilder();
for (int i = 0; i < Prompt.Length; i++)
sb.Append(" ");
for (int i = 0; i < error.FirstErrorIndex; i++)
sb.Append(" ");
Console.WriteLine(sb.ToString() + "^");
Console.WriteLine("Error: " + error.Message);
GlobalEnvironment.SetNameValue("LASTERROR", ObjectToLua.ToLuaValue(error));
}
catch (Exception error)
{
if (((LuaBoolean)GlobalEnvironment.GetValue(GlobalEnvironment.GetKey("DEBUG"))) == LuaBoolean.True)
Console.WriteLine(error.ToString());
else
Console.WriteLine("Error: " + error.Message);
GlobalEnvironment.SetNameValue("LASTERROR", ObjectToLua.ToLuaValue(error));
}
}
}
}
}
示例4: CreateGlobalEnviroment
/// <summary>
/// Creates a global environment with all the base modules registered and
/// some default values set.
/// </summary>
/// <returns></returns>
public static LuaTable CreateGlobalEnviroment(bool createBaseLib = true,
bool createStringLib = true,
bool createTableLib = true,
bool createOSLib = true,
bool createIOLib = true,
bool createFileLib = true,
bool createMathLib = true,
bool createScriptLib = true,
bool createWinFormsLib = true,
bool createConsoleLib = true,
bool createCoroutineLib = true,
bool createPackageLib = true,
bool createClassLib = true,
bool createFileSystemLib = true)
{
LuaTable global = new LuaTable();
// Register Lua Modules
if (createBaseLib)
BaseLib.RegisterFunctions(global);
if (createStringLib)
StringLib.RegisterModule(global);
if (createTableLib)
TableLib.RegisterModule(global);
if (createIOLib)
IOLib.RegisterModule(global);
if (createFileLib)
FileLib.RegisterModule(global);
if (createMathLib)
MathLib.RegisterModule(global);
if (createOSLib)
OSLib.RegisterModule(global);
if (createScriptLib)
ScriptLib.RegisterModule(global);
if (createWinFormsLib)
WinFormLib.RegisterModule(global);
if (createConsoleLib)
ConsoleLib.RegisterModule(global);
if (createCoroutineLib)
CoroutineLib.RegisterModule(global);
if (createPackageLib)
PackageLib.RegisterModule(global);
if (createClassLib)
ClassLib.RegisterModule(global);
if (createFileSystemLib)
FileSystemLib.RegisterModule(global);
global.SetNameValue("_WORKDIR", new LuaString(Application.StartupPath + "\\"));
global.SetNameValue("_VERSION", new LuaString("Sharp Lua 1.1"));
global.SetNameValue("_G", global);
if (createPackageLib)
{
// set package.preload table
LuaTable preload = (LuaTable) (global.GetValue("package") as LuaTable).GetValue("preload");
if (createStringLib)
preload.SetNameValue("string", (LuaTable) global.GetValue("string"));
if (createTableLib)
preload.SetNameValue("table", (LuaTable) global.GetValue("table"));
if (createIOLib)
preload.SetNameValue("io", (LuaTable) global.GetValue("io"));
if (createFileLib)
preload.SetNameValue("file", (LuaTable) global.GetValue("file"));
if (createMathLib)
preload.SetNameValue("math", (LuaTable) global.GetValue("math"));
if (createOSLib)
preload.SetNameValue("os", (LuaTable) global.GetValue("os"));
if (createScriptLib)
preload.SetNameValue("script", (LuaTable) global.GetValue("script"));
if (createWinFormsLib)
preload.SetNameValue("WinForms", (LuaTable) global.GetValue("WinForms"));
if (createConsoleLib)
preload.SetNameValue("console", (LuaTable) global.GetValue("console"));
if (createCoroutineLib)
preload.SetNameValue("coroutine", (LuaTable) global.GetValue("coroutine"));
if (createPackageLib) // wait a second...
preload.SetNameValue("package", (LuaTable) global.GetValue("package"));
if (createClassLib)
preload.SetNameValue("class", (LuaTable) global.GetValue("class"));
if (createFileSystemLib)
preload.SetNameValue("filesystem", (LuaTable) global.GetValue("filesystem"));
}
if (createFileSystemLib)
FileSystemLib.currentDir = global.GetValue("_WORKDIR").ToString();
GlobalEnvironment = global;
return global;
}
示例5: AddChildControls
private static void AddChildControls(object control, LuaTable table)
{
ToolStrip toolStrip = control as ToolStrip;
if (toolStrip != null)
{
foreach (var item in table.Keys)
{
try {
toolStrip.Items.Add((ToolStripItem)table.GetValue(item).Value);
} catch (Exception) {
}
}
return;
}
SplitContainer splitContainer = control as SplitContainer;
if (splitContainer != null)
{
splitContainer.Panel1.Controls.Add((Control)table.GetValue(1).Value);
splitContainer.Panel2.Controls.Add((Control)table.GetValue(2).Value);
return;
}
Control container = control as Control;
foreach (var item in table.Keys)
{
try {
container.Controls.Add((Control)table.GetValue(item).Value);
} catch (Exception) {
}
}
}
示例6: Evaluate
public override LuaValue Evaluate(LuaTable enviroment)
{
return enviroment.GetValue(this.Name);
}