lua-users home
lua-l archive

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


In message <CAEnbY+fGh2mxq3dUP4f9heeHZySceqhQtCQjwtAp5SwLvhtHkA@mail.gmail.com>
          Daurnimator <quae@daurnimator.com> wrote:

>On 21 July 2018 at 06:06, Gavin Wraith <gavin@wra1th.plus.com> wrote:
>> local D = { }
>> global = setmetatable ({ }, {
>>     __newindex = function (t, n, v) rawset (_G, n, v) end,
>>     __index = rawget,
>
>This assignment is redundant.
>
>>     })
>> global ._PROMPT = "> "
>> setmetatable (_G, {
>>   __newindex = function (t, n, v)
>>   if not D[n] then
>>     local w = debug.getinfo (2, "S").what
>>     if w ~= "C" then
>
>Why do you exclude C functions from the limitation?
>
>>       error ("\nattempt to write to undeclared variable " .. n, 2)
>>     end -- if
>>     D[n] = true
>>   end -- if
>>   rawset (t, n, v)
>
>You may want to make this a tail call for optimization purposes.

Thanks for these remarks. I have taken them all into account and moved
the "D[n] = true" statement into the body of global's metatable's __newindex
function, where it will not get used redundantly.

I am much happier with the syntax "global.x = ... ". RiscLua already
uses \ as a short form for "function" (an approximation to lambda).

--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/