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

Method Start

Assets/XLua/Tutorial/CSharpCallLua/CSCallLua.cs:70–113  ·  view source on GitHub ↗

Use this for initialization

()

Source from the content-addressed store, hash-verified

68
69 // Use this for initialization
70 void Start()
71 {
72 luaenv = new LuaEnv();
73 luaenv.DoString(script);
74
75 Debug.Log("_G.a = " + luaenv.Global.Get<int>("a"));
76 Debug.Log("_G.b = " + luaenv.Global.Get<string>("b"));
77 Debug.Log("_G.c = " + luaenv.Global.Get<bool>("c"));
78
79
80 DClass d = luaenv.Global.Get<DClass>("d");//映射到有对应字段的class,by value
81 Debug.Log("_G.d = {f1=" + d.f1 + ", f2=" + d.f2 + "}");
82
83 Dictionary<string, double> d1 = luaenv.Global.Get<Dictionary<string, double>>("d");//映射到Dictionary<string, double>,by value
84 Debug.Log("_G.d = {f1=" + d1["f1"] + ", f2=" + d1["f2"] + "}, d.Count=" + d1.Count);
85
86 List<double> d2 = luaenv.Global.Get<List<double>>("d"); //映射到List<double>,by value
87 Debug.Log("_G.d.len = " + d2.Count);
88
89 ItfD d3 = luaenv.Global.Get<ItfD>("d"); //映射到interface实例,by ref,这个要求interface加到生成列表,否则会返回null,建议用法
90 d3.f2 = 1000;
91 Debug.Log("_G.d = {f1=" + d3.f1 + ", f2=" + d3.f2 + "}");
92 Debug.Log("_G.d:add(1, 2)=" + d3.add(1, 2));
93
94 LuaTable d4 = luaenv.Global.Get<LuaTable>("d");//映射到LuaTable,by ref
95 Debug.Log("_G.d = {f1=" + d4.Get<int>("f1") + ", f2=" + d4.Get<int>("f2") + "}");
96
97
98 Action e = luaenv.Global.Get<Action>("e");//映射到一个delgate,要求delegate加到生成列表,否则返回null,建议用法
99 e();
100
101 FDelegate f = luaenv.Global.Get<FDelegate>("f");
102 DClass d_ret;
103 int f_ret = f(100, "John", out d_ret);//lua的多返回值映射:从左往右映射到c#的输出参数,输出参数包括返回值,out参数,ref参数
104 Debug.Log("ret.d = {f1=" + d_ret.f1 + ", f2=" + d_ret.f2 + "}, ret=" + f_ret);
105
106 GetE ret_e = luaenv.Global.Get<GetE>("ret_e");//delegate可以返回更复杂的类型,甚至是另外一个delegate
107 e = ret_e();
108 e();
109
110 LuaFunction d_e = luaenv.Global.Get<LuaFunction>("e");
111 d_e.Call();
112
113 }
114
115 // Update is called once per frame
116 void Update()

Callers

nothing calls this directly

Calls 5

LogMethod · 0.80
eFunction · 0.50
fFunction · 0.50
addMethod · 0.45
CallMethod · 0.45

Tested by

no test coverage detected