简体   繁体   中英

Dumping lua func with arguments

Is it possibly to dump the Lua table including function arguments? If so, how can I do it?

I have managed to dump tables and function with addresses, but I haven't been able to figure out a way to get function args, i have tried different methods, but no luck.

So I want to receive them truth dumping tables and function plus args of the function. Output should be something like this: Function JumpHigh(Player, height)

I don't know if it is even possible, but would be very handy.

Table only stores values.

If there's function stored in a table, then it's just a function body, there's no arguments. If arguments were applied, table would store only final result of that call.

Maybe you're talking about closure - function returned from other function, capturing some arguments from a top level function in a lexical closure? Then see debug.getupvalue() function to check closure's content.

Is this something what you're asking?

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

Note that upvalues stored is not necessary an argument to a toplevel function. It might be some local variable, storing precomputed value for the inner function.

Also note that if script was precompiled into Lua bytecode with stripping debug info, then you won't get upvalues' names, those will be empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM