lua-users home
lua-l archive

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

On Aug 4, 2016, at 9:54 AM, Soni L. <> wrote:

Can we get _SELF and _SUPER?

local x = 1
function f()
  local x = 2
  print(_SUPER.x) --> 1

  if x < 0 then error() end
  if x == 0 then return end
end, 3) --> 3; 2; 1;

For performance, they would be translated by the compiler. Passing _SUPER around would copy all upvalues into a table, but for simplicity changing this table wouldn't change upvalues (e.g. no current syntactic construct can create a metatable).

_SELF and _SUPER would be indexable and callable.

(No idea what to say next. Idk, I'm just rambling I guess .-.)

A more interesting question .. why do you need this? And, for your need, have you explored other ways to solve the problem within the existing Lua language?

For example, _SELF for functions is trivial…

local _SELF = function() … end
x = _SELF