lua-users home
lua-l archive

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


Thank you for your clarification.

I think comparing the pointers of the outer table and inner table
could find out whether it's a recursive table or not.
Am I right? If I miss something,  please let me know.

On Thu, Jan 21, 2021 at 8:13 PM Scott Morgan <blumf@blueyonder.co.uk> wrote:
>
> On 21/01/2021 11:23, 孙世龙 sunshilong wrote:
> > Thank you for your detailed explanation.
> >
> > The assignment operator does almost the same thing both in Lua and
> > Python whereas Python provides deepcopy() to do the aforementioned
> > deep copy.
> >
> >> As you can see, there's a lot of possible ways to do this, as well as
> >> potential issues, such as if there are recursive tables (tables that
> >
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >> link to themselves).
> >   ^^^^^^^^^^^^^^^^^
> > Could you give me a example(i.e recursive tables). I could not find much
> > information about it on Google(keyword: Lua recursive tables).
> >
> > tab = {};
> > tab ={tab};
> > I don't think `tab` is a  recursive table indeed.
>
> In that case, you've change the value of tab to a new table containing
> the old value of tab.
>
> tab = {}           -- tab points to a new table
> tab.child = tab    -- tab.child points to the same table tab points to
> tab = {tab}        -- tab now points to another table, which contains
>                    -- the value tab used to point to
>
> You might want to see the difference between 'values' and 'variables' here.
>
> A variable points to a value, but is not the value itself.
>
> Seems to be the same issue you had in your other thread[1]. Functions
> are not passed variables, they're passed values.
>
>
>
> [1] "How to acquire the name of the variables passes to the self-defined
> C function which has been successfully set by lua_register()?"