[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: predefined constants
- From: Rici Lake <lua@...>
- Date: Fri, 23 Jul 2004 10:56:50 -0500
On 24-Jul-04, at 3:55 AM, Adrian Sietsma wrote:
3/ use strings
if s == "STATE_1" then ...... end
still reads nicely, but are all those string comparisons going to cost
much ?
They are almost free. The strings are interned at compile time so the
string comparison is just a pointer comparison.
any other suggestions ?
local case = {}
function case.STATE_1(x, y) -- do something -- end
function case.STATE_2(x, y) -- do something else -- end
-- etc.
function do_state(state, x, y) return case[state](x, y) end
-- expand on this model as appropriate.