void Start () { LuaState state = new LuaState(); state.Start(); LuaBinder.Bind(state); state.DoString(script); state["space"] = Space.World; LuaFunction func = state.GetFunction("TestEnum"); func.BeginPCall(); func.Push(Space.World); func.PCall(); func.EndPCall(); func.Dispose(); func = null; GameObject go = GameObject.Find("/Light"); Light light = go.GetComponent<Light>(); func = state.GetFunction("ChangeLightType"); func.BeginPCall(); func.Push(light); func.Push(LightType.Directional); func.PCall(); func.EndPCall(); func.Dispose(); func = null; state.CheckTop(); state.Dispose(); state = null; }
//实际应用如Socket.Send(LuaStringBuffer buffer)函数发送协议, 在lua中调用Socket.Send(pb_data) //读取协议 Socket.PeekMsgPacket() {return MsgPacket}; lua 中,取协议字节流 MsgPack.data 为 LuaStringBuffer类型 //msg = Socket.PeekMsgPacket() //pb_data = msg.data void Start() { #if UNITY_5 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif new LuaResLoader(); LuaState state = new LuaState(); state.Start(); Bind(state); state.OpenLibs(LuaDLL.luaopen_pb); state.DoString(script); LuaFunction func = state.GetFunction("Encoder"); func.Call(); func.Dispose(); func = null; func = state.GetFunction("Decoder"); func.Call(); func.Dispose(); func = null; state.CheckTop(); state.Dispose(); state = null; }
void Awake () { lua = new LuaState(); lua.Start(); LuaBinder.Bind(lua); lua.DoString(luaFile.text, "LuaCoroutine.lua"); update = lua.GetFunction("Update"); lateupdate = lua.GetFunction("LateUpdate"); fixedupdate = lua.GetFunction("FixedUpdate"); LuaFunction f = lua.GetFunction("TestCortinue"); f.Call(); f.Dispose(); }
void Start() { LuaState lua = new LuaState(); lua.Start(); lua.DoString(script); string[] strs = { "aaa", "bbb", "ccc" }; LuaFunction func = lua.GetFunction("TestArray"); func.BeginPCall(); func.Push(strs); func.PCall(); double arg1 = func.CheckNumber(); string arg2 = func.CheckString(); bool arg3 = func.CheckBoolean(); Debugger.Log("return is {0} {1} {2}", arg1, arg2, arg3); func.EndPCall(); //转换一下类型,避免可变参数拆成多个参数传递 object[] objs = func.Call((object)strs); if (objs != null) { Debugger.Log("return is {0} {1} {2}", objs[0], objs[1], objs[2]); } lua.CheckTop(); func.Dispose(); lua.Dispose(); }
void Start() { lua = new LuaState(); lua.Start(); lua.DoString(script, "AccessingArray.cs"); int[] array = { 1, 2, 3, 4, 5}; func = lua.GetFunction("TestArray"); func.BeginPCall(); func.Push(array); func.PCall(); double arg1 = func.CheckNumber(); string arg2 = func.CheckString(); bool arg3 = func.CheckBoolean(); Debugger.Log("return is {0} {1} {2}", arg1, arg2, arg3); func.EndPCall(); //转换一下类型,避免可变参数拆成多个参数传递 object[] objs = func.Call((object)array); if (objs != null) { Debugger.Log("return is {0} {1} {2}", objs[0], objs[1], objs[2]); } lua.CheckTop(); }
void Start() { #if !TEST_GC #if UNITY_5 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif #endif lua = new LuaState(); lua.Start(); lua.DoString(script); //Get the function object func = lua.GetFunction("test.luaFunc"); if (func != null) { //有gc alloc object[] r = func.Call(123456); Debugger.Log("generic call return: {0}", r[0]); // no gc alloc int num = CallFunc(); Debugger.Log("expansion call return: {0}", num); } lua.CheckTop(); }
void Start () { #if UNITY_5 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif new LuaResLoader(); LuaState lua = new LuaState(); lua.Start(); lua.DoString(script); LuaFunction func = lua.GetFunction("TestInt64"); func.BeginPCall(); func.PushInt64(9223372036854775807 - 789); func.PCall(); LuaInteger64 n64 = func.CheckInteger64(); Debugger.Log("int64 return from lua is: {0}", n64); func.EndPCall(); func.Dispose(); func = null; lua.CheckTop(); lua.Dispose(); lua = null; }
// UniLua.ILuaState uniLua = LuaAPI.NewState(); // NLua.Lua nlua = new NLua.Lua(); // Use this for initialization void Start() { // GameObject labelas = GameObject.Find ("Label1"); GameObject label1 = this.transform.FindChild("Label1").gameObject; label1.AddComponent <TestClick>(); UIEventListener com = this.transform.FindChild("Label4").GetComponent <UIEventListener> (); com.onClick = OnClick; uLua.RegisterLuaDelegateType(typeof(UIEventListener.VoidDelegate), typeof(LuaEventArgsHandler)); object[] aa = uLua.DoFile("TestLua"); LuaInterface.LuaFunction fun = uLua.GetFunction("TB.TB1.Start"); uLua.callFunction(fun, new object[] { this.gameObject }); // uniLua.L_OpenLibs(); // var status = uniLua.L_DoFile("TestUniLua.lua"); // if( status != ThreadStatus.LUA_OK ) // { // Debug.Log(uniLua.ToString(-1)); // } // TextAsset file = Resources.Load<TextAsset>("TestNLua"); // object[] aa1 = nlua.DoString(file.text, "TestNLua"); // NLua.LuaFunction fun1 = nlua.GetFunction ("TB.TB1.Start"); // nlua.CallFunction (fun1, new object[]{this.gameObject}); }
void Start () { state = new LuaState(); state.Start(); LuaBinder.Bind(state); state.DoString(script); func = state.GetFunction("TestPick"); }
void Start() { new LuaResLoader(); state = new LuaState(); state.Start(); LuaBinder.Bind(state); state.DoString(script, "TestOutArg.cs"); func = state.GetFunction("TestPick"); }
void Awake () { LuaState l = new LuaState(); l.DoString(script); LuaFunction f = l.GetFunction("luaFunc"); object[] r = f.Call("I called a lua function!"); print(r[0]); Debug.Log("Test script 1 AWAKE."); }
void Awake () { luaState = new LuaState(); luaState.Start(); LuaBinder.Bind(luaState); LuaCoroutine.Register(luaState, this); luaState.DoString(script); LuaFunction func = luaState.GetFunction("TestCo"); func.Call(); func.Dispose(); }
void Awake() { lua = new LuaState(); lua.Start(); LuaBinder.Bind(lua); looper = gameObject.AddComponent<LuaLooper>(); looper.luaState = lua; lua.DoString(luaFile.text, "TestCoroutine.cs"); LuaFunction f = lua.GetFunction("TestCortinue"); f.Call(); f.Dispose(); f = null; }
void Start () { Application.RegisterLogCallback(Logger); new LuaResLoader(); LuaState state = new LuaState(); state.Start(); state.DoFile("TestLoader.lua"); LuaFunction func = state.GetFunction("Test"); func.Call(); Application.RegisterLogCallback(null); func.Dispose(); state.Dispose(); }
// Use this for initialization void Start () { LuaState l = new LuaState(); // First run the script so the function is created l.DoString(script); // Get the function object LuaFunction f = l.GetFunction("luaFunc"); // Call it, takes a variable number of object parameters and attempts to interpet them appropriately object[] r = f.Call("I called a lua function!"); // Lua functions can have variable returns, so we again store those as a C# object array, and in this case print the first one print(r[0]); }
//实际应用如Socket.Send(LuaStringBuffer buffer)函数发送协议, 在lua中调用Socket.Send(pb_data) //读取协议 Socket.PeekMsgPacket() {return MsgPacket}; lua 中,取协议字节流 MsgPack.data 为 LuaStringBuffer类型 //msg = Socket.PeekMsgPacket() //pb_data = msg.data void Start() { Application.RegisterLogCallback(ShowTips); new LuaResLoader(); LuaState state = new LuaState(); state.Start(); Bind(state); state.OpenLibs(LuaDLL.luaopen_pb); state.DoString(script); LuaFunction func = state.GetFunction("Encoder"); func.Call(); func.Dispose(); func = null; func = state.GetFunction("Decoder"); func.Call(); func.Dispose(); func = null; state.CheckTop(); state.Dispose(); state = null; }
void Start () { state = new LuaState(); state.Start(); state.DoString(script); LuaFunction func = state.GetFunction("Test"); func.BeginPCall(); func.PCall(); thread = func.CheckLuaThread(); func.EndPCall(); func.Dispose(); func = null; thread.Resume(10); }
// Use this for initialization void Start() { LuaState l = new LuaState(); LuaScriptMgr._translator = l.GetTranslator(); // First run the script so the function is created l.DoString(script); // Get the function object LuaFunction f = l.GetFunction("myFunc"); // Create a paused lua coroutine object from the parent state and a function co = new LuaThread(l, f); // The coroutine needs to be resumed each frame, since it is yielding each frame, alternatively you could only resume it on conditions in C# instead co.Start(); }
void Start () { lua = new LuaState(); lua.Start(); lua.DoString(script); //Get the function object func = lua.GetFunction("test.luaFunc"); if (func != null) { //有gc alloc object[] r = func.Call(123456); Debugger.Log(r[0]); // no gc alloc int num = CallFunc(); Debugger.Log(num); } lua.CheckTop(); }
void Start () { #if UNITY_5 Application.logMessageReceived += Logger; #else Application.RegisterLogCallback(Logger); #endif new LuaResLoader(); LuaState state = new LuaState(); state.Start(); state.DoFile("TestLoader.lua"); LuaFunction func = state.GetFunction("Test"); func.Call(); func.Dispose(); state.Dispose(); #if UNITY_5 Application.logMessageReceived -= Logger; #else Application.RegisterLogCallback(null); #endif }
void Awake() { map.Add(1, new TestAccount(2, "水水", 0)); map.Add(2, new TestAccount(1, "王伟", 1)); map.Add(3, new TestAccount(2, "王芳", 0)); LuaState luaState = new LuaState(); luaState.Start(); BindMap(luaState); luaState.DoString(script); LuaFunction func = luaState.GetFunction("TestDict"); func.BeginPCall(); func.Push(map); func.PCall(); func.EndPCall(); func.Dispose(); func = null; luaState.CheckTop(); luaState.Dispose(); luaState = null; }
void Start () { LuaState lua = new LuaState(); lua.Start(); lua.DoString(script); long x = 123456789123456789; double low = (double)(x & 0xFFFFFFFF); double high = (double)(x >> 32); Debugger.Log("number x low is {0}, high is {1}", low, high); LuaFunction func = lua.GetFunction("TestInt64"); func.BeginPCall(); func.PushInt64(123456789123456000); func.PCall(); LuaInteger64 n64 = func.CheckInteger64(); Debugger.Log("int64 return from lua is: {0}", n64); func.EndPCall(); func.Dispose(); func = null; lua.CheckTop(); lua.Dispose(); }
void Awake() { LuaState state = new LuaState(); state.Start(); Bind(state); state.DoString(script, "TestOverride.cs"); TestExport to = new TestExport(); LuaFunction func = state.GetFunction("Test"); func.Call(to); }
public static LuaFunction GetFunction(IntPtr L, int reference) { LuaState state = LuaState.Get(L); return(state.GetFunction(reference)); }
public LuaSnapShot(LuaState state) { L = state; find = state.GetFunction("FindObjectInGlobal"); }
void Awake() { #if UNITY_5 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif Instance = this; new LuaResLoader(); testGo = gameObject; state = new LuaState(); state.Start(); LuaBinder.Bind(state); state.BeginModule(null); state.RegFunction("TestArgError", TestArgError); state.RegFunction("TestTableInCo", TestTableInCo); state.RegFunction("TestCycle", TestCycle); state.RegFunction("TestNull", TestNull); state.RegFunction("TestAddComponent", TestAddComponent); state.RegFunction("TestOutOfBound", TestOutOfBound); state.RegFunction("TestMulStack", TestMulStack); state.BeginStaticLibs("TestStack"); state.RegFunction("Test1", Test1); state.RegFunction("PushLuaError", PushLuaError); state.RegFunction("Test3", Test3); state.RegFunction("Test4", Test4); state.RegFunction("Test5", Test5); state.RegFunction("Test6", Test6); state.EndStaticLibs(); state.EndModule(); //state.DoFile("TestErrorStack.lua"); state.Require("TestErrorStack"); show = state.GetFunction("Show"); testRay = state.GetFunction("TestRay"); showStack = state.GetFunction("ShowStack"); test4 = state.GetFunction("Test4"); TestDelegate += TestD1; TestDelegate += TestD2; }
void Start() { lua = new LuaState(); lua.Start(); LuaBinder.Bind(lua); lua.DoString(script, "TestInherit.cs"); float time = Time.realtimeSinceStartup; for (int i = 0; i < 200000; i++) { Vector3 v = transform.position; transform.position = v; } time = Time.realtimeSinceStartup - time; Debugger.Log("c# Transform get set cost time: " + time); LuaFunction func = lua.GetFunction("Test"); func.BeginPCall(); func.Push(transform); func.PCall(); func.EndPCall(); lua.CheckTop(); lua.Dispose(); lua = null; }
void OnBundleLoad() { LuaState state = new LuaState(); state.Start(); state.DoString("print('hello tolua#:'..tostring(Vector3.zero))"); state.DoFile("Main.lua"); LuaFunction func = state.GetFunction("Main"); func.Call(); func.Dispose(); state.Dispose(); state = null; }
//需要删除的转LuaFunction为委托,不需要删除的直接加或者等于即可 void Awake() { state = new LuaState(); state.Start(); LuaBinder.Bind(state); Bind(state); state.LogGC = true; state.DoString(script); GameObject go = new GameObject("TestGo"); listener = (TestEventListener)go.AddComponent(typeof(TestEventListener)); SetClick1 = state.GetFunction("SetClick1"); AddClick1 = state.GetFunction("AddClick1"); AddClick2 = state.GetFunction("AddClick2"); RemoveClick1 = state.GetFunction("RemoveClick1"); RemoveClick2 = state.GetFunction("RemoveClick2"); TestOverride = state.GetFunction("TestOverride"); AddEvent = state.GetFunction("AddEvent"); RemoveEvent = state.GetFunction("RemoveEvent"); AddSelfClick = state.GetFunction("AddSelfClick"); RemoveSelfClick = state.GetFunction("RemoveSelfClick"); }
void Awake() { state = new LuaState(); state.Start(); LuaBinder.Bind(state); state.BeginModule(null); state.BeginStaticLibs("TestStack"); state.RegFunction("Test1", Test1); state.RegFunction("Test2", Test2); state.RegFunction("Test3", Test3); state.EndStaticLibs(); state.EndModule(); state.DoString(script, "script"); show = state.GetFunction("Show"); testRay = state.GetFunction("TestRay"); }