MCPcopy Create free account
hub / github.com/defold/defold / Hash_new

Function Hash_new

engine/script/src/script_hash.cpp:85–104  ·  view source on GitHub ↗

hashes a string * All ids in the engine are represented as hashes, so a string needs to be hashed * before it can be compared with an id. * * @name hash * @param s [type:string] string to hash * @return hash [type:hash] a hashed string * @examples * * To compare a message_id in an on-message callback function: * * ```lua * function on_mes

Source from the content-addressed store, hash-verified

83 * ```
84 */
85 static int Hash_new(lua_State* L)
86 {
87 int top = lua_gettop(L);
88
89 dmhash_t hash;
90 dmhash_t* phash = ToHash(L, 1);
91 if (phash != 0)
92 {
93 hash = *phash;
94 }
95 else
96 {
97 const char* str = luaL_checkstring(L, 1);
98 hash = dmHashString64(str);
99 }
100 PushHash(L, hash);
101
102 assert(top + 1 == lua_gettop(L));
103 return 1;
104 }
105
106 /*# get hex representation of a hash value as a string
107 * Returns a hexadecimal representation of a hash value.

Callers

nothing calls this directly

Calls 4

lua_gettopFunction · 0.85
ToHashFunction · 0.85
PushHashFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected