Skip to content

Quession about write DSL like using lua table #91

Answered by edubart
Atypicalim asked this question in Q&A
Discussion options

You must be logged in to vote

At this moment, you can use this DSL only on by-value records:

local ItemByValueChild = @record{
  name: string,
}

local ItemByValue = @record{
  name: string,
  child: ItemByValueChild
}

local itemByValue: ItemByValue = {
  name = 'someName',
  child = {
    name = 'someName',
  }
}

Nelua introduces by-value records, and their semantics are different from Lua tables. A by value record is passed copying the whole data structure instead of just a reference; in contrast, Lua tables passes just a reference. My example above had to introduce a second struct, because on a by-value record it's impossible to use it recursively (the record size would be infinite).

What you really want to have t…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by edubart
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants
Converted from issue

This discussion was converted from issue #90 on August 11, 2021 16:20.