protected void AssertOutput( string script, string function, string expectedOutput, string message ) { using( Lua lua = new Lua( ) ) { lua.DoString( script ); AssertOutput( lua, function, expectedOutput, message ); } }
public static void Main( string[] args ) { try { using( Lua state = new Lua( ) ) { state.DoFile( "test.lua" ); LuaFunction f1 = state["AFunction"] as LuaFunction; state.DoString( "AFunction = nil" ); f1.Call( ); f1.Dispose( ); LuaFunction f2 = state["BFunction"] as LuaFunction; f2.Call( ); f2.Dispose( ); LuaFunction print = state["print"] as LuaFunction; LuaTable sillytable = state["SillyTable"] as LuaTable; string str = sillytable["aaa"] as string; print.Call( str ); sillytable["aaa"] = 9001; print.Call( state["SillyTable", "aaa"] ); sillytable.Dispose( ); state.CreateTable( "table" ); print.Call( state["table"] as LuaTable ); print.Dispose( ); } } catch( LuaException e ) { Console.WriteLine( "Fail: " + e.Message ); } }
public static void Main( string[] args ) { try { TestRemoting( ); using( Lua state = new Lua( ) ) { LuaFunction print = state["print"] as LuaFunction; LuaTable table = state.CreateTable(); table.SetValue( "test", "value" ); state["incomingTable"] = table; state.DoFile( "test.lua" ); var f = new Function(); state["TestClr"] = f; LuaFunction f1 = state["AFunction"] as LuaFunction; state.DoString( "AFunction = nil" ); print.Call( "AFunction returned: " + f1.Call( )[0] ); f1.Dispose( ); LuaFunction f2 = state["BFunction"] as LuaFunction; f2.Call( ); f2.Dispose( ); LuaTable sillytable = state["SillyTable"] as LuaTable; string str = sillytable["aaa"] as string; print.Call( str ); sillytable["aaa"] = 9001; foreach( var val in sillytable ) { Console.WriteLine("{0} = {1}", val.Key, val.Value); } print.Call( state["SillyTable", "aaa"] ); sillytable.Dispose( ); state.CreateTable( "table" ); print.Call( state["table"] as LuaTable ); print.Dispose( ); GC.KeepAlive(f); } } catch( LuaException e ) { Console.WriteLine( "Fail: " + e.Message ); } }
private static void TestRemoting( ) { RemoteFunction.LookupFunction = MainClass.Lookup; using( var lua2 = new Lua( ) ) { using( var lua1 = new Lua( ) ) { LookupTable<string, Lua>.Store( "lua1", lua1 ); LookupTable<string, Lua>.Store( "lua2", lua2 ); lua1["remote"] = RemoteFunction.Instance; lua1.DoString( @"function Test1( a, b ) print( a ); print( b.a.a ); return ""Hello from Lua1 "" .. remote( ""lua2"", ""Test2"", ""a"", ""b"" ); end"); lua2["remote"] = RemoteFunction.Instance; lua2.DoString( @" function Test2( a, b ) print( ""Test2"" .. a .. b ); return ""Hello from Lua2 Called In""; end print( remote( ""lua1"", ""Test1"", ""a"", { a = { a = ""This is in a nested table."" } } ) ); "); } } }