![](/img/trans.png)
[英]How to string.dump a string from arguments if there are any from the lua cli or dumping the code in the file if there are no arguments
[英]Dumping lua func with arguments
是否可以轉儲包含函數參數的Lua表? 如果是這樣,我該怎么辦?
我已經成功地轉儲了帶有地址的表和函數,但是我一直無法找出一種獲取函數args的方法,我嘗試了其他方法,但是沒有運氣。
所以我想接收它們真相轉儲表和函數以及函數的參數。 輸出應該是這樣的:Function JumpHigh(Player,height)
我不知道是否有可能,但會非常方便。
表僅存儲值。
如果表中存儲了函數,那么它只是一個函數體,沒有參數。 如果應用了參數,則table將僅存儲該調用的最終結果。
也許您是在談論閉包-從其他函數返回的函數,從詞匯閉包中的頂級函數中捕獲一些參數? 然后查看debug.getupvalue()
函數以檢查閉包的內容。
這是您要問的嗎?
local function do_some_action(x,y)
return function()
print(x,y)
end
end
local t = {
func = do_some_action(123,478)
}
-- only function value printed
print "Table content:"
for k,v in pairs(t) do
print(k,v)
end
-- list function's upvalues, where captured arguments may be stored
print "Function's upvalues"
local i = 0
repeat
i = i + 1
local name, val = debug.getupvalue(t.func, i)
if name then
print(name, val)
end
until not name
請注意,存儲的升值不一定是頂級函數的參數。 它可能是一些局部變量,用於存儲內部函數的預先計算的值。
還要注意,如果腳本通過剝離調試信息被預編譯為Lua字節碼,那么您將不會獲得upvalues的名稱,這些名稱將為空。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.