GithubHelp home page GithubHelp logo

Exports return at block end about pluto HOT 3 CLOSED

XmiliaH avatar XmiliaH commented on May 25, 2024
Exports return at block end

from pluto.

Comments (3)

Sainan avatar Sainan commented on May 25, 2024

Yes, this is the documented behavior. The return statement is implied at the end of the block. It is mainly intended for top-level functions, but it's also useful in function bodies to push into package.preloaded.

from pluto.

XmiliaH avatar XmiliaH commented on May 25, 2024

The documentation only states

The return statement is automatically generated.

not if this happens at the end of the function or the end of a block (end of if, end of loop, end of switch).

So it does not state how my example is translated.

local function f(extended)
    local function r1() end
    if extended then
        local function r2() end
        return {r2=r2}
    end
    return {r1=r1}
end

or

local function f(extended)
    local function r1() end
    if extended then
        local function r2() end
        return {r1=r1, r2=r2}
    end
    return {r1=r1}
end

or

local function f(extended)
    local exports = {}
    local function r1() end
    exports.r1 = r1
    if extended then
        local function r2() end
        exports.r2 = r2
    end
    return exports
end

from pluto.

Sainan avatar Sainan commented on May 25, 2024

Well, it does have the example:

-- end of scope; 'return' is automatically generated

Maybe can be a bit more explicit.

from pluto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.