本文整理汇总了C#中LuaState.ToInteger方法的典型用法代码示例。如果您正苦于以下问题:C# LuaState.ToInteger方法的具体用法?C# LuaState.ToInteger怎么用?C# LuaState.ToInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaState
的用法示例。
在下文中一共展示了LuaState.ToInteger方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCreateTable
public void TestCreateTable()
{
LuaState L = null;
using (L = new LuaState())
{
L.CreateTable(0, 0);
Assert.Equal(1, L.GetTop());
Assert.Equal(LuaType.Table, L.Type(-1));
L.Len(-1);
Assert.Equal(0, L.ToInteger(-1));
L.CreateTable(3, 7);
Assert.Equal(3, L.GetTop());
Assert.Equal(LuaType.Table, L.Type(-1));
L.Len(-1);
Assert.Equal(0, L.ToInteger(-1));
}
}
示例2: TestToInteger
public void TestToInteger()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushNil()
.PushNumber(123.45)
.PushInteger(987)
.PushString("Test")
.PushString("5.6")
.PushString("5D")
.PushString("5z")
.PushBoolean(true)
.PushCClosure(l => 0, 0)
//.PushLightUserData(DateTime.Now)
.PushGlobalTable()
;
bool isnum;
Assert.Equal(0, L.ToInteger(1));
Assert.Equal(0, L.ToInteger(1, out isnum));
Assert.Equal(false, isnum);
Assert.Equal(0, L.ToInteger(2));
Assert.Equal(0, L.ToInteger(2, out isnum));
Assert.Equal(false, isnum);
Assert.Equal(987, L.ToInteger(3));
Assert.Equal(987, L.ToInteger(3, out isnum));
Assert.Equal(true, isnum);
Assert.Equal(0, L.ToInteger(4));
Assert.Equal(0, L.ToInteger(4, out isnum));
Assert.Equal(false, isnum);
Assert.Equal(0, L.ToInteger(5));
Assert.Equal(0, L.ToInteger(6));
Assert.Equal(0, L.ToInteger(7));
Assert.Equal(0, L.ToInteger(8));
Assert.Equal(0, L.ToInteger(9));
Assert.Equal(0, L.ToInteger(10));
Assert.Equal(0, L.ToInteger(11));
Assert.Equal(0, L.ToInteger(12));
}
}
示例3: TestPushInteger
public void TestPushInteger()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushInteger(1234);
Assert.Equal(1, L.GetTop());
Assert.Equal(LuaType.Number, L.Type(-1));
Assert.Equal(1234, L.ToInteger(-1));
}
}
示例4: TestPushUnsigned
public void TestPushUnsigned()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushUnsigned(23);
Assert.Equal(23, L.ToInteger(-1));
}
}
示例5: TestNext
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());
}
}