lua-users home
lua-l archive

Create a new table based on an already existed table (through Lua or C API)?

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


How to create a new table based on an already existed table (through
Lua or C API)?
This code snippet seems impossible to achieve this goal:
foo = {};
foo.a = 1;
foo.b = 2;
new = foo;
print(new, foo) --they both point to the same table!
new.a = new.a+1; --the value of foo.a has been modified too.
 --I hope the table named `new` to be a
table which is independent from the table named `foo`.

AltStyle によって変換されたページ (->オリジナル) /