Class CString

Get a string from a UTF-8 encoded C string If byteLength is not provided, the string is assumed to be null-terminated.

Example

var ptr = lib.symbols.getVersion();
console.log(new CString(ptr));

Example

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!

Hierarchy

  • String
    • CString

Constructors

Properties

Accessors

Constructors

  • Get a string from a UTF-8 encoded C string If byteLength is not provided, the string is assumed to be null-terminated.

    Example

    var ptr = lib.symbols.getVersion();
    console.log(new CString(ptr));

    Example

    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!

    Parameters

    • ptr: number

      The pointer to the C string

    • Optional byteOffset: number

      bytes to skip before reading

    • Optional byteLength: number

      bytes to read

    Returns CString

Properties

byteLength?: number
byteOffset?: number
ptr: number

The 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.

Accessors

  • get arrayBuffer(): ArrayBuffer
  • Get the ptr as an ArrayBuffer

    null or empty ptrs returns an ArrayBuffer with byteLength 0

    Returns ArrayBuffer

Generated using TypeDoc