private void Start() { this.lua = new LuaState(); this.lua.Start(); LuaBinder.Bind(this.lua); this.lua.DoString(this.script, "TestInherit.cs"); float num = Time.realtimeSinceStartup; for (int i = 0; i < 200000; i++) { Vector3 position = base.transform.position; base.transform.position = position; } num = Time.realtimeSinceStartup - num; Debugger.Log("c# Transform get set cost time: " + num); LuaFunction function = this.lua.GetFunction("Test", true); function.BeginPCall(); function.Push(base.transform); function.PCall(); function.EndPCall(); this.lua.CheckTop(); this.lua.Dispose(); this.lua = null; }
//-------- private void Awake() { if (null != singleton) { Destroy(gameObject); return; } singleton = this; DontDestroyOnLoad(gameObject); if (null == scriptFolder) { return; } lua = new MyLuaState(); lua.Start(); LuaBinder.Bind(lua); addSearchPath(lua, Application.dataPath + scriptFolder); lua.DoFile(engineFileName); engine = lua.GetTable("_Engine"); func_engine_update = engine.GetLuaFunction("update"); func_engine_late_update = engine.GetLuaFunction("lateupdate"); }
void Start() { lua = new LuaState(); lua.Start(); LuaBinder.Bind(lua); lua.DoString(script); 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 Start() { #if UNITY_4_6 || UNITY_4_7 Application.RegisterLogCallback(ShowTips); #else Application.logMessageReceived += ShowTips; #endif new LuaResLoader(); state = new LuaState(); state.Start(); LuaBinder.Bind(state); state.DoString(script, "AccessingEnum.cs"); state["space"] = Space.World; // no gc // state.PushValue(Space.World); // state.LuaSetGlobal("space"); LuaFunction func = state.GetFunction("TestEnum"); func.BeginPCall(); func.PushValue(Space.World); func.PCall(); func.EndPCall(); func.Dispose(); func = null; }
// Use this for initialization void Start() { _state = new LuaState(); _state.Start(); LuaBinder.Bind(_state); _state.DoString(script); }
protected virtual void Bind() { LuaBinder.Bind(luaState); ColaLuaExtension.Register(luaState); DelegateFactory.Init(); LuaCoroutine.Register(luaState, this); }
// Use this for initialization public void TestStart() { //GameObject.DontDestroyOnLoad(gameObject); new LuaResLoader(); lua = new LuaState(); this.OpenLibs(); //这里是添加调试luaide lua.LuaSetTop(0); float t = Time.realtimeSinceStartup; LuaBinder.Bind(lua); Debug.Log("LuaBinder Wrap注册:" + (Time.realtimeSinceStartup - t) + "s"); LuaCoroutine.Register(lua, this); //携程 DelegateFactory.Init(); lua.Start(); string fullPath = Application.dataPath + "/FXGame/Lua"; lua.AddSearchPath(fullPath); fullPath = Application.dataPath + "/FXGame/ToLua/Lua"; lua.AddSearchPath(fullPath); StartMain(); StartLooper();//这里是处理update的方法,不调用这里计时器执行一次 }
//需要删除的转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"); }
/// <summary> /// 自定义解析的初始化 /// </summary> public void Init() { //激活自定义解析器,最后打包的时候再用 //new LuaCustomLoader(); //初始化唯一的LuaState luaState = new LuaState(); luaState.Start(); //委托初始化 委托工厂初始化 想要C#和Lua相互访问使用委托 必须先初始化工厂 否则没办法使用 DelegateFactory.Init(); //协程相关 //如果想让tolua协程跑起来 必须加一个函数 LuaLooper luaLooper = this.gameObject.AddComponent <LuaLooper>(); //将我们自己声明的解析器和lualoop绑定起来 luaLooper.luaState = luaState; //Lua协程注册 LuaCoroutine.Register(luaState, this); //Lua使用unity中的相关类 绑定Lua解析器 LuaBinder.Bind(luaState); }
void Start() { InputMgr.Instance.initialize(); ManifestMgr.Init(); AtlasMgr.Instance.Init(); #if UNITY_5 || UNITY_2017 || UNITY_2018 Application.logMessageReceived += Log; #else Application.RegisterLogCallback(Log); #endif lua = new LuaState(); lua.Start(); LuaBinder.Bind(lua); lua.OpenLibs(LuaDLL.luaopen_pb); lua.OpenLibs(LuaDLL.luaopen_struct); lua.OpenLibs(LuaDLL.luaopen_lpeg); #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX luaState.OpenLibs(LuaDLL.luaopen_bit); #endif DelegateFactory.Register(); string dataPath = Application.dataPath; int index = dataPath.LastIndexOf("/"); dataPath = dataPath.Substring(0, index); //lua.AddSearchPath(fullPath); lua.DoFile(Path.Combine(dataPath, "Client/Scripts/__init.lua")); LogicFrame.Instance.initialize(lua); GameSocket.Instance.run("192.168.1.108", "8007"); }
/// <summary> /// Inititialize the lua runtime environment /// </summary> /// <remarks> /// This method should be called before every Nova related work happens. The begining of the Start or Awake /// of the game controller might be a good choice /// </remarks> private void Init() { if (isInited) { return; } new LuaResLoader(); DelegateFactory.Init(); lua = new LuaState(); lua.Start(); LuaBinder.Bind(lua); lua.AddSearchPath(Application.dataPath + "/Nova/Lua"); // do default includes lua.DoString("require 'requires'"); // get the lua load string function luaLoadString = lua.GetFunction("loadstring"); if (luaLoadString == null) { // loadstring is deprecated after Lua 5.2 luaLoadString = lua.GetFunction("load"); } isInited = true; }
// Use this for initialization public void Init() { lua = new LuaState(); lua.AddSearchPath(puremvcPath); lua.Start(); LuaBinder.Bind(lua); }
void Awake() { #if UNITY_5 || UNITY_2017 || UNITY_2018 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif new LuaResLoader(); lua = new LuaState(); lua.Start(); LuaBinder.Bind(lua); DelegateFactory.Init(); // add component: LuaLooper looper = gameObject.AddComponent <LuaLooper>(); looper.luaState = lua; lua.DoString(luaFile.text, "TestLuaCoroutine.lua"); // get and call function: TestCortinue LuaFunction f = lua.GetFunction("TestCortinue"); f.Call(); f.Dispose(); f = null; }
public LuaCode() { InitLoader(); luaState = new LuaState(); LuaBinder.Bind(luaState); luaState.Start(); }
void Start() { Debugger.Log("Main.cs"); Text[] text = GameObject.FindObjectsOfType <Text>(); if (text.Length > 1) { Destroy(text[1].transform.parent.parent.gameObject); } var LastLuaLooper = GameObject.FindObjectOfType <LuaLooper>(); if (LastLuaLooper != null) { Destroy(LastLuaLooper.gameObject); Debugger.Log("Destroy:LastLuaLooper"); } lua = new LuaState(); lua.Start(); Debugger.Log("create:LuaState"); LuaBinder.Bind(lua); GameObject LuaLooper = new GameObject("LuaLooper"); LuaLooper.AddComponent <LuaLooper>().luaState = lua; DontDestroyOnLoad(LuaLooper); Debugger.Log("create:LuaLooper"); lua.DoFile("Main"); }
private void Awake() { Application.logMessageReceived += new Application.LogCallback(this.ShowTips); TestLuaStack.Instance = this; new LuaResLoader(); TestLuaStack.testGo = base.gameObject; this.state = new LuaState(); this.state.Start(); LuaBinder.Bind(this.state); this.state.BeginModule(null); this.state.RegFunction("TestArgError", new LuaCSFunction(TestLuaStack.TestArgError)); this.state.RegFunction("TestTableInCo", new LuaCSFunction(TestLuaStack.TestTableInCo)); this.state.RegFunction("TestCycle", new LuaCSFunction(TestLuaStack.TestCycle)); this.state.RegFunction("TestNull", new LuaCSFunction(TestLuaStack.TestNull)); this.state.RegFunction("TestAddComponent", new LuaCSFunction(TestLuaStack.TestAddComponent)); this.state.RegFunction("TestOutOfBound", new LuaCSFunction(TestLuaStack.TestOutOfBound)); this.state.RegFunction("TestMulStack", new LuaCSFunction(TestLuaStack.TestMulStack)); this.state.BeginStaticLibs("TestStack"); this.state.RegFunction("Test1", new LuaCSFunction(TestLuaStack.Test1)); this.state.RegFunction("PushLuaError", new LuaCSFunction(TestLuaStack.PushLuaError)); this.state.RegFunction("Test3", new LuaCSFunction(TestLuaStack.Test3)); this.state.RegFunction("Test4", new LuaCSFunction(TestLuaStack.Test4)); this.state.RegFunction("Test5", new LuaCSFunction(TestLuaStack.Test5)); this.state.RegFunction("Test6", new LuaCSFunction(TestLuaStack.Test6)); this.state.EndStaticLibs(); this.state.EndModule(); this.state.Require("TestErrorStack"); TestLuaStack.show = this.state.GetFunction("Show", true); TestLuaStack.testRay = this.state.GetFunction("TestRay", true); TestLuaStack.showStack = this.state.GetFunction("ShowStack", true); TestLuaStack.test4 = this.state.GetFunction("Test4", true); TestLuaStack.TestDelegate = (Action)Delegate.Combine(TestLuaStack.TestDelegate, new Action(this.TestD1)); TestLuaStack.TestDelegate = (Action)Delegate.Combine(TestLuaStack.TestDelegate, new Action(this.TestD2)); }
void Start() { #if UNITY_5_4_OR_NEWER Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif new LuaResLoader(); 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); lua.Call("Test", transform, true); lua.Dispose(); lua = null; }
private void Awake() { new LuaResLoader(); state = new LuaState(); state.Start(); LuaBinder.Bind(state); }
private void Start() { LuaState luaState = new LuaState(); luaState.Start(); LuaBinder.Bind(luaState); luaState.DoString(this.script, "LuaState.cs"); luaState["space"] = Space.World; LuaFunction function = luaState.GetFunction("TestEnum", true); function.BeginPCall(); function.Push(Space.World); function.PCall(); function.EndPCall(); function.Dispose(); GameObject gameObject = GameObject.Find("/Light"); Light component = gameObject.GetComponent <Light>(); function = luaState.GetFunction("ChangeLightType", true); function.BeginPCall(); function.Push(component); function.Push(LightType.Directional); function.PCall(); function.EndPCall(); function.Dispose(); luaState.CheckTop(); luaState.Dispose(); }
public static void Start() { state = new LuaState(); state.Start(); LuaBinder.Bind(state); LuaBridge.Register(); }
public static void Init() { state.Start(); LuaBinder.Bind(state); ApplicationManager.s_OnApplicationUpdate += Update; }
void Initialize() { luaState = new LuaState(); loader = new LuaResLoader(); #if UNITY_EDITOR luaState.AddSearchPath(LuaConst.luaDir); #endif #if AB_MODE luaState.AddSearchPath(AssetBundleUtility.LocalAssetBundlePath); luaState.AddSearchPath(AssetBundleUtility.GetStreamingPath()); #endif luaState.OpenLibs(LuaDLL.luaopen_pb); //if (LuaConst.openLuaSocket) //{ // OpenLuaSocket(); //} //if (LuaConst.openZbsDebugger) //{ // OpenZbsDebugger(); //} luaState.LuaSetTop(0); LuaBinder.Bind(luaState); luaState.Start(); LuaCoroutine.Register(luaState, this); }
//初始化 private void init() { #if UNITY_EDITOR //LuaFileUtils.Instance.beZip = UseAssetBundleLuaInEditor; LuaFileUtils.Instance.beZip = false; #else LuaFileUtils.Instance.beZip = true; #endif mLuaState = new LuaState(); mLuaState.LogGC = false; mLuaState.Start(); LuaBinder.Bind(mLuaState); mLuaState.DoFile(LuaFileUtils.Instance.beZip ? LuaEnterFile : LuaEnterDebugFile); //协程 // luaCoroutine = GameObject.Find("LuaCoroutine"); // if (luaCoroutine == null) // { // luaCoroutine = new GameObject(); // luaCoroutine.gameObject.name = "LuaCoroutine"; // luaCoroutine.AddComponent<LuaCoroutineComponent>(); UnityEngine.Object.DontDestroyOnLoad(luaCoroutine); // } // LuaCoroutine.Register(mLuaState, luaCoroutine.GetComponent<LuaCoroutineComponent>()); addFunc(FuncName.createLuaFile); }
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; }
//需要删除的转LuaFunction为委托,不需要删除的直接加或者等于即可 void Awake() { #if UNITY_5 || UNITY_2017 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif new LuaResLoader(); 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"); }
public void StartUp() { LuaConst.luaResDir = ResHelper.GetLuaFolder(); LuaState lua = new LuaState(); //重新创建lua读取 new LuaFileUtils(); //设置lua搜索路径 #if UNITY_EDITOR //编辑器模式下永远使用 Assets下的lua lua.AddSearchPath(LuaConst.luaDir); lua.AddSearchPath(LuaConst.toluaDir); #else //非编辑器模式下永远使用Res下的Lua lua.AddSearchPath(ResHelper.GetLuaFolder()); #endif //启动lua lua.Start(); LuaBinder.Bind(lua); DelegateFactory.Init(); lua.DoFile("Main.lua"); this.gameObject.AddComponent <LuaLooper>().luaState = lua; }
public void StartLua(GameObject go) { luaState = new LuaState(); #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX luaState.OpenLibs(LuaDLL.luaStateopen_bit); #endif luaState.OpenLibs(LuaDLL.luaopen_pb); luaState.OpenLibs(LuaDLL.luaopen_lpeg); luaState.LuaGetField(LuaIndexes.LUA_REGISTRYINDEX, "_LOADED"); luaState.OpenLibs(LuaDLL.luaopen_cjson); luaState.LuaSetField(-2, "cjson"); luaState.OpenLibs(LuaDLL.luaopen_cjson_safe); luaState.LuaSetField(-2, "cjson.safe"); luaState.LuaSetTop(0); LuaBinder.Bind(luaState); luaState.Start(); luaLooper = go.AddComponent <LuaLooper>(); luaLooper.luaState = luaState; Initialized = true; }
private void StartLua() { NTGResourceController.Instance.InitBundleDependencies(); lua = new LuaState(); #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX lua.OpenLibs(LuaDLL.luaopen_bit); #endif lua.LuaGetField(LuaIndexes.LUA_REGISTRYINDEX, "_LOADED"); lua.OpenLibs(LuaDLL.luaopen_cjson); lua.LuaSetField(-2, "cjson"); lua.OpenLibs(LuaDLL.luaopen_cjson_safe); lua.LuaSetField(-2, "cjson.safe"); lua.LuaSetTop(0); LuaBinder.Bind(lua); lua.Start(); looper = gameObject.AddComponent <LuaLooper>(); looper.luaState = lua; Initialized = true; }
//初始化方法 protected void Init() { //创建虚拟机 luaEnv = new LuaState(); luaEnv.OpenLibs(LuaDLL.luaopen_pb); //启动虚拟机 luaEnv.Start(); //委托工厂初始化 DelegateFactory.Init(); //绑定C#中,unity中的方法给lua使用,少了这一句,在lua中无法使用,Unity的API LuaBinder.Bind(luaEnv); //执行lua协同要先有这个组件 LuaLooper lusLoop = gameObject.AddComponent <LuaLooper>(); //指定虚拟机 lusLoop.luaState = luaEnv; Debug.Log("###################" + PathTools.GetPackerABPath()); luaEnv.AddSearchPath(PathTools.GetPackerABPath() + "/LUA"); luaEnv.AddSearchPath(PathTools.GetPackerABPath() + "/LUA/lua"); //加载lua的入口文件 luaEnv.DoFile("Main.lua"); //执行入口函数 ,封装的方法 LuaCallFunc("Main", gameObject); //启动update isExeUpdate = true; }
void Start() { #if UNITY_5 || UNITY_2017 Application.logMessageReceived += ShowTips; #else Application.RegisterLogCallback(ShowTips); #endif new LuaResLoader(); 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; }