1. -- ************************************************************************
  2. -- Script:   BYTEARRAY MIMICRY
  3. -- Version:  0.2
  4. -- Date:     2008-11-30
  5. --
  6. -- simulates ByteArray by overwriting obj.ilk ('ilk' as property), ilk(obj) ('ilk' as function) and string(obj)
  7. --
  8. -- ************************************************************************
  9.  
  10. property ancestor
  11. property ilk    -- for overwriting x.ilk -> #byteArray
  12.  
  13. on new me, p1, p2
  14.   me.ancestor = script("ByteArray").new(p1, p2)
  15.   me.ilk = #ByteArray
  16.   return me
  17. end
  18.  
  19. ----------------------------------------
  20. -- for overwriting x.ilk() or ilk(x) -> #byteArray
  21. ----------------------------------------
  22. on ilk me
  23.   return #ByteArray
  24. end
  25.  
  26. ----------------------------------------
  27. -- "<ByteArrayObject length = 0 ByteArray = <Void>> "
  28. -- "<ByteArrayObject length = 12 ByteArray = 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c > "
  29. ----------------------------------------
  30. on string me  
  31.   str = "<ByteArrayObject length = "&me.length&" ByteArray ="
  32.   if me.length=0 then
  33.     put " <Void>" after str
  34.   else
  35.     cnt = min(me.length, 10)
  36.     repeat with i = 1 to cnt
  37.       put " 0x" & me._hex(chartonum(me.pData.char[i]))&"," after str
  38.     end repeat
  39.     delete the last char of str
  40.   end if
  41.   put "> " after str
  42.   return str
  43. end
[raw code]