Chromatic <[EMAIL PROTECTED]> wrote: > On Sat, 2004-01-24 at 06:18, Leopold Toetsch wrote:
>> Either: >> new $P2, .HashlikeStruct, $P1 >> or >> assign $P2, $P1 > That gave me "Illegal initializer for struct", which may be related to > your next comment. The UnManagedStruct initializer is a list of triples (s. classes/unmanagedstruct.pmc:init_pmc or docs/pmc/struct.pod). Above error message is obviously from the first check if the array length % 3 is zero. >> If you make the initializer an OrderedHash, you can access struct >> elements by integer or string key. You would only need a test in >> char_offset_key, if you have an integer or string key. > Can you explain that in a little more detail? Assume I'm a lurker (for > their benefit, of course, not that I'm fumbling in the dark here). s. t/pmc/orderedhash.t The initializer of the struct could look like: new P1, .OrderedHash set P1["a"], .DATATYPE_a set P1[1], 0 set P1[2], 0 set P1["b"], .DATATYPE_b set P1[4], 0 set P1[5], 0 new P2, .UnManagedStruct, P1 Now you can access P2[0] := P2["a"] or P2[1] := P2["b"] elements of the structure by name or by struct item index. (The index is internally multiplied by 3, so that it maps to the initializer item). > What would you extend? As already mentioned char_offset_key would need a check, if a string key is passed. > Would you use the technique Dan suggested of keeping a mapping of string > key to offset hanging off the cache.pmc_key pointer? Isn't really needed. > If not, what would you do? s. above > -- c leo