This can be solved by storing items in the keys and setting values to a dummy value (like true), so you can use a table like an unordered set with fast insertion, removal, and lookup. The problem with this is that removal is slow (need to shift down other items), and checking if an item is in the array is slow (need to loop over all the items). Often people new to Lua will create an array to store a group of objects, even if the order isn't necessary. Lua offers no standard function for it, mainly because of all the different ways you can copy a table. Comparing tables using = will return false even if the two tables have the same contents, they must actually be references to the same table.įinally, if you want to copy a table, you'll have to do it manually. The garbage collector is designed to work correctly even in the case where a table (directly or indirectly) contains a reference to itself.Ī related thing to remember is that table comparison works by reference. Tables are freed from memory by the garbage collector sometime after the last reference to them is gone (not necessarily instantly).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |