/**
     * 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);
    }
Ejemplo n.º 2
0
    public void Initialize()
    {
        YwLuaSvr cLuaSvr = LuaSvr;

        if (!cLuaSvr.Initialize(OnInitializeProgress, OnInitializedOk, false))
        {
            YwDebug.LogError("The lua environment can not be initialized!");
            return;
        }
    }
Ejemplo n.º 3
0
    /**
     * 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;
        }
    }
Ejemplo n.º 4
0
	static public int constructor(IntPtr l) {
		try {
			YwDebug o;
			o=new YwDebug();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Ejemplo n.º 5
0
 static public int constructor(IntPtr l)
 {
     try {
         YwDebug o;
         o = new YwDebug();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 6
0
 static public int LogException_s(IntPtr l)
 {
     try {
         System.Exception a1;
         checkType(l, 1, out a1);
         YwDebug.LogException(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 7
0
 public static int constructor(IntPtr l)
 {
     try {
         YwDebug o;
         o=new YwDebug();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
    /**
     * 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));
    }
Ejemplo n.º 11
0
    /**
     * 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));
        }
    }
Ejemplo n.º 12
0
    /**
     * 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();
    }