[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: argument alternative
- From: spir <denis.spir@...>
- Date: Tue, 23 Feb 2010 18:50:07 +0100
Hello,
A stupid question, I guess, but I cannot find any satisfying solution myself.
A Color constructor needs to accept as argument an HLS, an RGB, xor a hex ("#FF0000") color format. While the latter is indeed a string, HLS and RGB formats are tables, so that I cannot distinguish using types. (This is not limited to constructors, of course.)
The only solution I found is requiring the arg itself be passed inside a table:
c = Color{RGB={100,0,0}}
Well, a bit heavy (but not that much heavier as typical c = Color(RGB=(100,0,0)) in other languages ;-)
A side advantage is additional attributes can be set on the color at the same time:
RED = Color{RGB={100,0,0}, name="red"}
But I would like to know if you use other solutions.
Denis
PS: What about named args in Lua? After all, an arg list is a kind of table...
Other dynamic languages have arg lists with named & unnamed args, but no such data structures. In Lua, we have the opposite features: tables with named & unnamed items, but no such arg lists ;-)
________________________________
la vita e estrany
http://spir.wikidot.com/