[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible enhancements for Lua 5.2
- From: Andre Leiradella <andre@...>
- Date: Sun, 26 Jun 2011 23:38:05 -0300
On 26/06/2011 22:57, Wesley Smith wrote:
Like I said before, I already have a solution that is computing a hash of
the string and using it in the switch. What I'm looking for is someway to
use a hash that's already computed and save some cycles from my binding
code.
Why not just use enums everywhere. You can push them into Lua and
pass them as args to your C code instead. It seems like this would be
much more maintainable and less of a PITA. The point of strings is
that they can be any sequence of characters, which if you're using in
a switch based on hash values doesn't apply to your case. Basically
you're treating strings as enums, so why not just use the best tool
for the job?
wes
-- warning: contrived example code below
local level = getCurrentLevel()
level:onEnter( getHero(), level:getObject( 'volume1' ), function()
local e = level:spanObject( 'boss1', 10, 0, 20 )
e:setState( 'attack' )
e:onKill( function() level:spanObject( 'exitkey', e:getPosition() )
end )
end)
I guess you're suggesting I could use VOLUME1, BOSS1, ATTACK and EXITKEY
as numbers set in the global table. If so, that would involve a table
lookup but yes, the switch on the C side would deal with numbers
directly. But that's not my main concern.
The thing is onEnter, spanObject, setState, onKill and getPosition
cannot be replaced by numbers without leading to seriously cryptic
scripts which leave me with my original problem.
Cheers,
Andre