lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>> If the theory is indeed confirmed, is there a reason why the line hook
>> is not triggered *before* the entire translation?

> Line hooks are triggered whenever the code starts executing a new line.
> There is no relation to what the line does. We cannot control when
> they are triggered.

Clearly.

> It seems that the best solution is to actually do the "= nil" part. The
> new version of `localfunc' would be something like this:

To me, this seems like a needless inefficiency solely introduced to avoid
explaining to hypothetical programmers using a hypothetical debugger.

The resulting code generated would consist of a LOADNIL followed by a
CLOSURE to the same stack slot; any decent peephole optimiser would
remove the first instruction, so deliberately creating it seems perverse.

The manual clearly states that the debug interface should not be used
for normal program execution; while I am aware that there are those
who use it to implement Perl-like manipulation of pseudonamed local
variables, I personally believe that this is contrary to the design
of Lua (to say nothing of its obvious inefficiency and the fact that
it would fail if debugging information were stripped.)

I do not believe that it would be excessive to introduce a sentence
into the manual (in the debug interface section) explaining that
in the statement:
  local function foo(...) ... end
the local variable "foo" is conceptually in scope prior to the
statement, but its value is undefined.

Rici