lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, 2013-12-13 at 15:03 -0600, Andrew Starks wrote:
> On Fri, Dec 13, 2013 at 2:22 PM, Luther <lutheroto@gmail.com> wrote:
> > I did see that thread, but when Andrew says "When someone sets the list
> > to `nil`, i need to clear it.", it sounds like this:
> >
> > local list = createListAndFillItWithStuff()
> >
> > -- This magically clears the table, not the variable.
> > list = nil
> >
> > I don't see how else to interpret his question.
> 
> 
> obj = MyObj()
> 
> obj.list_of_stuff = Something_that_puts_bunches_of_objects_in_here()
> 
> ---
> Now, the act of adding stuff to this list is caught by a setter, which
> iterates the list and does some object related maintenance, for
> example, mapping video IO ports to logical outputs (probably not
> helpful context, but it's the best I have)
> 
> Later, if I'm resetting this list:
> 
> obj.list_of_stuff = nil
> ---
> I don't want that table to ever be *gone*, so I have a setter method
> for `list_of_stuff` that stops this from resulting in its
> nilification. Instead, clears the list and then some...
> 
> In a couple of cases, clearing any item in the list has consequences
> for the object, so, I keep the actual list in a shadow table.
> 
> So would `table.clear` work on the shadow table? Does it work only on
> things that are found in pairs? Does it work on anything it gets its
> hands on, using lua_next?
> 
> If a user calls table.clear, and nothing happens, that's not _bad_. If
> I could *define* what happened when it was called on a table, say in
> "__clear", then I would use it in more often and I wouldn't need to
> care/worry about the fact that it wouldn't work as expected / (as I
> wanted) in certain table confabulations (shadow tables, etc).

Ok, so the list is actually a sub-table. That makes a lot more sense :)

Luther