- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
Can hashtables have instances of structs as values?
From my understanding structs are internally just integers, so this should work ok as outlined below?
Can hashtables have instances of structs as values?
From my understanding structs are internally just integers, so this should work ok as outlined below?
JASS:
library HashTable initializer initTable
globals
hashtable ht = InitHashtable()
endglobals
struct MyStruct
integer a = 0
endstruct
function load takes integer id returns MyStruct //or integer?
return LoadInteger(ht, id, 0)
endfunction
private function initTable takes nothing returns nothing
local MyStruct m = MyStruct.create()
set m.a = 5
call SaveInteger(ht, 'hfoo', 0, m) //need to cast m to int?
set m = MyStruct.create() //this will create a new struct instance?
set m.a = 6
call SaveInteger(ht, 'n00b', 0, m)
endfunction
...
load('hfoo') //this will return what?
//a pointer to the struct? its integer index?
load('hfoo').a == 5 //true? is this valid?
load('n00b').a == 6 //true?
endlibrary