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

Returning from inside a with statement? #208

Closed
Awpteamoose opened this issue Aug 11, 2015 · 0 comments
Closed

Returning from inside a with statement? #208

Awpteamoose opened this issue Aug 11, 2015 · 0 comments

Comments

@Awpteamoose
Copy link

So the following code:

(arg1, arg2) ->
    with table_with_functions
        return {
            .fn1("work")
            .fn2("more work")
        }

My intent is to have a function return a table that is filled with values returned by functions inside table_with_functions.

Compiles fine, generates the following code:

return function(arg1, arg2)
  do
    local _with_0 = table_with_functions
    return {
      _with_0.fn1("work"),
      _with_0.fn2("more work")
    }
    return _with_0
  end
end

That last return is not valid Lua and it doesn't work.

I've ended up writing it like such:

(arg1, arg2) ->
    with table_with_functions
        return {
            .fn1("work")
            .fn2("more work")
        }
    local _

But that just seems like a hack to avoid implicit return.


Am I doing something wrong? Is there a better way? I've only been using MoonScript for about two days so I might've missed something.

@leafo leafo closed this as completed in ce396ac Sep 27, 2015
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

1 participant