I am really tired of repeating hash(“foo”) thing. and I can not pass string as a go.property. so I wrote this little script. free to use if you feel it useful.
hashy.lua (292 Bytes)
to use it. you can require it as a global like "hashy = require “hashy” "
for example, in the on_message callback.
you can use it like this:
function on_message(self,id,message,sender)
if id = hashy.test then … end (the same as id=hash(“test”), easier and faster)
end
also, you can check the string value to an existed hashvalue, for example:
local test = hashy.abc
print(hashy(hash(“abc”))) – will return abc as string.
4 Likes
print(hashy(hash(“abc”))) is returning error "attempt to call global ‘hashy’ (a table value)"
please help
Try:
pprint(hashy)
Might give clues…
For what it’s worth, what I do is have a separate file with all my constants which gives me a few benefits in my opinion:
- A bit easier to catch spelling errors (you’ll get
nil
if you misspell) - SImple, it’s just a table with variables
- No
hash_to_hex
call for each lookup - No extra string operations in release builds
- Can still print the hashes in debug builds
3 Likes