lua-users home
lua-l archive

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


2018-03-21 0:15 GMT+02:00 dyngeccetor8 <dyngeccetor8@disroot.org>:
> On 03/20/2018 02:57 PM, Soni "They/Them" L. wrote:
>>
>> In Lua, the only use-case I can think of is for accessing shadowed variables in
>> a block scope:
>>
>> function f(a, flag)
>>   local a = a or {}
>>   local b = true
>>   if flag then
>>     forget a -- temporarily forget the shadowed `a` so we can get to the
>> original `a`'s nil/false-ness
>>     b = not not a -- tobool operator
>>   end
>>   -- use the shadowed `a` normally
>> end
>
> I think better way is to allow indirect access to lexical scope
> variables. Like "_G" but populated with local variables. (And
> some awkward name to access outer level, say "__parent".)

If the code is not stripped, the debug library has the necessary information.

The more I think about this idea, the more it seems to me that

(a) the same functionality is achievable already, in a cumbersome way,
 in "pure" Lua 5.1
(b) such simple syntax would allow the effortless writing of programs
with really opaque logic

So I agree with Martin's conclusion:

> I believe this may be implemented but will introduce much more problems than solve.