Get a string from a UTF-8 encoded C string
If byteLength
is not provided, the string is assumed to be null-terminated.
var ptr = lib.symbols.getVersion();
console.log(new CString(ptr));
var ptr = lib.symbols.getVersion();
// print the first 4 characters
console.log(new CString(ptr, 0, 4));
While there are some checks to catch invalid pointers, this is a difficult thing to do safely. Passing an invalid pointer can crash the program and reading beyond the bounds of the pointer will crash the program or cause undefined behavior. Use with care!
The pointer to the C string
Optional
byteOffset: numberbytes to skip before reading
Optional
byteLength: numberbytes to read
Optional
byteOptional
byteThe ptr to the C string
This CString
instance is a clone of the string, so it
is safe to continue using this instance after the ptr
has been
freed.
Get the ptr as an ArrayBuffer
null
or empty ptrs returns an ArrayBuffer
with byteLength
0
Generated using TypeDoc
Get a string from a UTF-8 encoded C string If
byteLength
is not provided, the string is assumed to be null-terminated.Example
Example
While there are some checks to catch invalid pointers, this is a difficult thing to do safely. Passing an invalid pointer can crash the program and reading beyond the bounds of the pointer will crash the program or cause undefined behavior. Use with care!