Skip to content

Returning from inside a with statement? #208

Description

@Awpteamoose

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:

returnfunction(arg1, arg2)
dolocal_with_0=table_with_functionsreturn {
_with_0.fn1("work"),
_with_0.fn2("more work")
}
return_with_0endend

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions