//重加载一个脚本文件,变量的值会全部恢复. public void CallScript(string script) { try { if (!string.IsNullOrEmpty(script)) { if (File.Exists(Application.persistentDataPath + "/" + script)) { svr.start(Application.persistentDataPath + "/" + script); } else { svr.start(script); } } else { Debug.Log("script file is null or empty"); } } catch (Exception exp) { Debug.LogError(exp.Message + ":" + exp.StackTrace); } }
void Start() { lua = new LuaSvr(); self = (LuaTable)lua.start("LuaFiles/building_txt"); //self = (LuaTable)lua.luaState.getObject("data"); //object o = lua.luaState.getFunction("GetData").call(); Debug.Log("table " + ((LuaTable)self[1])["name"]); LuaFunction dataFunction = ((LuaFunction)self["GetData"]); LuaTable dataTable = (LuaTable)dataFunction.call(); LuaFunction callFunction = (LuaFunction)self["CallBack"]; callFunction.call(222); //lua.luaState.getFunction("CallBack").call(); lua.luaState.getFunction("Call").call(2); Debug.Log("table " + ((LuaTable)dataTable[1])["use_money"] + " is Null " + (callFunction == null)); LuaTable d = (LuaTable)((LuaFunction)self["GetData1"]).call(); Debug.Log("---------------- : " + ((LuaTable)d[1])["use_money"]); LuaTable table2 = (LuaTable)lua.start("LuaFiles/building_txt1"); test2 = (LuaFunction)self["test"]; object o = test2.call(self, 9, 1); Debug.Log("add function :" + o); SetTransform = (LuaFunction)self["SetTransform"]; SetTransform.call(self, tr); //tr.localPosition = new Vector3(2, 2, 2); }
//主状态上.加载脚本后,运行以main为名称的函数 public void CallScript(string script) { try { if (!string.IsNullOrEmpty(script)) { string p = string.Format("{0}/{1}", Application.persistentDataPath, script); if (File.Exists(p)) { svr.start(p); } else { svr.start(script); } } else { Debug.Log("script file is null or empty"); } } catch (Exception exp) { Debug.LogError(string.Format("{0}:{1}", exp.Message, exp.StackTrace)); } }
void complete() { if (LGameConfig.GetInstance().isShowFps) { LFPSView.Show(); } if (!LGameConfig.GetInstance().isDebug) //生产环境 { if (LGameConfig.GetInstance().isHotFix) { GameObject canvas = GameObject.Find("Canvas"); Text lab_unzip = null; if (canvas.transform.Find("prog")) { canvas.transform.Find("prog").gameObject.SetActive(true); lab_unzip = canvas.transform.Find("prog/lab_unzip").GetComponent <Text>(); } GameObject obj = new GameObject(); obj.name = "ResUpdate"; LResUpdate resUpdate = obj.AddComponent <LResUpdate> (); resUpdate.onUnzipProgressHandler = (int step) => { if (lab_unzip) { lab_unzip.text = step.ToString(); } Debug.Log(" unzip " + step); }; resUpdate.onCompleteHandler = () => { Destroy(obj); LLoadBundle.GetInstance().LoadAllBundles(new string[] { "@lua.ab", "@luaconfig.ab" }, () => { _l.start("main"); }); }; resUpdate.checkUpdate(); } else { LLoadBundle.GetInstance().LoadAllBundles(new string[] { "@lua.ab", "@luaconfig.ab" }, () => { _l.start("main"); }); } } else //PC端开发 { _l.start("main"); } }
void OnLaunched() { m_launched = true; SLua.Logger.Log("OnSvrLaunched"); DoBind(m_luaState.L); LuaEvtCenter.Enable = true; //入口文件可以不叫main,但要有一个global的main方法, 其返回一个含有luaSvr_update等方法的一个表 m_luaTable = m_luaSvr.start("main") as LuaTable; m_luaUpdate = ((LuaFunction)m_luaTable["luaSvr_update"]).cast <LuaDelegate_Update>(); m_luaLateUpdate = ((LuaFunction)m_luaTable["luaSvr_lateUpdate"]).cast <LuaDelegate_Update>(); m_luaNotify = ((LuaFunction)m_luaTable["luaSvr_notify"]).cast <LuaDelegate_Notify>(); //m_luaNotify = (LuaFunction)m_luaTable["luaSvr_notify"]; m_luaNotifyError = ((LuaFunction)m_luaTable["luaSvr_notifyCsError"]).cast <LuaDelegate_NotifyError>(); Application.logMessageReceived += UnityLogCallback; //监听unitys的log LuaFunction luaLaunch = (LuaFunction)m_luaTable["luaSvr_launch"]; if (luaLaunch != null) { luaLaunch.call(); } }
void Start() { luaSvr = new LuaSvr(); luaSvr.init(null, () => { luaSvr.start("useLua"); }, LuaSvrFlag.LSF_DEBUG); }
void LuaVMReady() { lua.start("HelloLua.lua"); /* * if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor) * { * // 注意: 当在editor下运行时,直接使用 ROOT/lua 目录下的原始文件,不会使用更新下来的文件 * lua.luaState.doString("package.path = '" + Application.dataPath + "/Lua/?.lua'"); * // StartGameLogic(); * * lua.luaState.doString("require 'HelloLua'"); * } * else * { * // string cachePath = Application.temporaryCachePath; * // lua.luaState.doString("package.path = '" + cachePath + "/lua/?.lua'"); * // if (!Directory.Exists(cachePath + "/lua")) * // { * // MyLogger.Info("首次运行,正在准备基础文件..."); * // WWWLoader.LoadFromStreaming("scripts.pack", UnpackScripts, UnpackScriptsError); * // } * // else * // { * // StartGameLogic(); * // } * } */ }
// Use this for initialization void Start() { l = new LuaSvr(); l.init(null, () => { l.start("valuetype"); }); using (LuaState newState = new LuaState()) { LuaTable table = new LuaTable(newState); Vector2 v2 = new Vector2(1, 2); Vector3 v3 = new Vector3(1, 2, 3); Vector4 v4 = new Vector4(1, 2, 3, 4); Color col = new Color(.1f, .2f, .3f); Foo foo = new Foo(); table["v2"] = v2; table["v3"] = v3; table["v4"] = v4; table["col"] = col; table["foo"] = foo; Assert.IsTrue((Vector2)table["v2"] == v2); Assert.IsTrue((Vector3)table["v3"] == v3); Assert.IsTrue((Vector4)table["v4"] == v4); Assert.IsTrue((Color)table["col"] == col); Assert.IsTrue(table["foo"] == foo); } }
void complete() { LuaSvr.mainState.loaderDelegate += LuaLoder; lua_Svr.start("Lua_BagEvent"); LuaSvr.mainState.getFunction("getroot").call(this.gameObject); LuaSvr.mainState.getFunction("EventMain").call(); }
void complete() { LuaSvr.mainState.loaderDelegate += LuaLoder; lua_Svr.start("UseClass"); LuaSvr.mainState.getFunction("GetRoot").call(this.gameObject); LuaSvr.mainState.getFunction("ClassMain").call(); }
public void StartLuaSvr(Action <bool> onComplete) { string initModulePath = GetModulePath(m_luaInitModuleName); TextAsset initModuleAsset = null; initModuleAsset = ResourceManager.Instance.LoadAsset <TextAsset>(initModulePath); if (initModuleAsset == null) { Debug.LogError("StartLuaSvr fail load initModuleAsset fail"); onComplete(false); } // 构造lua state 环境 m_luaSvr = new LuaSvr(); // 设置lua模块加载器 LuaSvr.mainState.loaderDelegate = LuaLoader; // 初始化lua环境 m_luaSvr.init(null, () => { // 加载初始化模块 if (!string.IsNullOrEmpty(m_luaInitModuleName)) { m_luaSvr.start(m_luaInitModuleName); } }); onComplete(true); }
// Use this for initialization void Start() { l = new LuaSvr(); l.init(null, () => { l.start("delegate"); }); }
void Start() { svr = new LuaSvr(); svr.init(null, () => { self = (LuaTable)svr.start("skynet/main"); }, LuaSvrFlag.LSF_EXTLIB); }
// Use this for initialization void Start() { l = new LuaSvr(); l.init(null, () => { l.start("LuaTest"); }); }
// Use this for initialization void Start() { l = new LuaSvr(); l.init(null, () => { l.start("varobj"); }); }
// Use this for initialization void Start() { luaSvr = new LuaSvr(); luaSvr.init(null, () => { self = (LuaTable)luaSvr.start("startGame"); }); }
void Awake() { _instance = this; svr = new LuaSvr(); self = (LuaTable)svr.start("LuaFiles/LuaCallCsAPI"); self["event"] = DataEventSource.Instance; self["name"] = "API"; }
// Use this for initialization void Start() { l = new LuaSvr(); l.init(null, () => { l.start("valuetype"); }); }
/// <summary> /// 从resouce目录加载Lua脚本,并初始化 /// </summary> /// <param name="_rsPath">Resouce下的目录</param> /// <param name="_forceReading">是否强制读取</param> public SLua.LuaTable RsLoad(string _rsPath) { Log("加载:" + _rsPath); if (mluasvr.inited == false) { Log("还未初始化,等待初始化后加载:" + _rsPath); waitLoadLua = _rsPath; return(null); } if (luaDict.ContainsKey(_rsPath)) { return(luaDict[_rsPath]); } //设置执行脚本 //LuaState ls_state = new LuaState(); //设置脚本启动代理 LuaState.loaderDelegate = ((string fn) => { //获取Lua文件执行目录 string file_path = Directory.GetCurrentDirectory() + "/Assets/Resources/" + fn; file_path = file_path.Replace('/', '\\'); file_path = file_path.Replace('.', '\\'); Log("准备加载脚本:" + file_path); var file = File.ReadAllBytes(file_path + ".lua"); if (file == null) { LogError("加载Lua脚本失败,不存在的Lua脚本"); } else { Log("加载脚本成功.文件大小:" + file.Length); } return(file); }); //通过刚才设置的代理方法加载,就会从Res目录下读取带.lua的文件了 var self = (LuaTable)mluasvr.start(_rsPath); if (self != null) { luaDict.Add(_rsPath, self); return(self); } LogError("脚本初始化错误,脚本:" + _rsPath); return(null); }
void Start() { c = this; l = new LuaSvr(); l.init(null, () => { l.start("custom"); }); }
void Start() { luaSvr = new LuaSvr(); LuaSvr.mainState.loaderDelegate += LuaLoader; luaSvr.init(null, () => { luaSvr.start("MyPackage.Lua"); }); }
private void Awake() { LuaSvr svr = new LuaSvr(); svr.init(null, () => { svr.start("06_RequireImport/06_RequireImport"); }); }
void Start() { luaSvr = new LuaSvr(); LuaSvr.mainState.loaderDelegate += LuaLoader; luaSvr.init(null, () => { luaSvr.start("UseCSharpClass.Lua"); }); }
// Use this for initialization void Start() { luaSvr = new LuaSvr(); luaSvr.init(null, () => { self = (LuaTable)luaSvr.start("main"); //selfUpdate = (LuaFunction)self["update"]; }); }
void Start() { c = this; l = new LuaSvr(); l.init(null, () => { l.start("BindCSharp"); }); }
void Start() { luaSvr = new LuaSvr(); LuaSvr.mainState.loaderDelegate += LuaLoader; luaSvr.init(null, () => { luaSvr.start("CreatePrefab.Lua"); }); }
void OnComplete() { l.start("main"); SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.LoadScene("Example"); }
void Start() { svr = new LuaSvr(); svr.init(null, () => { self = (LuaTable)svr.start("circle/circle"); update = (LuaFunction)self["update"]; }); }
/// <summary> /// Inits the S lua. /// </summary> /// <returns><c>true</c>, if S lua was inited, <c>false</c> otherwise.</returns> /// <param name="progress">Progress.</param> public static bool InitSLua(System.Action <int> progress) { XBytecodeFilePicker.InitPicker(); luaServer = new LuaSvr(); platformPath = GetPlatformBytecodeFloder(); if (!string.IsNullOrEmpty(platformPath)) { LuaSvr.mainState.loaderDelegate = LoadScript; } Debug.LogFormat("BytecodeFloder : {0}", platformPath); luaServer.init(progress, () => { #if !RELEASE LuaSvr.mainState["_DEBUG"] = true; #endif #if UNITY_EDITOR LuaSvr.mainState["_EDITOR"] = true; #endif #if UNITY_ANDROID LuaSvr.mainState["_ANDROID"] = true; #endif #if UNITY_IPHONE luaServer.luaState["_IPHONE"] = true; #endif #if _LANGUAGE_CN LuaSvr.mainState["_LANGUAGE_CN"] = true; #endif #if _LANGUAGE_EN LuaSvr.mainState["_LANGUAGE_EN"] = true; #endif #if _LOCAL_SERVER LuaSvr.mainState["_LOCAL_SERVER"] = true; #endif var success = luaServer.start("main"); if (success == null || (bool)success != true) { Debug.LogError("Lua main intialize failed."); } }, LuaSvrFlag.LSF_BASIC | LuaSvrFlag.LSF_EXTLIB #if !RELEASE && LUA_DEBUG | LuaSvrFlag.LSF_DEBUG #endif ); return(true); }
void Start() { svr = new LuaSvr(); svr.init(null, () => { self = (LuaTable)svr.start("circle/circles"); update = (LuaFunction)self["update"]; ud = update.cast <UpdateDelegate>(); }); }