Reputation: 17
I have someTabe = {}
someTabe.foo = function (x,y)
return x + y
end
How can I get pint(function"(function (x,y) return x + y end
)??? Not return result.
Upvotes: 1
Views: 97
Reputation: 1543
You can't get code itself, but you can get bytecode using string.dump()
:
local f = function(x,y) print('AAA') end)
local bytecode = string.dump(f) -- Get bytecode of function
local f2 = load(f) -- It is copy of f, but (f ~= f2)
f2() -- prints AAA
Upvotes: 0
Reputation: 40
You could could look for a decompiler online if you are just trying to see the code. However in your own code it is impossible.
Upvotes: 0
Reputation: 72402
You cannot recover the source code of a function from inside Lua.
> print(someTabe.foo)
function: 0x7fed0bc091f0
This is telling you that someTabe.foo
contains a function, which has been converted to internal representation stored at the address shown.
If you need to recover the source code of a function from inside Lua, you need to compile it manually with load and then use the debug library to get the source code.
Upvotes: 1