本文整理汇总了C#中LuaState.PushString方法的典型用法代码示例。如果您正苦于以下问题:C# LuaState.PushString方法的具体用法?C# LuaState.PushString怎么用?C# LuaState.PushString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaState
的用法示例。
在下文中一共展示了LuaState.PushString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestLen
public void TestLen()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushString("Test")
.PushString("5.6")
.PushString("5D")
.PushString("5z")
;
L.Len(1);
Assert.Equal(4, L.ToNumber(-1));
L.Len(2);
Assert.Equal(3, L.ToNumber(-1));
L.Len(3);
Assert.Equal(2, L.ToNumber(-1));
L.Len(4);
Assert.Equal(2, L.ToNumber(-1));
}
}
示例3: TestGetSetUserValue
public void TestGetSetUserValue()
{
LuaState L = null;
using (L = new LuaState())
{
L.NewTable();
Assert.Equal(15, (int)L.GetUserValue(1));
L.PushString("UserValue");
L.SetUserValue(1);
Assert.Equal(2, L.GetTop());
Assert.Equal(LuaType.String, L.GetUserValue(1));
L.SetTop(0);
var ud = L.NewUserData(12);
Assert.Equal(LuaType.Nil, L.GetUserValue(1));
L.PushString("UserValue");
L.SetUserValue(1);
Assert.Equal(2, L.GetTop());
Assert.Equal(LuaType.String, L.GetUserValue(1));
}
}
示例4: TestInsert
public void TestInsert()
{
LuaState L = null;
using (L = new LuaState())
{
Assert.Equal(0, L.GetTop());
L.PushNumber(1);
L.PushString("Test");
L.PushNumber(2);
L.PushString("Text");
L.PushNumber(3);
L.PushString("Toto");
L.PushNumber(4);
Assert.Equal(7, L.GetTop());
L.Insert(2);
Assert.Equal(7, L.GetTop());
Assert.Equal(1, L.ToNumber(1));
Assert.Equal(4, L.ToNumber(2));
Assert.Equal("Test", L.ToString(3));
Assert.Equal(2, L.ToNumber(4));
Assert.Equal("Text", L.ToString(5));
Assert.Equal(3, L.ToNumber(6));
Assert.Equal("Toto", L.ToString(7));
}
}
示例5: TestXMove
public void TestXMove()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushString("#1 Line 1");
L.PushString("#1 Line 2");
L.PushString("#1 Line 3");
Assert.Equal(3, L.GetTop());
using (LuaState L2 = new LuaState())
{
L2.PushString("#2 Line 1");
L2.PushString("#2 Line 2");
L2.PushString("#2 Line 3");
Assert.Equal(3, L2.GetTop());
Assert.Same(L, L.XMove(L2, 2));
Assert.Equal(1, L.GetTop());
Assert.Equal(5, L2.GetTop());
Assert.Equal("#1 Line 1", L.ToString(1));
Assert.Equal(null, L.ToString(2));
Assert.Equal("#2 Line 1", L2.ToString(1));
Assert.Equal("#2 Line 2", L2.ToString(2));
Assert.Equal("#2 Line 3", L2.ToString(3));
Assert.Equal("#1 Line 2", L2.ToString(4));
Assert.Equal("#1 Line 3", L2.ToString(5));
}
Assert.Throws<ArgumentNullException>(() => L.XMove(null, 1));
var mockLs = new Mock<ILuaState>();
Assert.Throws<InvalidOperationException>(() => L.XMove(mockLs.Object, 1));
}
}
示例6: TestError
public void TestError()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushString("Error message");
var ex = Assert.Throws<LuaAtPanicException>(() => L.Error());
Assert.Equal("Error message", ex.Message);
}
}
示例7: TestSetGetI
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));
}
}
示例8: TestConcat
public void TestConcat()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushString("One");
L.PushNumber(2);
L.PushString("Three");
L.PushNumber(4);
L.Concat(3);
Assert.Equal("2.0Three4.0", L.ToString(-1));
}
}
示例9: TestRawSetGetP
public void TestRawSetGetP()
{
LuaState L = null;
using (L = new LuaState())
{
L.CreateTable(0, 0);
Assert.Equal(1, L.GetTop());
L.PushString("Value");
L.RawSetP(1, new IntPtr(2));
Assert.Equal(1, L.GetTop());
L.RawGetP(1, new IntPtr(1));
Assert.Equal(2, L.GetTop());
Assert.Equal(true, L.IsNil(-1));
L.RawGetP(1, new IntPtr(2));
Assert.Equal(3, L.GetTop());
Assert.Equal(true, L.IsString(-1));
Assert.Equal("Value", L.ToString(-1));
}
}
示例10: TestSetGetGlobal
public void TestSetGetGlobal()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushString("Value A");
L.SetGlobal("a");
Assert.Equal(0, L.GetTop());
L.GetGlobal("a");
Assert.Equal(1, L.GetTop());
Assert.Equal(LuaType.String, L.Type(-1));
L.GetGlobal("b");
Assert.Equal(2, L.GetTop());
Assert.Equal(LuaType.Nil, L.Type(-1));
}
}
示例11: TestPushValue
public void TestPushValue()
{
LuaState L = null;
using (L = new LuaState())
{
Assert.Equal(0, L.GetTop());
L.PushNumber(1);
L.PushString("Test");
L.PushNumber(2);
L.PushString("Text");
Assert.Equal(4, L.GetTop());
L.PushValue(-1).PushValue(2);
Assert.Equal(6, L.GetTop());
Assert.Equal(1, L.ToNumber(1));
Assert.Equal("Test", L.ToString(2));
Assert.Equal(2, L.ToNumber(3));
Assert.Equal("Text", L.ToString(4));
Assert.Equal("Text", L.ToString(5));
Assert.Equal("Test", L.ToString(6));
}
}
示例12: TestPushString
public void TestPushString()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushString("Text");
Assert.Equal(1, L.GetTop());
Assert.Equal(LuaType.String, L.Type(-1));
}
}
示例13: TestPop
public void TestPop()
{
LuaState L = null;
using (L = new LuaState())
{
L.PushNumber(1);
L.PushString("Text");
L.PushNumber(2);
L.PushString("Text");
Assert.Equal(4, L.GetTop());
L.Pop(2);
Assert.Equal(2, L.GetTop());
L.Pop(1);
Assert.Equal(1, L.GetTop());
L.Pop(2);
Assert.Equal(-1, L.GetTop());
}
}
示例14: 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());
}
}
示例15: Main
static void Main(string[] args)
{
TestGC();
Class1 cl1 = new Class1();
LuaState state = new LuaState(true);
state.GetGlobals().Register("MyCallback", new LuaPlusCallback(MyCallback));
state.DoString("MyVar = 5");
// System.Reflection.MethodInfo info = typeof(Class1).GetMethod("Func2");
// state.GetGlobals().Register("Func", null, typeof(Class1).GetMethod("Func")); //typeof(Class1).GetMethod("Func"));
// state.DoString("Func(5)");
LuaObject obj = state.GetGlobal("MyVar");
state.DoString("MyCallback('Hello')");
LuaObject funcObj = state.GetGlobal("print");
// funcObj.Call("Stuff", 0);
try
{
// state.DoString( "print('Hello, world!')" );
}
catch (Exception e)
{
}
state.DoString("MyTable = { 1, 2, [3] = { \"Hi\" } }");
double num = obj.GetNumber();
LuaObject obj3 = state.GetGlobals()["MyTable"];
String s = obj3.TypeName();
LuaObject obj2 = new LuaObject(obj);
obj2.AssignWString(state, "Yo baby!");
state.DoString("MyTable = { 1, 2, 3, A = 5, 4 }");
foreach (LuaNode node in state.Globals["MyTable"])
{
Console.WriteLine(node);
}
try
{
LuaObject globObj = state.Globals["MyTable"][1][2];
}
catch (LuaException e)
{
int hi = 5;
}
{
state.DoString("require 'glob'");
state.DoString("return glob.match('**')");
LuaObject filesObj = new LuaObject(state, -1);
foreach (LuaNode node in filesObj)
{
Console.WriteLine(node.Value.GetString());
}
}
{
LuaObject globObj = state.GetGlobal("glob");
LuaObject matchObj = globObj["match"];
matchObj.Push();
state.PushString("**");
state.PCall(1, 1, 0);
LuaObject filesObj = new LuaObject(state, -1);
foreach (LuaNode node in filesObj)
{
Console.WriteLine(node.Value.GetString());
}
}
System.IO.FileStream fileStream = new System.IO.FileStream("Out.lua", FileMode.Create);
LuaStateStreamOutFile outFile = new LuaStateStreamOutFile(fileStream);
state.DumpObject(outFile, "MyTable", state.Globals["MyTable"]);
TestIOX();
}