Page 1 of 1
table reference through Thread:start
Posted: Tue May 23, 2023 12:43 pm
by mk8
so i would like to pass a table reference to a thread via Thread:start. the wiki says:
(The argument may be) a string, number, boolean, LÖVE object, or simple table.
what does 'simple table' mean in this context? i'd like to make it so that when the original table changes, the thread has access to the changed table, not the original one. is this possible?
Re: table reference through Thread:start
Posted: Tue May 23, 2023 12:51 pm
by mk8
also the
Variant page says that
Nested tables are not officially supported in versions prior to 11.0.
so can Thread:start() take a nested table or no?
Re: table reference through Thread:start
Posted: Tue May 23, 2023 1:52 pm
by slime
mk8 wrote: ↑Tue May 23, 2023 12:43 pm
i'd like to make it so that when the original table changes, the thread has access to the changed table, not the original one. is this possible?
Each thread has a completely independent Lua instance, so sharing tables in that manner isn't possible. When you pass a table into Thread:start or Channel:push it has to copy it.
Re: table reference through Thread:start
Posted: Tue May 23, 2023 7:40 pm
by mk8
slime wrote: ↑Tue May 23, 2023 1:52 pm
mk8 wrote: ↑Tue May 23, 2023 12:43 pm
i'd like to make it so that when the original table changes, the thread has access to the changed table, not the original one. is this possible?
Each thread has a completely independent Lua instance, so sharing tables in that manner isn't possible. When you pass a table into Thread:start or Channel:push it has to copy it.
oh. sad. i think i'll manage though. nice to know, thx!
Re: table reference through Thread:start
Posted: Wed May 24, 2023 6:43 am
by zorg
mk8 wrote: ↑Tue May 23, 2023 12:51 pm
also the
Variant page says that
Nested tables are not officially supported in versions prior to 11.0.
so can Thread:start() take a nested table or no?
It can in version 11.0 and later, but it will still be a copy.
You could use any of the löve provided *Data classes since those only pass a reference between threads... although working with them currently is a bit of a chore, and regardless, you'll need to make sure you're careful with manipulating it at the same time from multiple threads; reading is less problematic than writing it, of course.