[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: documentation bug: call hook [WAS: Strange way to determine whether it is Lua or C function]
- From: Viacheslav Usov <via.usov@...>
- Date: Sun, 23 Aug 2020 18:55:55 +0200
On Sun, Aug 23, 2020 at 5:26 PM Viacheslav Usov <email@example.com> wrote:
> This is so because the "c" hook is invoked before the function is
> called, yet the context (stack frame) of the function is already
This is indeed so (in Lua 5.3 at least), contrarily to the
documentation that states: "The call hook: is called when the
interpreter calls a function. The hook is called just after Lua enters
the new function, before the function gets its arguments."
local debug = require 'debug'
for i = 1, 9 do print(i, debug.getlocal(2, i)) end
local function f(a, b, c) end
f('foo', 'bar', 'baz')
1 a foo
2 b bar
3 c baz
4 (*temporary) table: 0000016BA4367798
So the arguments are definitely on stack and available for inspection.
It is actually good, because a call hook without access to arguments
would be much less useful. The meaning of "just after Lua enters the
new function" is subject to interpretation.
I suggest another description instead: "The call hook: is called when
the interpreter calls a function. The hook is called as if the new
function had just begun execution, with its stack frame (specifically,
arguments) observable from the hook."