Come to think of it you may also want to check that numeric indices are
indeed positive integers before appending their value. I usually don't
because their not being so is rare.
Den tis 30 aug. 2022 10:56BPJ skrev:
>
>
> Den mån 29 aug. 2022 20:13Hans Hagen via ntg-context
> skrev:
>
>> On
Den mån 29 aug. 2022 20:13Hans Hagen via ntg-context
skrev:
> On 8/29/2022 7:33 PM, BPJ via ntg-context wrote:
> > Hi,
> >
> > I use the attached Lua function to merge array, map and mixed tables
> alike
> > (but differently! :-) The trick is to check if each key is numeric or
> not,
> > append
On Mon, 29 Aug 2022, Hans Hagen via ntg-context wrote:
> On 8/29/2022 2:20 PM, Aditya Mahajan via ntg-context wrote:
> > Hi,
> >
> > How do I merge two lua tables? I believe that table.merge or table.merged
> should do the trick, but I cannot figure out how to use them.
> >
> > ```
> > local t1
On 8/29/2022 7:33 PM, BPJ via ntg-context wrote:
Hi,
I use the attached Lua function to merge array, map and mixed tables alike
(but differently! :-) The trick is to check if each key is numeric or not,
append if it is and overwrite if it isn't.
you really want something like this then:
Hi,
I use the attached Lua function to merge array, map and mixed tables alike
(but differently! :-) The trick is to check if each key is numeric or not,
append if it is and overwrite if it isn't.
This function just ignores non-table arguments because that is what I
usually want. You may want to
On 8/29/2022 2:20 PM, Aditya Mahajan via ntg-context wrote:
Hi,
How do I merge two lua tables? I believe that table.merge or table.merged
should do the trick, but I cannot figure out how to use them.
```
local t1 = { 1, 2 }
local t2 = { 8, 9 }
local m1 = {}
table.merge(m1,t1, t2)
On Mon, 29 Aug 2022, Aditya Mahajan via ntg-context wrote:
> Hi,
>
> How do I merge two lua tables? I believe that table.merge or table.merged
> should do the trick, but I cannot figure out how to use them.
>
> ```
> local t1 = { 1, 2 }
> local t2 = { 8, 9 }
>
> local m1 = {}
>
Hi,
How do I merge two lua tables? I believe that table.merge or table.merged
should do the trick, but I cannot figure out how to use them.
```
local t1 = { 1, 2 }
local t2 = { 8, 9 }
local m1 = {}
table.merge(m1,t1, t2)
table.print(m1)
local m2 = table.merged(t1, t2)
table.print(m2)
```