vscode調式LUA(EmmyLua)

codetodo發表於2024-11-01

安裝EmmyLUA外掛

或者在github中下載
https://github.com/EmmyLua/VSCode-EmmyLua
https://github.com/jiehuali/VSCode-EmmyLua.git

增加除錯Launch.json

開啟資料夾後會變成create a launcher.json,點選Run And Debug, 選擇EmmyLua New Debugger(這個是作者推薦的,更穩定些,前面兩個已經不更新了)

  • .vscode\launch.json
{
  // 使用 IntelliSense 瞭解相關屬性。 
  // 懸停以檢視現有屬性的描述。
  // 欲瞭解更多資訊,請訪問: https://go.microsoft.com/fwlink/?linkid=830387
  // https://blog.csdn.net/qq_34035956/article/details/109255357
  "version": "0.2.0",
  "configurations": [
    {
      "type": "emmylua_new",
      "request": "launch",
      "name": "EmmyLua New Debug",
      "host": "localhost",
      "port": 9966,
      "ext": [
        ".lua",
        ".lua.txt",
        ".lua.bytes"
      ],
      // "ideConnectDebugger"改為false(這裡ide是指VSCode,Debugger是指Unity
      "ideConnectDebugger": false
    }
  ]
}

專案中載入EmmyLua

function luamain()
	-- 全域性設定隨機數
	math.randomseed(GetCurTime())
	openLuaDebugServer()
	...
end

-- 開啟LUA除錯
function openLuaDebugServer()
	-- local openDebugLua = true
	if openDebugLua then
		connectEmmyLua('localhost', '0.5.14')
	end
end

function connectEmmyLua(addr, ver) 
	-- connect EmmyLua
	-- package.cpath = package.cpath .. ';C:/Users/lijh/.vscode/extensions/tangzx.emmylua-0.5.14/debugger/emmy/windows/x86/?.dll'
	-- package.cpath = package.cpath .. ';'..os.getenv("USERPROFILE")..'/.vscode/extensions/tangzx.emmylua-0.5.14/debugger/emmy/windows/x86/?.dll'
	package.cpath = package.cpath .. ';'..os.getenv("USERPROFILE")..'/.vscode/extensions/tangzx.emmylua-'..ver..'/debugger/emmy/windows/x86/?.dll'
	local dbg = require ('emmy_core')
	dbg.tcpConnect(addr, 9966)
end

參考連結

  • ( https://blog.csdn.net/qq_34035956/article/details/109255357 )
  • ( https://www.cnblogs.com/sailJs/p/16435038.html )

相關文章