leafo / moonscript

:crescent_moon: A language that compiles to Lua

Home Page:https://moonscript.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I make a named function?

alxgnon opened this issue · 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. 🧄

Thanks

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?

commented

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.