[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "local" and stack
- From: Jayanth Acharya <jayachar88@...>
- Date: Sun, 22 Sep 2013 11:34:43 +0530
@Sven, @JayCarlon, @Luiz - thanks for taking time to answer to my question. I think I understood the most of it. I am trying to stitch together the 3 answers, to understand it completely and finding some contradiction. Hopefully a follow-up answer might clear it up completely.
My question was indeed based on my observations around the upvalue semantics. I was following a tutorial to understand a particular way in which metatables are used, and the ability to return a local variable caused some confusion.
One contradiction (assumed) from @Sven and @Luiz's response regarding 'reference counting'. So - for return value (the object being referred-to), if it is not ref-counted, then I am guessing that semantics are always 'copy' ? That is, a copy of a local object is created and it is passed (sans referencing variable) as return value, and the function's local variable (and the object it was referring) is made GC candidate immediately. Is that correct ?
@Sven, regarding the upvalue catching semantics, where you say that it is done "conservatively", could you elaborate a bit ? I see three local variables (all tables), and only one of them really needs to have a lifetime, longer than that the function invocation, since it is returned. Was wondering if you call it conservative, because all 3 variables are not retained ?
@JayCarlson, the point about the edge-cases is understood. I saw some similar "extra specification behaviour" led and defined by the official (or main) Python implementation (written in C). Perhaps, this is why in spite of searching for an explanation of the semantics, in the Lua book, I didn't find many clues.