int n = h"hello"; is a compile time equivalent of int n = HashString("hello");. As with raw strings, both h"" and H"" are accepted.
Similar to raw strings, it works as a hack on the lexer. The string is parsed like a regular string would be and then when the end is found, the whole token gets replaced with 0x12345678 hex integer token containing the hash value. Then, the parser just sees an integer instead.
What this doesn't allow for is hashing non-literal constants at compile time, like:
const string S = "foo";
const int H = h(S);
That would require an operator and then constant folding. I was thinking of overloading unary ~ for strings to do this, but it would require VM changes as well.
Testing
Added test case to constants.nss
Changelog
Added
scriptcomp: Added support for hashed string literals, h"..." and H"...".
Licence
[x] I am licencing my change under the project's MIT licence, including all changes to GPL-3.0 licenced parts of the codebase.
int n = h"hello";
is a compile time equivalent ofint n = HashString("hello");
. As with raw strings, both h"" and H"" are accepted.Similar to raw strings, it works as a hack on the lexer. The string is parsed like a regular string would be and then when the end is found, the whole token gets replaced with 0x12345678 hex integer token containing the hash value. Then, the parser just sees an integer instead.
What this doesn't allow for is hashing non-literal constants at compile time, like:
That would require an operator and then constant folding. I was thinking of overloading unary
~
for strings to do this, but it would require VM changes as well.Testing
Added test case to constants.nss
Changelog
Added
h"..."
andH"..."
.Licence