[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: _SELF and _SUPER
- From: "Soni L." <fakedme@...>
- Date: Sat, 6 Aug 2016 10:26:33 -0300
On 06/08/16 06:19 AM, Tim Hill wrote:
On Aug 4, 2016, at 9:54 AM, Soni L. <fakedme@gmail.com
<mailto:fakedme@gmail.com>> wrote:
Can we get _SELF and _SUPER?
local x = 1
function f()
local x = 2
print(_SUPER.x) --> 1
end
print(f())
pcall(function(x)
if x < 0 then error() end
if x == 0 then return end
print(x)
_SELF(x-1)
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…
do
local _SELF = function() … end
x = _SELF
end
—Tim
Well, you actually need to use "local function _SELF"
Also:
do
local function _SELF() print(_SELF) end
x = _SELF
_SELF = nil
end
x() --> nil
While a proper _SELF would be safe from such things.
I've used recursive pseudo-anonymous functions before. _SELF would make
them easier to use.
f((function()
local function inside_anonymous(args, I, should, take)
end
return inside_anonymous
end)())
--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.