lua-users home
lua-l archive

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



On Nov 26, 2014, at 4:04 PM, Thiago L. <fakedme@gmail.com> wrote:

Hi,

I had this function:

local function myfunc(a,b)
  -- some code here
  x = myfunc(y,z)
  -- more code here
  return v
end

Then I changed the name of the function:

local function dothing(a,b)

But I forgot to change the body!

To avoid having to change the function body every time (and to be able to call itself when using local name = function(args)), I propose an operator or keyword or something that returns the same value as "debug.getinfo(1,'f').func"...

"What should it be?" good question... I'm not sure... I'd use "self" but that's reserved by the :func() syntax sugar... "function.self" seems interesting but weird/'not-lua'...


Wrap the function and let it capture itself as an upvalue. For example;

do
local X = function(...)
    X(...)
end
someglobal = X
end

No need for any syntactic sugar