improve hd2str_lua()

hd2str_lua() was very slow.
These commits speed up hd2str_lua().