table reference through Thread:start

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

table reference through Thread:start

Post 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?
hippity hoppity ur code is my property (thanc in advanc)
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

Re: table reference through Thread:start

Post 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?
hippity hoppity ur code is my property (thanc in advanc)
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: table reference through Thread:start

Post 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.
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

Re: table reference through Thread:start

Post 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!
hippity hoppity ur code is my property (thanc in advanc)
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: table reference through Thread:start

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests