本文整理汇总了C#中Lua.CompileChunk方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.CompileChunk方法的具体用法?C# Lua.CompileChunk怎么用?C# Lua.CompileChunk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lua
的用法示例。
在下文中一共展示了Lua.CompileChunk方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Exception01
public void Exception01()
{
using (Lua l = new Lua())
{
var g = l.CreateEnvironment();
try
{
g.DoChunk(l.CompileChunk("\nNull(a, a);", "test.lua", LuaDeskop.StackTraceCompileOptions, new KeyValuePair<string, Type>("a", typeof(int))), 1);
}
catch (Exception e)
{
LuaExceptionData d = LuaExceptionData.GetData(e);
Assert.IsTrue(d[2].LineNumber == 2);
}
}
} // proc Exception01
示例2: Button_Click_1
private void Button_Click_1(object sender, RoutedEventArgs e)
{
using (Lua l = new Lua())
{
var t = new LuaTable();
var c = l.CompileChunk(
String.Join(Environment.NewLine,
"local v1 = 2;",
"local v2 = 4;",
"function f()",
" return v1 + v2;",
"end;",
"return f();"), "test", null);
var r = c.Run(t);
txtResult.Text = String.Format("Test: v1=[{0}], v2=[{1}], r={2}", Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 1), Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 2), r.ToInt32());
}
}
示例3: Exception02
public void Exception02()
{
using (Lua l = new Lua())
{
var g = l.CreateEnvironment();
try
{
g.DoChunk(l.CompileChunk("math.abs(-1 / a).A();", "test.lua", LuaDeskop.StackTraceCompileOptions, new KeyValuePair<string, Type>("a", typeof(int))), 1);
}
catch (Exception e)
{
LuaExceptionData d = LuaExceptionData.GetData(e);
Debug.Print("Error: {0}", e.Message);
Debug.Print("Error at:\n{0}", d.StackTrace);
Assert.IsTrue(d[2].LineNumber == 1); // && d[2].ColumnNumber == 18 in release this is one
}
}
} // proc Exception01
示例4: Main
static void Main(string[] args)
{
Console.Write(TestAsync().Result);
using (Lua l = new Lua())
{
var t = new LuaTable();
var c = l.CompileChunk(
String.Join(Environment.NewLine,
"local v1 = 2;",
"local v2 = 4;",
"function f()",
" return v1 + v2;",
"end;",
"return f();"), "test", null);
var r = c.Run(t);
Console.WriteLine("Test: v1=[{0}], v2=[{1}], r={2}", Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 1), Lua.RtGetUpValue(t.GetMemberValue("f") as Delegate, 2), r.ToInt32());
}
//LinqTest2();
Console.ReadKey();
}
示例5: DoScript
private void DoScript(Lua l, LuaGlobal g, string sScript)
{
Type type = typeof(RunLuaTests);
using (Stream src = type.Assembly.GetManifestResourceStream(type, "CompTests." + sScript))
using (StreamReader sr = new StreamReader(src))
{
Console.WriteLine();
Console.WriteLine(new string('=', 60));
Console.WriteLine("= " + sScript);
Console.WriteLine();
try
{
g.DoChunk(l.CompileChunk(sr, sScript, LuaDeskop.StackTraceCompileOptions));
}
catch (Exception e)
{
if (e is LuaException)
Console.WriteLine("Line: {0}, Column: {1}", ((LuaException)e).Line, ((LuaException)e).Column);
Console.WriteLine("StackTrace:");
Console.WriteLine(LuaExceptionData.GetData(e).StackTrace);
throw;
}
}
}
示例6: TestFunctions62
public void TestFunctions62()
{
using (Lua l = new Lua())
{
l.PrintExpressionTree = Console.Out;
dynamic g = l.CreateEnvironment();
var c = l.CompileChunk("print(a)", "dummy", null, new KeyValuePair<string, Type>("a", typeof(object)));
g.dochunk(c, 1);
g.dochunk(c, "a");
}
}
示例7: EventTest05
public void EventTest05()
{
using (Lua l = new Lua())
{
l.PrintExpressionTree = Console.Out;
var g = l.CreateEnvironment();
var c = l.CompileChunk(Lines(
"local a : System.EventHandler = function(a, b) : void",
" print('Hallo');",
"end;",
"a();"), "dummy", null);
g.DoChunk(c);
}
}
示例8: EventTest04
public void EventTest04()
{
using (Lua l = new Lua())
{
var g = l.CreateEnvironment();
var c = l.CompileChunk(Lines(
"local a : System.EventHandler = function(a, b) : void",
" print('Hallo');",
"end;",
"a()"), "dummy", LuaDeskop.StackTraceCompileOptions);
g.DoChunk(c);
}
}
示例9: Create
public bool Create()
{
ScriptEnvironment lastEnvironment = null, oldLastEnvironment = null;
try
{
if (ms_luaState == null)
{
ms_luaState = new Lua();
//ms_luaDebug = new LuaStackTraceDebugger();
ms_luaDebug = null;
if (Resource.Manager.Configuration.ScriptDebug)
{
ms_luaDebug = new LuaStackTraceDebugger();
}
ms_luaCompileOptions = new LuaCompileOptions();
ms_luaCompileOptions.DebugEngine = ms_luaDebug;
ms_initChunks = new []
{
ms_luaState.CompileChunk("system/MessagePack.lua", ms_luaCompileOptions),
ms_luaState.CompileChunk("system/dkjson.lua", ms_luaCompileOptions),
ms_luaState.CompileChunk("system/resource_init.lua", ms_luaCompileOptions)
};
}
m_luaEnvironment = ms_luaState.CreateEnvironment();
foreach (var func in ms_luaFunctions)
{
//m_luaEnvironment[func.Key] = Delegate.CreateDelegate
var parameters = func.Value.GetParameters()
.Select(p => p.ParameterType)
.Concat(new Type[] { func.Value.ReturnType })
.ToArray();
var delegType = Expression.GetDelegateType
(
parameters
);
var deleg = Delegate.CreateDelegate
(
delegType,
null,
func.Value
);
var expParameters = parameters.Take(parameters.Count() - 1).Select(a => Expression.Parameter(a)).ToArray();
var pushedEnvironment = Expression.Variable(typeof(PushedEnvironment));
Expression<Func<PushedEnvironment>> preFunc = () => PushEnvironment(this);
Expression<Action<PushedEnvironment>> postFunc = env => env.PopEnvironment();
Expression body;
if (func.Value.ReturnType.Name != "Void")
{
var retval = Expression.Variable(func.Value.ReturnType);
body = Expression.Block
(
func.Value.ReturnType,
new[] { retval, pushedEnvironment },
Expression.Assign
(
pushedEnvironment,
Expression.Invoke(preFunc)
),
Expression.Assign
(
retval,
Expression.Call(func.Value, expParameters)
),
Expression.Invoke(postFunc, pushedEnvironment),
retval
);
}
else
{
body = Expression.Block
(
func.Value.ReturnType,
new[] { pushedEnvironment },
Expression.Assign
(
pushedEnvironment,
Expression.Invoke(preFunc)
),
Expression.Call(func.Value, expParameters),
//.........这里部分代码省略.........
示例10: CodePlexExample5
public void CodePlexExample5()
{
using (Lua l = new Lua())
{
LuaChunk c = l.CompileChunk("return a;", "test.lua", null);
var g1 = l.CreateEnvironment();
var g2 = l.CreateEnvironment();
g1["a"] = 2;
g2["a"] = 4;
Console.WriteLine((int)(g1.DoChunk(c)[0]) + (int)(g2.DoChunk(c)[0]));
}
}