/** * Load an lua file. * * @param string strFile - The file name without extension. * @return bool - true if success, otherwise false. */ public bool DoFile(string strFile) { if (string.IsNullOrEmpty(strFile)) { return(false); } // Try to do file. try { // The lua file return the table itself. object cChunk = YwLuaScriptMng.Instance.LuaSvr.luaState.doFile(strFile); if ((null == cChunk) || !(cChunk is LuaTable)) { return(false); } // Remember lua table. m_cLuaTableOpt = new YwLuaTable((LuaTable)cChunk); return(true); } catch (System.Exception e) { YwDebug.LogError(YwLuaSvr.FormatException(e)); } return(false); }
public void Initialize() { YwLuaSvr cLuaSvr = LuaSvr; if (!cLuaSvr.Initialize(OnInitializeProgress, OnInitializedOk, false)) { YwDebug.LogError("The lua environment can not be initialized!"); return; } }
/** * Initialize the lua script environment. * * @param void. * @return void. */ public void Initialize() { YwLuaSvr cLuaSvr = LuaSvr; if (!cLuaSvr.Initialize(OnInitializeProgress, OnInitializedOk, LuaSvrFlag.LSF_BASIC | LuaSvrFlag.LSF_EXTLIB)) { YwDebug.LogError("The lua environment can not be initialized!"); return; } }
static public int LogError_s(IntPtr l) { try { System.Object a1; checkType(l, 1, out a1); YwDebug.LogError(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
/** * Call a lua method. * * @param ref LuaFunction cResFunc - The result of the function, if the lua function calls ok, if it is not null, will call it instead of look up from table by strFunc. * @param string strFunc - The function name. * @param params object[] aParams - The params. * @return object - The number of result. */ public object CallMethod(ref LuaFunction cResFunc, string strFunc, params object[] aParams) { // Check function first. if (null == cResFunc) { // Check params. if (string.IsNullOrEmpty(strFunc)) { return(null); } // Check table. if (!Valid) { return(null); } // Check function. object cFuncObj = m_cLuaTable[strFunc]; if ((null == cFuncObj) || !(cFuncObj is LuaFunction)) { return(null); } // Get function. cResFunc = (LuaFunction)cFuncObj; if (null == cResFunc) { return(null); } } // Try to call this method. try { if (null == aParams) { return(cResFunc.call()); } else { return(cResFunc.call(aParams)); } } catch (Exception e) { YwDebug.LogError(YwLuaSvr.FormatException(e)); cResFunc = null; return(null); } }
/** * Computer a md5 hash from a stream. * * @param Stream cStream - The stream. * @return string - The md5 hash. */ public string ComputeHash(Stream cStream) { if (null == cStream) { return(string.Empty); } if (null == m_cMd5) { YwDebug.LogError("You used an invalid md5 instance!"); return(string.Empty); } return(GetMd5Hash(m_cMd5, cStream)); }
/** * Computer a md5 hash from a buffer. * * @param byte[] aBuffer - The buffer. * @return string - The md5 hash. */ public string ComputeHash(byte[] aBuffer) { if ((null == aBuffer) || (0 == aBuffer.Length)) { return(string.Empty); } if (null == m_cMd5) { YwDebug.LogError("You used an invalid md5 instance!"); return(string.Empty); } return(GetMd5Hash(m_cMd5, aBuffer)); }
/** * Update method. * * @param void. * @return void. */ public void Update() { // The main update logic entry. if (null == m_cUpdateFunc) { return; } // Try to call update. try { m_cUpdateFunc.call(); } catch (System.Exception e) { YwDebug.LogError(YwLuaSvr.FormatException(e)); } }
/** * The initializing complete callback event. * * @param void. * @return void. */ private void OnInitializedOk() { YwLuaSvr cLuaSvr = LuaSvr; if (!cLuaSvr.inited) { YwDebug.LogError("Create lua server failed!"); return; } cLuaSvr.start("Main"); // Get update function. m_cUpdateFunc = cLuaSvr.GetFunction("Update"); if (null == m_cUpdateFunc) { YwDebug.LogError("There is no update function in main file! Are you missing \'Update()\'?"); return; } // Get late update function. m_cLateUpdateFunc = cLuaSvr.GetFunction("LateUpdate"); if (null == m_cLateUpdateFunc) { YwDebug.LogError("There is no late update function in main file! Are you missing \'LateUpdate()\'?"); return; } // Get fixed update function. m_cFixedUpdateFunc = cLuaSvr.GetFunction("FixedUpdate"); if (null == m_cFixedUpdateFunc) { YwDebug.LogError("There is no fixed update function in main file! Are you missing \'FixedUpdate()\'?"); return; } // Get lite update function. m_cLiteUpdateFunc = cLuaSvr.GetFunction("LiteUpdate"); if (null == m_cLiteUpdateFunc) { YwDebug.LogError("There is no lite update function in main file! Are you missing \'LiteUpdate()\'?"); return; } }
/** * Create a lua class instance for monobehavior instead of do a file. * * @param string strFile - The lua class name. * @return bool - true if success, otherwise false. */ public bool CreateClassInstance(string strClassName) { if (string.IsNullOrEmpty(strClassName)) { return(false); } // Try to get global lua class. try { // Get class first. LuaTable cClsTable = (LuaTable)YwLuaScriptMng.Instance.LuaSvr.luaState[strClassName]; if (null == cClsTable) { return(false); } // Get "new" method of the lua class to create instance. LuaFunction cNew = (LuaFunction)cClsTable["new"]; if (null == cNew) { return(false); } // We choose no default init parameter for constructor. object cInsChunk = cNew.call(); if (null == cInsChunk) { return(false); } // If we create instance ok, use it as table. m_cLuaTableOpt = new YwLuaTable((LuaTable)cInsChunk); return(true); } catch (System.Exception e) { YwDebug.LogError(YwLuaSvr.FormatException(e)); } return(false); }
/** * Update method. * * @param void. * @return void. */ public void Update() { // The main update logic entry. if (null == m_cUpdateFunc) { return; } // Try to call update. //UWAEngine.PushSample("YwLuaScriptMng.Test.Update"); try { m_cUpdateFunc.call(); } catch (System.Exception e) { YwDebug.LogError(YwLuaSvr.FormatException(e)); } //UWAEngine.PopSample(); }