Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I make a named function? #422

Open
alxgnon opened this issue Jul 18, 2020 · 2 comments
Open

How can I make a named function? #422

alxgnon opened this issue Jul 18, 2020 · 2 comments

Comments

@alxgnon
Copy link

alxgnon commented Jul 18, 2020

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

@alxgnon alxgnon changed the title Q: Can you make named functions? How can I make a named function? Jul 18, 2020
@daelvn
Copy link

daelvn commented Jul 18, 2020

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?

@RyanSquared
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants