Skip to content

Why Lua tables aren't accepted as JS dictionaries? #44

@Egor-Skriptunoff

Description

@Egor-Skriptunoff

I want to translate this JS one-liner to Lua:

Split(['#Left', '#Right'], {gutterSize: 15, minSize: 270, sizes: [25, 75], snapOffset: 0, expandToMin: true});

This works, but is too bulky:

local window = js.global
local options = js.new(window.Object)
options.gutterSize = 15
options.minSize = 270
options.sizes = window:Array(25, 75)
options.snapOffset = 0
options.expandToMin = true
window:Split(window:Array('#Left', '#Right'), options)

This looks nice, but doesn't work:

local window = js.global
window:Split(window:Array('#Left', '#Right'), {gutterSize = 15, minSize = 270, sizes = window:Array(25, 75), snapOffset = 0, expandToMin = true})

Why Fengari doesn't convert Lua tables to JS dictionaries on-the-fly?
It's too boring to write this conversion manually.

If there are some reasons why such conversion could not be done automatically,
please add a function js.dict(lua_table) which will convert Lua-curly-braces into JS-curly-braces.
This function would make creating a JS dictionary on Lua side a lot easier:

window:Split(window:Array('#Left', '#Right'), js.dict{gutterSize = 15, minSize = 270, sizes = window:Array(25, 75), snapOffset = 0, expandToMin = true})

Yes, I know that I can write such function myself on Lua side, but this function is a "must-have" for every developer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions