本文整理汇总了C#中LuaInterface.Lua.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.GetString方法的具体用法?C# Lua.GetString怎么用?C# Lua.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaInterface.Lua
的用法示例。
在下文中一共展示了Lua.GetString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/*
* Sample test script that shows some of the capabilities of
* LuaInterface
*/
public static void Main()
{
Console.WriteLine("Starting interpreter...");
Lua l=new Lua();
Console.WriteLine("Reading test.lua file...");
l.DoFile("test.lua");
double width=l.GetNumber("width");
double height=l.GetNumber("height");
string message=l.GetString("message");
double color_r=l.GetNumber("color.r");
double color_g=l.GetNumber("color.g");
double color_b=l.GetNumber("color.b");
Console.WriteLine("Printing values of global variables width, height and message...");
Console.WriteLine("width: "+width);
Console.WriteLine("height: "+height);
Console.WriteLine("message: "+message);
Console.WriteLine("Printing values of the 'color' table's fields...");
Console.WriteLine("color.r: "+color_r);
Console.WriteLine("color.g: "+color_g);
Console.WriteLine("color.b: "+color_b);
width=150;
Console.WriteLine("Changing width's value and calling Lua function print to show it...");
l["width"]=width;
l.GetFunction("print").Call(width);
message="LuaNet Interface Test";
Console.WriteLine("Changing message's value and calling Lua function print to show it...");
l["message"]=message;
l.GetFunction("print").Call(message);
color_r=30;
color_g=10;
color_b=200;
Console.WriteLine("Changing color's fields' values and calling Lua function print to show it...");
l["color.r"]=color_r;
l["color.g"]=color_g;
l["color.b"]=color_b;
l.DoString("print(color.r,color.g,color.b)");
Console.WriteLine("Printing values of the tree table's fields...");
double leaf1=l.GetNumber("tree.branch1.leaf1");
string leaf2=l.GetString("tree.branch1.leaf2");
string leaf3=l.GetString("tree.leaf3");
Console.WriteLine("leaf1: "+leaf1);
Console.WriteLine("leaf2: "+leaf2);
Console.WriteLine("leaf3: "+leaf3);
leaf1=30; leaf2="new leaf2";
Console.WriteLine("Changing tree's fields' values and calling Lua function print to show it...");
l["tree.branch1.leaf1"]=leaf1; l["tree.branch1.leaf2"]=leaf2;
l.DoString("print(tree.branch1.leaf1,tree.branch1.leaf2)");
Console.WriteLine("Returning values from Lua with 'return'...");
object[] vals=l.DoString("return 2,3");
Console.WriteLine("Returned: "+vals[0]+" and "+vals[1]);
Console.WriteLine("Calling a Lua function that returns multiple values...");
object[] vals1=l.GetFunction("func").Call(2,3);
Console.WriteLine("Returned: "+vals1[0]+" and "+vals1[1]);
Console.WriteLine("Creating a table and filling it from C#...");
l.NewTable("tab");
l.NewTable("tab.tab");
l["tab.a"]="a!";
l["tab.b"]=5.5;
l["tab.tab.c"]=6.5;
l.DoString("print(tab.a,tab.b,tab.tab.c)");
Console.WriteLine("Setting a table as another table's field...");
l["tab.a"]=l["tab.tab"];
l.DoString("print(tab.a.c)");
Console.WriteLine("Registering a C# static method and calling it from Lua...");
// Pause so we can connect with the debugger
// Thread.Sleep(30000);
l.RegisterFunction("func1",null,typeof(TestLuaInterface).GetMethod("func"));
vals1=l.GetFunction("func1").Call(2,3);
Console.WriteLine("Returned: "+vals1[0]);
TestLuaInterface obj=new TestLuaInterface();
Console.WriteLine("Registering a C# instance method and calling it from Lua...");
l.RegisterFunction("func2",obj,typeof(TestLuaInterface).GetMethod("funcInstance"));
vals1=l.GetFunction("func2").Call(2,3);
Console.WriteLine("Returned: "+vals1[0]);
Console.WriteLine("Testing throwing an exception...");
obj.ThrowUncaughtException();
Console.WriteLine("Testing catching an exception...");
obj.ThrowException();
Console.WriteLine("Testing inheriting a method from Lua...");
obj.LuaTableInheritedMethod();
Console.WriteLine("Testing overriding a C# method with Lua...");
obj.LuaTableOverridedMethod();
Console.WriteLine("Stress test RegisterFunction (based on a reported bug)..");
obj.RegisterFunctionStressTest();
Console.WriteLine("Test structures...");
obj.TestStructs();
//.........这里部分代码省略.........
示例2: loadFile
internal void loadFile(String filename)
{
if (string.IsNullOrEmpty(luaFile))
throw new Exception("No Lua file specified");
if (!System.IO.File.Exists(filename))
throw new Exception("Cannot find file " + filename);
// store the file data
this.theData = System.IO.File.ReadAllBytes(filename);
interp = new Lua();
this.usedSetData = false;
#region register predefined functions & variables
// register the functions
interp.RegisterFunction("read", this, this.GetType().GetMethod("read"));
interp.RegisterFunction("read2", this, this.GetType().GetMethod("read2"));
interp.RegisterFunction("readWORD", this, this.GetType().GetMethod("readWORD"));
interp.RegisterFunction("readlWORD", this, this.GetType().GetMethod("readlWORD"));
interp.RegisterFunction("readDWORD", this, this.GetType().GetMethod("readDWORD"));
interp.RegisterFunction("readlDWORD", this, this.GetType().GetMethod("readlDWORD"));
interp.RegisterFunction("readString", this, this.GetType().GetMethod("readString"));
interp.RegisterFunction("readString2", this, this.GetType().GetMethod("readString2"));
interp.RegisterFunction("stringToInt", this, this.GetType().GetMethod("stringToInt"));
interp.RegisterFunction("setData", this, this.GetType().GetMethod("setData"));
interp.RegisterFunction("setData2", this, this.GetType().GetMethod("setData2"));
interp.RegisterFunction("addData", this, this.GetType().GetMethod("addData"));
interp.RegisterFunction("addData2", this, this.GetType().GetMethod("addData2"));
interp.RegisterFunction("toHexadecimal", this, this.GetType().GetMethod("ToHexadecimal"));
// register the default variables
interp["filesize"] = theData.Length;
interp["filename"] = filename.Substring(filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1);
interp["filepath"] = filename.Substring(0, filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1);
#endregion
// read the plugin
try
{
interp.DoFile(this.luaFile);
// if the variable invalid has been set, display it, and reset the data
if (interp["invalid"] != null)
{
MainWindow.ShowError(interp.GetString("invalid"));
this.bData.Data = new byte[0];
}
else
{
#region format
// try to read the format
if (interp["format"] != null)
{
int format = (int)(double)interp["format"];
switch (this.Parent.BindingType)
{
case BindingType.GRAPHICS:
if (format < 1 || format > 7)
MainWindow.ShowError("Plugin warning: the format of the graphics should range from 1 up to and including 7.\n"
+ "Value " + format + " is ignored");
else
GraphicsData.GraphFormat = (GraphicsFormat)format;
break;
case BindingType.PALETTE:
if (format < 5 || format > 7)
MainWindow.ShowError("Plugin warning: the format of the palette should range from 5 up to and including 7.\n"
+ "Value " + format + " is ignored");
else
PaletteData.PalFormat = (PaletteFormat)format;
break;
}
}
#endregion
if (this.parentBinding.BindingType == BindingType.PALETTE || (int)GraphicsData.GraphFormat >= 5)
{
#region palette order
if (interp["order"] != null)
{
string s = ((string)interp["order"]).ToUpper();
if (s.Length != 3 || !s.Contains("R") || !s.Contains("G") || !s.Contains("B"))
MainWindow.ShowError("Plugin warning: the colour order is invalid.\n"
+ "Value " + s + " is ignored.");
else
PaletteData.PalOrder = (PaletteOrder)Enum.Parse(typeof(PaletteOrder), s);
}
#endregion
#region alpha location
if (interp["alphaAtStart"] != null)
{
bool atStart = (bool)interp["alphaAtStart"];
PaletteData.AlphaSettings.Location = atStart ? AlphaLocation.START : AlphaLocation.END;
}
#endregion
#region ignore alpha
if (interp["ignoreAlpha"] != null)
{
//.........这里部分代码省略.........