本文整理汇总了C#中Lua.DoString方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.DoString方法的具体用法?C# Lua.DoString怎么用?C# Lua.DoString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lua
的用法示例。
在下文中一共展示了Lua.DoString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AccessObjectProperty
public void AccessObjectProperty()
{
using (Lua lua = new Lua())
{
TestClass t1 = new TestClass();
t1.testval = 4;
lua["netobj"] = t1;
lua.DoString("var=netobj.testval");
double var = (double)lua["var"];
//Console.WriteLine("value from Lua="+var);
Assert.Equal(4, var);
lua.DoString("netobj.testval=3");
Assert.Equal(3, t1.testval);
//Console.WriteLine("new val (from Lua)="+t1.testval);
}
}
示例2: CallGlobalFunctionOneArg
public void CallGlobalFunctionOneArg()
{
using (Lua lua = new Lua())
{
lua.DoString("a=2\nfunction f(x)\na=a+x\nend");
lua.GetFunction("f").Call(1);
double num = lua.GetNumber("a");
//Console.WriteLine("a="+num);
Assert.Equal(num, 3d);
}
}
示例3: TestRemoting
public void TestRemoting()
{
using( Lua remoting1 = new Lua( ) )
using( Lua remoting2 = new Lua( ) )
{
remoting1["remote"] = RemoteFunction.Instance;
LookupTable<string, Lua>.Store( "TestRemoting1", remoting1 );
LookupTable<string, Lua>.Store( "TestRemoting2", remoting2 );
remoting1.DoString( LuaScripts.GetScriptString( "TestRemoting1" ) );
remoting2.DoString( LuaScripts.GetScriptString( "TestRemoting2" ) );
AssertOutput( remoting2, "Execute", "TestRemoting1: Value 2\nValue 1" );
}
}
示例4: Ensure_That_CLR_Errors_Are_Received
public void Ensure_That_CLR_Errors_Are_Received( )
{
using( Lua err = new Lua( ) )
{
err["throwClrException"] = ThrowClrException.Instance;
err.DoString( LuaScripts.GetScriptString( "TestExecution" ) );
try
{
((LuaFunction)err["ExecuteClr"]).Call( );
Assert.Fail( "Test CLR Errors: error not received." );
}
catch
{
// Assert.Pass
}
}
}
示例5: Main
public static void Main(string[] args)
{
Lua lua = new Lua();
lua.DynamicContext.print = (LuaFunction)print;
lua.DynamicContext.read = (LuaFunction)read;
while (true)
{
string line = Console.ReadLine();
try
{
lua.DoString(line);
}
catch (LuaException ex)
{
for (int i = 0; i < ex.col - 1; i++)
Console.Write(" ");
Console.WriteLine("^");
Console.WriteLine(ex.message);
}
}
}
示例6: CallTableFunctionTwoReturns
public void CallTableFunctionTwoReturns()
{
using (Lua lua = new Lua())
{
lua.DoString("a={}\nfunction a.f(x,y)\nreturn x,x+y\nend");
object[] ret = lua.GetFunction("a.f").Call(3, 2);
//Console.WriteLine("ret="+ret[0]+","+ret[1]);
Assert.Equal(2, ret.Length);
Assert.Equal(3, (double)ret[0]);
Assert.Equal(5, (double)ret[1]);
}
}
示例7: LuaInterfaceValueProperty
public void LuaInterfaceValueProperty()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('LuaInterface.Test')");
lua.DoString("TestClass=luanet.import_type('LuaInterface.Test.Mock.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("itest={}");
lua.DoString("function itest:get_intProp() return itest.int_prop; end");
lua.DoString("function itest:set_intProp(val) itest.int_prop=val; end");
lua.DoString("a=test:callInterface8(itest)");
int a = (int)lua.GetNumber("a");
Assert.Equal(3, a);
//Console.WriteLine("interface returned: "+a);
}
}
示例8: CreateNetObjectOverloadedCons
public void CreateNetObjectOverloadedCons()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly(\"LuaInterface.Test\")");
lua.DoString("TestClass=luanet.import_type(\"LuaInterface.Test.Mock.TestClass\")");
lua.DoString("test=TestClass('str')");
object[] res = lua.DoString("return test");
TestClass test = (TestClass)res[0];
//Console.WriteLine("returned: "+test.getStrVal());
Assert.Equal("str", test.getStrVal());
}
}
示例9: LuaDelegateValueTypesByRefParam
public void LuaDelegateValueTypesByRefParam()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('LuaInterface.Test')");
lua.DoString("TestClass=luanet.import_type('LuaInterface.Test.Mock.TestClass')");
lua.DoString("test=TestClass()");
lua.DoString("function func(x,y) return x+y; end");
lua.DoString("test=TestClass()");
lua.DoString("a=test:callDelegate3(func)");
int a = (int)lua.GetNumber("a");
Assert.Equal(5, a);
//Console.WriteLine("delegate returned: "+a);
}
}
示例10: LuaTableInheritedMethod
public void LuaTableInheritedMethod()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('LuaInterface.Test')");
lua.DoString("TestClass=luanet.import_type('LuaInterface.Test.Mock.TestClass')");
lua.DoString("test={}");
lua.DoString("function test:overridableMethod(x,y) return x*y; end");
lua.DoString("luanet.make_object(test,'LuaInterface.Test.Mock.TestClass')");
lua.DoString("test:setVal(3)");
lua.DoString("a=test.testval");
int a = (int)lua.GetNumber("a");
lua.DoString("luanet.free_object(test)");
Assert.Equal(3, a);
//Console.WriteLine("interface returned: "+a);
}
}
示例11: CallObjectMethodOverloadedOutParam
public void CallObjectMethodOverloadedOutParam()
{
using (Lua lua = new Lua())
{
TestClass t1 = new TestClass();
lua["netobj"] = t1;
lua.DoString("a,b=netobj:outVal(2)");
int a = (int)lua.GetNumber("a");
int b = (int)lua.GetNumber("b");
Assert.Equal(2, a);
Assert.Equal(5, b);
//Console.WriteLine("function returned (from lua)="+a+","+b);
}
}
示例12: GetNumberInTable
public void GetNumberInTable()
{
using (Lua lua = new Lua())
{
lua.DoString("a={b={c=2}}");
double num = lua.GetNumber("a.b.c");
//Console.WriteLine("a.b.c="+num);
Assert.Equal(num, 2d);
}
}
示例13: LuaTableBaseMethod
public void LuaTableBaseMethod()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly('LuaInterface.Test')");
lua.DoString("TestClass=luanet.import_type('LuaInterface.Test.Mock.TestClass')");
lua.DoString("test={}");
lua.DoString("function test:overridableMethod(x,y) return 2*self.base:overridableMethod(x,y); end");
lua.DoString("luanet.make_object(test,'LuaInterface.Test.Mock.TestClass')");
lua.DoString("a=TestClass:callOverridable(test,2,3)");
int a = (int)lua.GetNumber("a");
lua.DoString("luanet.free_object(test)");
Assert.Equal(10, a);
//Console.WriteLine("interface returned: "+a);
}
}
示例14: GetGlobalString
public void GetGlobalString()
{
using (Lua lua = new Lua())
{
lua.DoString("a=\"test\"");
string str = lua.GetString("a");
//Console.WriteLine("a="+str);
Assert.Equal(str, "test");
}
}
示例15: CreateArray
public void CreateArray()
{
using (Lua lua = new Lua())
{
lua.DoString("luanet.load_assembly(\"LuaInterface.Test\")");
lua.DoString("TestClass=luanet.import_type(\"LuaInterface.Test.Mock.TestClass\")");
lua.DoString("arr=TestClass[3]");
lua.DoString("for i=0,2 do arr[i]=TestClass(i+1) end");
TestClass[] arr = (TestClass[])lua["arr"];
Assert.Equal(arr[1].testval, 2);
}
}