lua-users home
lua-l archive

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

If you want to stick to regular table notation, syntax modders (luaSub, MetaLua) could be taught to detect this.

Then again, if you don't have other use for them, it's probably an overkill.

Lua Newbie kirjoitti 27.3.2008 kello 21:17:
I've googled and searched the archive to no avail ...

Is there a way to detect duplicate field names in a table?

Suppose I want users to be able to configure an app using lua. They create a table like:


I want to detect and reject any duplicate keys (eg key1=key2). By default, Lua appears to ignore all but the last instance of the key. (I'm guessing that it actually installs val1 at key1 but then replaces val1 with val2.) That is OK in some cases, but I've got lots of keys and want to detect typos that lead to duplicates.

I've figured out how to iterate over key, value pairs but the duplicates are skipped.

Any way to handle this?


Looking for last minute shopping deals? Find them fast with Yahoo! Search.