Quirrel4.41.0

iostream.blob.tostring

Method of blob, from module "iostream"
instance.tostring(): string

Allows calling .tostring() on blob instances (bypassing _get)

Return value

A string of the form (instance : 0x...), the default text the VM prints for any instance that has no _tostring metamethod.

Notes

A blob defines _get, so without this method a plain .tostring lookup would go through _get (which expects a numeric index) instead of reaching the built-in conversion; this method is registered directly so the call still works and reaches the same default text that println on a blob would show.

The returned string embeds this blob's memory address, so it differs on every run and must never be printed as-is; only its fixed prefix, checked here, is stable. Use as_string to get the bytes themselves as text.

Example

examples/iostream/blob/tostring.nut
from "iostream" import blob

let s = blob(2).tostring()
println("type(s) =", type(s))
println("s.len() > 10 =", s.len() > 10)     // the address makes the string long
println("s.slice(0, 6) =", s.slice(0, 6))    // only the fixed prefix is safe to print
Output:
type(s) = string
s.len() > 10 = true
s.slice(0, 6) = (insta

See also

as_stringReturns the blob contents as a string
blobclass index