moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

How can I make a named function?

Open alxgnon opened this issue 4 years ago • 2 comments

Hello,

How can I create a non-anonymous function? This is the Lua I want:

local function foo()
end

This is what I tried to do:

foo = foo() ->

Clearly that doesn't work. Could not find an answer anywhere.

I ask because I would like to use the Lua outliner. I would like to avoid seeing "Anonymous" everywhere. :garlic:

Thanks

alxgnon avatar Jul 18 '20 02:07 alxgnon

As far as I'm concerned, there is no way to do this with MoonScript. Both local foo = function()end and local function foo() end are roughly equivalent in Lua already, so the first is the way that MoonScript went with.

Maybe it would be interesting to see how this could be made, but are there other benefits beside debugging?

daelvn avatar Jul 18 '20 10:07 daelvn

The only possible benefit is that PUC-Rio Lua has an OP_SELF bytecode that optimizes the case of defining function x:y() that MoonScript can't take advantage of.

RyanSquared avatar Jul 20 '20 09:07 RyanSquared