[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Removing Dictionary Elements
- From: Matthew Percival <matthew@...>
- Date: Wed, 20 Apr 2005 09:31:31 +1000
G'Day,
I'm a fairly new Lua user (only a week's experience), and am having a
little trouble with something I thought would be a fairly simple
operation.
I have am loading a dictionary from a file, editing elements, then
saving them again. To this point, it's fairly simple. I'm getting
caught, however, when it comes to deleting elements from the table. I
checked the wiki as well as the reference manual, and only found
table.remove, which seems to only work for indexed tables.
I've written a simple function to step through each key in the table,
and if it's not the one I want to remove add it to a the new table. Not
very clean, but it does the job. I was wondering if there were a better
method for this already built into the language that I've missed
somewhere, or isn't in the wiki.
While I'm asking questions, I wonder if perhaps there is a better way
to save the table to a file. I have a function which runs the file I'm
saving it to with dofile(), then returns the table I saved earlier
(nice, clean and simple), but when I want to save it I have an ugly
function I wrote which steps through each key and value, nesting loops
as it comes across nested tables. I'd imagine I could clean it up a
little with recursion, but I was wondering if there were a simple way to
save it with chunks like I can do with loading it.
Thanks for any assistance you can provide,
Matthew Percival