Skip to content

luaTarget: "5.1" polyfills #157

Description

@Janne252

Hey,

Since the generated lua code may contain features that are not present in Lua 5.1, there might be a need for Lua polyfills, namely the table.pack and table.unpack methods (of which neither are available in Lua 5.1).

For example

// zoo() actually returns an array we want to unpack. 
// Otherwise we could use /** !TupleReturn */ decorator!
let [foo, bar] = zoo();

Results in

local foo,bar=table.unpack(zoo())

Which won't work in a strict Lua 5.1 environment.

Proposed polyfills

table.pack

if not table.pack then
    function table.pack (...)
        return {n=select('#',...); ...}
    end
end

Source: https://github.com/stevedonovan/Penlight/blob/master/lua/pl/compat.lua#L133

table.unpack

if not table.unpack then
    function table.unpack(...)
        return unpack(...)
    end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions