debug
*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡。
概要
函式
profilebegin(label: string):() |
profileend():() |
setmemorycategory(tag: string):string |
resetmemorycategory():() |
dumpcodesize():() |
API 參考
函式
traceback
traceback
info
info
info
profilebegin
profileend
debug. profileend():()
返回
()
範例程式碼
除錯檔案結束
debug.profilebegin("Outer")
debug.profilebegin("Inner")
-- 此處的工作在兩個標籤下計時
debug.profileend() -- 關閉 "Inner"
debug.profileend() -- 關閉 "Outer"getmemorycategory
setmemorycategory
參數
返回
範例程式碼
除錯設置記憶體類別
local original = debug.setmemorycategory("MapGeneration")
print(debug.getmemorycategory()) --> MapGeneration
-- 在這裡進行的分配會在開發者控制台的 "MapGeneration" 下列出
local tiles = table.create(1000, 0)
-- 返回值是之前的類別,因此可以恢復
print(debug.setmemorycategory(original) == "MapGeneration") --> true
print(#tiles) --> 1000resetmemorycategory
debug. resetmemorycategory():()
返回
()
範例程式碼
除錯重置記憶體類別
local automatic = debug.getmemorycategory()
debug.setmemorycategory("生成中")
print(debug.getmemorycategory()) --> 生成中
debug.resetmemorycategory()
print(debug.getmemorycategory() == automatic) --> truedumpcodesize
debug. dumpcodesize():()
返回
()
範例程式碼
除錯轉儲代碼大小
-- debug.dumpcodesize() 只能從 Studio 命令欄運行,並將報告打印到輸出,
-- 每個原生腳本一個表格,最大的函數在前:
-- # 原生代碼大小分析
-- <n> 個腳本,<n> 個函數,<n> KB 記憶體,256 MB 代碼大小限制
-- ## <script name>
-- <n> 個函數,<n> KB 記憶體
-- | 函數 | 行 | 原生代碼大小 | 原生代碼大小 (%) |
-- 只有以 --!native 開頭並已運行的腳本會出現在報告中。
-- 從腳本中會引發錯誤,pcall 會捕獲
local ok, message = pcall(debug.dumpcodesize)
print(ok) --> false
print(message) --> dumpcodesize 只能從 CommandBar 調用