[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How can I detect duplicate field names?
- From: "Evan DeMond" <evan.demond@...>
- Date: Thu, 27 Mar 2008 16:25:56 -0400
On Thu, Mar 27, 2008 at 3:17 PM, Lua Newbie <email@example.com
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).
Take a look at "Read-only tables" in Programming in Lua - that example can be adapted to do what you want.http://www.lua.org/pil/13.4.5.html
The only difference: Instead of throwing an error every time you detect an update, first check to see if the value you're trying to set is nil. If it's not nil, throw the error - but if there's nothing there, do the assignment yourself to allow the update to go through.
Hope this helps,