From: Aditya Mahajan via ntg-context <ntg-context@ntg.nl>
To: Aditya Mahajan via ntg-context <ntg-context@ntg.nl>
Cc: Aditya Mahajan <adityam@umich.edu>
Subject: Re: Merging two lua tables
Date: Mon, 29 Aug 2022 08:29:13 -0400 (EDT) [thread overview]
Message-ID: <nycvar.YAK.7.78.908.2208290827510.152217@nqv-guvaxcnq> (raw)
In-Reply-To: <nycvar.YAK.7.78.908.2208290815500.152217@nqv-guvaxcnq>
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 = {}
> table.merge(m1,t1, t2)
> table.print(m1)
>
> local m2 = table.merged(t1, t2)
> table.print(m2)
> ```
>
> Processing the file with context filename shows that both m1 and m2 are {8, 9}. What am I missing.
Looking at the code, I see what is happening. table.merge(d) assume that the tables are key-value tables so the keys of the first table are silently overwritten by the send. I guess, I'll have to write my own function to merge "array" tables.
Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2022-08-29 12:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 12:20 Aditya Mahajan via ntg-context
2022-08-29 12:29 ` Aditya Mahajan via ntg-context [this message]
2022-08-29 17:33 ` BPJ via ntg-context
2022-08-29 18:10 ` Hans Hagen via ntg-context
2022-08-30 8:56 ` BPJ via ntg-context
2022-08-30 10:08 ` BPJ via ntg-context
2022-08-29 14:28 ` Hans Hagen via ntg-context
2022-08-30 5:52 ` Aditya Mahajan via ntg-context
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=nycvar.YAK.7.78.908.2208290827510.152217@nqv-guvaxcnq \
--to=ntg-context@ntg.nl \
--cc=adityam@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).