In release mode the reverse hash functionality does not work, but URLs should still work. The individual parts of the URL are hashes and I’m sure these return the values for the hashed strings. Try this:
Judging by the confusion on all sides here, I think it’s likely I’m missing something basic. It’s just troublesome it works on all devices apart from the S20. And that it’s so HOT TODAY.
In an effort to get to the crux of the matter, here is what I’m trying to do, step by step:
Turn message.other_id (a collision object) into a game object url.
Use tostring(url) as an id, ie. game_objects[tostring(url)], to cross reference it.
I get the feeling #2 is a no-no, so maybe the questions are:
What is the correct way of referencing a game object in an associative array?
I’ll try to explain it in a bit different way.
Strings are available only for debug reason, there are no strings in release build.
It doesn’t matter you can’t see this string. It is not a bug, but if you mention this as a bug, probably you try to use hash in a wrong way.
Could you please explain why it’s bothering you and what exactly doesn’t work in your project because of that?
As you see from your screenshot (?), the values: 17296653182486628446 and 12693854167970456507 are the same as in my example. Thus the original strings are “main”, and “/terrain”. So, your url seems fine.
Using the Url as a string, is a no-no. As mentioned, the string representation is for debugging purposes. You should be able to use the url as a key in a table. If all else fails:
local s = "" .. hash_to_hex(u.socket) .. ":/" .. hash_to_hex(u.path) .. "#" .. hash_to_hex(u.fragment)
io.stderr:write(string.format("string_id: %s\n", s))
Yes, #2 is a very big NO-NO. It will break down completely in a release build. The tostring() will result in the non-unique [main:<unknown>] string and it will be useless as a table key.
If it is a hash then you can use it as a key in a table. The hashes will be unique even in a debug build. If it is a URL you need to convert it to a unique string from its components before using it as a key:
local EMPTY = hash("")
local function to_key(url)
return hash_to_hex(url.socket or EMPTY) .. hash_to_hex(url.path or EMPTY) .. hash_to_hex(url.fragment or EMPTY)
end
That’s the million dollar question. Which other devices have you tested on?
And now that I think of it maybe we should handle this under-the-hood somehow. We should provide a better __tostring meta-method for URLs. It’s not the first time someone has stumbled on to this issue.
Given the solution described, it would apply to all platforms in release mode. If you still only have that particular issue on the S20, then you have another issue in your code.
It would be really nice if the URL object you got for a given object or component was always the same one, so you could use them as table keys, rather than ending up with something like this:
By looking a the Lua C code, it seems it’s not possible since it stores the pointer of the object. However, we’ll implement another function for the url, that would give you the url as a unique key, that you can use instead, to the same effect.