Hello, I really like Squirrel but recently I discovered the need for a little addition to the language: Compile time string hashing. I wanted to help out so I went ahead and implemented the feature.
The patch can be found
here, I created it using Beyond Compare so I'm not sure if it will work with GNU patch - but the modifications are quite restricted and to manual apply it wouldn't be too hard.
When the patch is applied a new string prefix operator '#' is added such that during lexing the string following is passed to a user provided hashing function. The lexer then creates an integer token instead of a string using the value you've generated.
You can now write Squirrel code like this and get.
a <- #"WALK_ANIMATION"
print ( a );
> a = -347238472348 // or whatever you returnThe interface is very simple, you write a hash function with the signature
(SQInteger)HASHFUNCTION( const SQChar* string ); and bind it to the compiler using:
sq_setcompilerhashfunction( SQVM, HASHFUNCTION );I've use this feature, as you might have guessed, to speed up runtime animation lookups. I hope this helps other people too.
Regards,
David Walters