public void TestCall() { LuaState L = null; using (L = new LuaState()) { L.PushFunction(l => { var a = L.ToNumber(1); var b = L.ToNumber(2); L.PushNumber(a * b); return 1; }); L.PushNumber(12); L.PushNumber(4); L.Call(2, 1); Assert.Equal(1, L.GetTop()); Assert.Equal(48, L.ToNumber(-1)); L.DoString(@" function testA(a,b) return a-b end function testB(a,b) DoAnError(a,b) end "); Assert.Equal(1, L.GetTop()); L.GetGlobal("testA"); L.PushNumber(12); L.PushNumber(4); L.Call(2, 1); Assert.Equal(2, L.GetTop()); Assert.Equal(8, L.ToNumber(-1)); L.GetGlobal("testB"); L.PushNumber(12); L.PushNumber(4); var ex = Assert.Throws<LuaAtPanicException>(() => L.Call(2, 1)); Assert.Equal("[string \"\r...\"]:6: attempt to call a nil value (global 'DoAnError')", ex.Message); } }
public void TestGetStack() { LuaState L = null; using (L = new LuaState()) { L.PushNumber(23); L.PushFunction(l => { var ar = new LuaDebug(); Assert.Throws<NotImplementedException>(() => l.GetStack(0, ar)); //Assert.Equal(0, l.GetStack(0, ar)); //Assert.Equal(0, ar.currentline); return 0; }); L.PCall(0, 0, 0); } }
public void TestGetUpvalue() { LuaState L = null; using (L = new LuaState()) { L.PushNumber(23); L.PushFunction(l => { Assert.Equal(null, l.GetUpvalue(0, 0)); return 0; }); L.PCall(0, 0, 0); } }
public void TestUpvalueJoin() { LuaState L = null; using (L = new LuaState()) { L.PushNumber(23); L.PushFunction(l => { //TODO Do test //l.UpvalueJoin(0, 0, 0, 0); return 0; }); L.PCall(0, 0, 0); } }
public void TestSetHook() { LuaState L = null; using (L = new LuaState()) { LuaHook hook = (ILuaState l, LuaDebug ar) => { }; Assert.Throws<NotImplementedException>(() => L.SetHook(hook, LuaHookMask.MaskCall | LuaHookMask.MaskLine | LuaHookMask.MaskCount, 1)); L.PushNumber(23); L.PushFunction(l => { return 0; }); L.PCall(0, 0, 0); } }
public void TestCallK() { LuaState L = null; using (L = new LuaState()) { L.PushFunction(l => { var a = L.ToNumber(1); var b = L.ToNumber(2); L.PushNumber(a * b); return 1; }); L.PushNumber(12); L.PushNumber(4); Assert.Throws<NotImplementedException>(() => L.CallK(2, 1, 0, null)); } }
public void TestPushFunction() { LuaState L = null; using (L = new LuaState()) { L.PushFunction((l) => { l.PushNumber(12.34); return 0; }); Assert.Equal(1, L.GetTop()); Assert.Equal(LuaType.Function, L.Type(-1)); Assert.Throws<ArgumentNullException>(() => L.PushFunction(null)); } }
public void TestPCall() { LuaState L = null; using (L = new LuaState()) { L.PushFunction(l => { var a = L.ToNumber(1); var b = L.ToNumber(2); L.PushNumber(a * b); return 1; }); L.PushNumber(12); L.PushNumber(4); Assert.Equal(LuaStatus.OK, L.PCall(2, 1, 0)); Assert.Equal(1, L.GetTop()); Assert.Equal(48, L.ToNumber(-1)); L.DoString(@" function testA(a,b) return a-b end function testB(a,b) DoAnError(a,b) end "); Assert.Equal(1, L.GetTop()); L.GetGlobal("testA"); L.PushNumber(12); L.PushNumber(4); Assert.Equal(LuaStatus.OK, L.PCall(2, 1, 0)); Assert.Equal(2, L.GetTop()); Assert.Equal(8, L.ToNumber(-1)); L.GetGlobal("testB"); L.PushNumber(12); L.PushNumber(4); Assert.Equal(LuaStatus.ErrRun, L.PCall(2, 1, 0)); Assert.Equal("[string \"\r...\"]:6: attempt to call a nil value (global 'DoAnError')", L.ToString(-1)); } }