public void TestSetGetI() { LuaState L = null; using (L = new LuaState()) { L.CreateTable(0, 0); Assert.Equal(1, L.GetTop()); L.PushString("Value"); L.SetI(1, 2); Assert.Equal(1, L.GetTop()); L.GetI(1, 1); Assert.Equal(2, L.GetTop()); Assert.Equal(true, L.IsNil(-1)); L.GetI(1, 2); Assert.Equal(3, L.GetTop()); Assert.Equal(true, L.IsString(-1)); Assert.Equal("Value", L.ToString(-1)); } }
public void TestNext() { LuaState L = null; using (L = new LuaState()) { L.NewTable(); var t = L.GetTop(); L.PushString("Value A"); L.SetField(t, "a"); L.PushString("Value 2"); L.SetI(t, 2); Assert.Equal(1, L.GetTop()); int count = 0; bool foundA = false; // First Key L.PushNil(); while (L.Next(t)) { count++; // => 'key' at index -2 , 'value' as index -1 if (LuaType.String == L.Type(-2)) { Assert.False(foundA); Assert.Equal(LuaType.String, L.Type(-2)); Assert.Equal("a", L.ToString(-2)); Assert.Equal(LuaType.String, L.Type(-1)); Assert.Equal("Value A", L.ToString(-1)); foundA = true; } else { // Second key Assert.Equal(LuaType.Number, L.Type(-2)); Assert.Equal(2, L.ToInteger(-2)); Assert.Equal(LuaType.String, L.Type(-1)); Assert.Equal("Value 2", L.ToString(-1)); } // Remove 'value' and keep the 'key' on the stack for the next key L.Pop(1); } Assert.Equal(2, count); Assert.True(foundA); // No more key // The stack is cleaned Assert.Equal(1, L.GetTop()); } }