MCPcopy Create free account
hub / github.com/Tencent/xLua / Main

Method Main

General/Src/XLuaTest.cs:75–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73 public delegate double LuaMax(double a, double b);
74
75 public static void Main()
76 {
77 LuaEnv luaenv = new LuaEnv();
78 luaenv.DoString("CS.System.Console.WriteLine('hello world')");
79
80 var max = luaenv.Global.GetInPath<LuaMax>("math.max");
81 Console.WriteLine("max:" + max(32, 12));
82
83 luaenv.Global.Set("obj1", new AccessByGenGode());
84 luaenv.Global.Set("obj2", new AccessByReflection());
85
86 luaenv.DoString(@"
87 local p = CS.Point(3, 4)
88 print('-----------------------------')
89 obj2:Print(p)
90 print('-----------------------------')
91 obj1:Print(p)
92 print('-----------------------------')
93 ");
94
95
96 var calc = new Calc();
97 luaenv.Global.Set("calc", calc);
98 luaenv.DoString("print(calc:Add(2, 4))");
99
100
101 try
102 {
103 Console.WriteLine("2 + 4 =" +calc.Add(2, 4));
104 luaenv.DoString(@"
105 xlua.hotfix(CS.Calc, 'Add', function(self, a, b)
106 return a + b
107 end)
108 ");
109 Console.WriteLine("2 + 4 =" + calc.Add(2, 4));
110
111 CalcByConfig calc2 = new CalcByConfig();
112 Console.WriteLine("2 + 4 =" + calc2.Add(2, 4));
113 luaenv.DoString(@"
114 xlua.hotfix(CS.CalcByConfig, 'Add', function(self, a, b)
115 return a + b
116 end)
117 ");
118 Console.WriteLine("2 + 4 =" + calc2.Add(2, 4));
119
120 //�ͷ�hotfix
121 luaenv.DoString(@"
122 xlua.hotfix(CS.Calc, 'Add', nil)
123 xlua.hotfix(CS.CalcByConfig, 'Add', nil)
124 ");
125 }
126 catch(Exception e)
127 {
128 Console.WriteLine("Hotfix exception:" + e);
129 }
130 max = null;
131 luaenv.Dispose();
132 }

Callers

nothing calls this directly

Calls 3

DisposeMethod · 0.80
SetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected