consejos de depuración de lua


título: habilidades de depuración lua
categorías: Lua
etiquetas: [lua, depuración, habilidades]
fecha: 2022-07-14 16:31:27
comentarios: falso
mathjax: verdadero
toc: verdadero

consejos de depuración de lua


precuela

Habilidades de depuración de script lua del juego, para lograr la ejecución en tiempo real después de modificar los scripts lógicos y mejorar la eficiencia del desarrollo


Modo editor del lado de la PC

  1. Crear un nuevo script de código de prueba

    gDebugCustom = gDebugCustom or {
          
          }
    
    function gDebugCustom.Test01()
    	gLog("--- Test01")    
    end
    
  2. El editor agrega análisis a este script y muestra el botón

    imagen-20220715161734442

    1. Haga clic en el botón para ejecutar el método correspondiente

      • csharp

        GameMgr.CallLuaFunction("Debug_ExecCustomLua", luaFile, funcName);
        
      • lúa

        -- 动态执行 自定义 lua 文件调试
        function Debug_ExecCustomLua(luaFile, funcName)
            local ok = xpcall(function()
                gAssert(Utils.IsFileExist(luaFile), "--- 找不到lua 文件, path: {0}", luaFile)
                dofile(luaFile)
                gAssert(gDebugCustom, "--- 找不到全局 table: gDebugCustom")
                gAssert(type(gDebugCustom[funcName]) == "function", "--- 找不到 gDebugCustom.{0} 方法", funcName)
        
                gDebugCustom[funcName]()
            end, __G__TRACKBACK__)
            if ok then
                gLog("<color=#00ff00ff>--- gDebugCustom.{0} success!</color>", funcName)
            else
                gLog("<color=yellow>--- gDebugCustom.{0} execute fail!</color>", funcName)
            end
        end
        
        
        
        
        

terminal móvil

descargar lua

  1. Agregue un método global al script de prueba [modo de editor de PC] (#modo de editor de PC) gDebugWebFnpara la ejecución web

    
    gDebugCustom = gDebugCustom or {
          
          }
    
    function gDebugCustom.Test01()
        gLog("--- Test01")
    end
    
     -- 增加的全局方法
    gDebugWebFn = function()
        gDebugCustom.Test01()
    end
    
    
  2. Vaya al botón de interfaz de usuario de depuración del juego para ejecutar un script de prueba de descarga y ejecutegDebugWebFn

    local function testDynamicLua()
        local url = "http://192.168.1.200:59090/lua/custom_unittest.lua"
        gTool.SafeDoString(url, function(isStop, msg)
            gLog("<color=#ffff00>--- gTool.SafeDoString, isStop: {0}</color>, msg: {1}", isStop, msg)
            gAssert(type(gDebugWebFn) == "function", "--- 找不到全局调试方法 gDebugWebFn")
            gDebugWebFn()
        end)
    end
    

Avanzado
  1. Ejecute dinámicamente scripts y descargue dinámicamente otros scripts lógicos nuevamente, lo que reescribirá el método lua para lograr una lógica de script de actualización en tiempo real.

    -- 避免出现在 unity editor中
    gDebugCustom.requireExt = function(luaPath, callback)
        local luaDirUrl = "http://192.168.1.200:59090/require"
        local newPath = string.gsub(luaPath, "%.", "/")
        local relaPath = string.formatExt("{0}.lua", newPath)
        local fullUrl = string.formatExt("{0}/{1}", luaDirUrl, relaPath)
        -- gLog("--- fullUrl: {0}", fullUrl)
    
        local cbWrap = function(isOk, res)
            gAssert(isOk, "--- url require fail, luaPath: {0}, fullUrl: {1}", luaPath, fullUrl)
            gLog("<color=#00ff00>--- url require success</color>, luaPath: {0}, fullUrl: {1}", luaPath, fullUrl)
            if callback then callback(res) end
        end
    
        gBestHttpMgr:GetData(fullUrl, function(isSucc, data)
            if isSucc and not IsNull(data) then
                local text = Utils.BytesToUTF8(data)
                local ok, res = xpcall(loadstring(text), __G__TRACKBACK__)
                if not ok then
                    cbWrap(false, "do remote string error")
                else
                    -- 移动端非 ab 模式, 写入本地
                    if gLogicTool.IsMobile() and not Const.LuaBundleMode then
                        local fullPath = gTool.PathJoin(Application.persistentDataPath, Const.kResluaDir, relaPath)
                        Utils.WriteFileUTF8(fullPath, text)
                    end
    
                    cbWrap(true, res)
                end
            else
                cbWrap(false, "Network error")
            end
        end)
    end
    
    function gDebugCustom.Dynamic()
        local function testGm()
            gDebugCustom.requireExt("logic.common.gm", function()
                local input = "show me the log"
                local isOk = gGmMgr:Do(input)
                gLog("--- gm ok: {0}", isOk)
            end)
        end
    	
        -- 测试
        testGm()
    end
    
    
    
    

copia lateral de Android lua

En la forma de lua de texto sin formato, puede copiar directamente el script lua en el proyecto al directorio del cuerpo del paquete con el comando adb y luego reiniciar el juego o reiniciar la máquina virtual lua

  • comando adb

    $ adb push E:/its/rummy_itc-v4/z_tempSave/lua /sdcard/Android/data/com.aaa.bbb/files
    

Supongo que te gusta

Origin blog.csdn.net/yangxuan0261/article/details/125946307
Recomendado
Clasificación