本文整理汇总了C#中LuaState.PushCClosure方法的典型用法代码示例。如果您正苦于以下问题:C# LuaState.PushCClosure方法的具体用法?C# LuaState.PushCClosure怎么用?C# LuaState.PushCClosure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaState
的用法示例。
在下文中一共展示了LuaState.PushCClosure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAtPanic
public void TestAtPanic()
{
LuaState L = null;
using (L = new LuaState())
{
Assert.Throws<ArgumentNullException>(() => L.AtPanic(null));
// Default panic
L.PushCClosure(l => {
L.PushString("Test panic");
L.Error();
return 0;
}, 0);
Exception ex = Assert.Throws<LuaAtPanicException>(() => L.Call(0, 0));
Assert.Equal("Test panic", ex.Message);
// user panic
L.PushCClosure(l => {
L.PushString("Test panic");
L.Error();
return 0;
}, 0);
var old = L.AtPanic(l => {
throw new ApplicationException(String.Format("Panic !! => {0}", l.ToString(-1)));
});
ex = Assert.Throws<ApplicationException>(() => L.Call(0, 0));
Assert.Equal("Panic !! => Test panic", ex.Message);
// Restore
L.AtPanic(old);
// Restore the default
Assert.True(L.RestoreOriginalAtPanic());
Assert.False(L.RestoreOriginalAtPanic());
}
}
示例2: TestPushCClosure
public void TestPushCClosure()
{
LuaState L = null;
using (L = new LuaState())
{
LuaFunction f = l => 0;
L.PushCClosure(f, 0);
Assert.Equal(1, L.GetTop());
Assert.Equal(LuaType.Function, L.Type(-1));
Assert.Same(f, L.ToCFunction(-1));
}
}