|
void | tf_util_register (JSContext *context) |
|
JSValue | tf_util_utf8_decode (JSContext *context, JSValue value) |
|
uint8_t * | tf_util_try_get_array_buffer (JSContext *context, size_t *psize, JSValueConst obj) |
|
JSValue | tf_util_try_get_typed_array_buffer (JSContext *context, JSValueConst obj, size_t *pbyte_offset, size_t *pbyte_length, size_t *pbytes_per_element) |
|
bool | tf_util_report_error (JSContext *context, JSValue value) |
|
int | tf_util_get_length (JSContext *context, JSValue value) |
|
int | tf_util_insert_index (const void *key, const void *base, size_t count, size_t size, int(*compare)(const void *, const void *)) |
|
JSValue | tf_util_new_uint8_array (JSContext *context, const uint8_t *data, size_t size) |
|
size_t | tf_base64_encode (const uint8_t *source, size_t source_length, char *out, size_t out_length) |
|
size_t | tf_base64_decode (const char *source, size_t source_length, uint8_t *out, size_t out_length) |
|
int | tf_util_backtrace (void **buffer, int count) |
|
const char * | tf_util_backtrace_to_string (void *const *buffer, int count) |
|
const char * | tf_util_backtrace_string () |
|
void | tf_util_print_backtrace () |
|
const char * | tf_util_function_to_string (void *function) |
|
bool | tf_util_get_default_global_setting_bool (const char *name) |
|
int | tf_util_get_default_global_setting_int (const char *name) |
|
const char * | tf_util_get_default_global_setting_string (const char *name) |
|
tf_setting_kind_t | tf_util_get_global_setting_kind (const char *name) |
|
void | tf_util_document_settings (const char *line_prefix) |
|
bool | tf_util_is_mobile () |
|
size_t | tf_string_set (char *buffer, size_t size, const char *string) |
|
This is becoming just a dumping ground of small helpers.
◆ tf_countof
#define tf_countof |
( |
|
a | ) |
((int)(sizeof((a)) / sizeof(*(a)))) |
Get the number of elements in an array.
- Parameters
-
- Returns
- The number of array elements.
◆ tf_max
Value: ({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a > _b ? _a : _b; \
})
Get the maximum of two values.
- Parameters
-
a | The first value. |
b | The second value. |
- Returns
- The maximum of a and b.
◆ tf_min
Value: ({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a > _b ? _b : _a; \
})
Get the minimum of two values.
- Parameters
-
a | The first value. |
b | The second value. |
- Returns
- The minimum of a and b.
◆ tf_setting_kind_t
◆ uv_loop_t
◆ _tf_setting_kind_t
◆ tf_base64_decode()
size_t tf_base64_decode |
( |
const char * |
source, |
|
|
size_t |
source_length, |
|
|
uint8_t * |
out, |
|
|
size_t |
out_length |
|
) |
| |
Base64-decode data.
- Parameters
-
| source | The source data. |
| source_length | The length of the source data. |
[out] | out | A buffer to receipve the decoded data. |
| out_length | The size of the buffer to receive decoded data. |
- Returns
- The size of the decoded data.
◆ tf_base64_encode()
size_t tf_base64_encode |
( |
const uint8_t * |
source, |
|
|
size_t |
source_length, |
|
|
char * |
out, |
|
|
size_t |
out_length |
|
) |
| |
Base64-encode data.
- Parameters
-
| source | The source data. |
| source_length | The length of the source data. |
[out] | out | A buffer to receive the encoded data. |
| out_length | The size of the buffer to receive encoded data. |
- Returns
- The size of the encoded data.
◆ tf_string_set()
size_t tf_string_set |
( |
char * |
buffer, |
|
|
size_t |
size, |
|
|
const char * |
string |
|
) |
| |
Populate a string buffer, truncating if necessary.
- Parameters
-
buffer | The buffer. |
size | The size of the buffer. |
string | The value to set. |
- Returns
- The number of bytes set, not including the NULL terminator.
◆ tf_util_backtrace()
int tf_util_backtrace |
( |
void ** |
buffer, |
|
|
int |
count |
|
) |
| |
Capture a stack backtrace of the calling thread.
- Parameters
-
[out] | buffer | A buffer with at least count element to receive the backtrace. |
| count | The size of buffer. |
- Returns
- The numbef of captured frames.
◆ tf_util_backtrace_string()
const char * tf_util_backtrace_string |
( |
| ) |
|
Capture a stack backtrace of the calling thread and convert it immediately to string.
- Returns
- A string representation of the stack backtrace with function names, files, and line numbers, as possible. Must be freed with tf_free() by the caller.
◆ tf_util_backtrace_to_string()
const char * tf_util_backtrace_to_string |
( |
void *const * |
buffer, |
|
|
int |
count |
|
) |
| |
Convert a stack backtrace to string.
- Parameters
-
buffer | A stack backtrace. |
count | The number of elements in the backtrace. |
- Returns
- A string representation of the stack backtrace with function names, files, and line numbers, as possible. Must be freed with tf_free() by the caller.
◆ tf_util_document_settings()
void tf_util_document_settings |
( |
const char * |
line_prefix | ) |
|
Log documentation for the available settings.
- Parameters
-
line_prefix | Text to prefix each line with." |
◆ tf_util_function_to_string()
const char * tf_util_function_to_string |
( |
void * |
function | ) |
|
Convert a function pointer to its name, if possible.
- Returns
- The function name or null.
◆ tf_util_get_default_global_setting_bool()
bool tf_util_get_default_global_setting_bool |
( |
const char * |
name | ) |
|
Get the default value of a global setting as a boolean.
- Parameters
-
- Returns
- The default value.
◆ tf_util_get_default_global_setting_int()
int tf_util_get_default_global_setting_int |
( |
const char * |
name | ) |
|
Get the default value of a global setting as an integer.
- Parameters
-
- Returns
- The default value.
◆ tf_util_get_default_global_setting_string()
const char * tf_util_get_default_global_setting_string |
( |
const char * |
name | ) |
|
Get the default value of a global setting as a string.
- Parameters
-
- Returns
- The default value.
◆ tf_util_get_global_setting_kind()
Get the expected kind of a global setting.
- Parameters
-
- Returns
- The setting kind or unknown if nonexistent.
◆ tf_util_get_length()
int tf_util_get_length |
( |
JSContext * |
context, |
|
|
JSValue |
value |
|
) |
| |
Get the length of an array.
- Parameters
-
context | The JS context. |
value | An array with a "length" field. |
- Returns
- The array's length.
◆ tf_util_insert_index()
int tf_util_insert_index |
( |
const void * |
key, |
|
|
const void * |
base, |
|
|
size_t |
count, |
|
|
size_t |
size, |
|
|
int(*)(const void *, const void *) |
compare |
|
) |
| |
Get the index at which to insert into an array in order to preserve sorted order.
- Parameters
-
key | The key being inserted. |
base | The beginning of the array. |
count | The number of elements in the array. |
size | The size of a single element of the array. |
compare | A comparison function comparing key and an element of the array. |
- Returns
- The index at which to insert key in the array, between 0 and count inclusive.
◆ tf_util_is_mobile()
bool tf_util_is_mobile |
( |
| ) |
|
Check if the app is running on a mobile device.
- Returns
- true for iPhone/Android, false otherwise.
◆ tf_util_new_uint8_array()
JSValue tf_util_new_uint8_array |
( |
JSContext * |
context, |
|
|
const uint8_t * |
data, |
|
|
size_t |
size |
|
) |
| |
Create a Uint8Array from bytes.
- Parameters
-
context | The JS context. |
data | The bytes. |
size | The number of bytes in data. |
- Returns
- The created array.
◆ tf_util_print_backtrace()
void tf_util_print_backtrace |
( |
| ) |
|
Print a stack backtrace of the calling thread.
◆ tf_util_register()
Register utility script functions.
- Parameters
-
◆ tf_util_report_error()
bool tf_util_report_error |
( |
JSContext * |
context, |
|
|
JSValue |
value |
|
) |
| |
Print an error and message the owning task if possible.
- Parameters
-
context | The JS context. |
value | The value which might be an exception. |
- Returns
- true If the value was an exception and an error was reported.
◆ tf_util_try_get_array_buffer()
uint8_t * tf_util_try_get_array_buffer |
( |
JSContext * |
context, |
|
|
size_t * |
psize, |
|
|
JSValueConst |
obj |
|
) |
| |
Get the data from what might be an ArrayBuffer.
- Parameters
-
| context | The JS context. |
[out] | psize | The size of the data in bytes. |
| obj | The object which might be an ArrayBuffer. |
- Returns
- The ArrayBuffer's data.
◆ tf_util_try_get_typed_array_buffer()
JSValue tf_util_try_get_typed_array_buffer |
( |
JSContext * |
context, |
|
|
JSValueConst |
obj, |
|
|
size_t * |
pbyte_offset, |
|
|
size_t * |
pbyte_length, |
|
|
size_t * |
pbytes_per_element |
|
) |
| |
Get the ArrayBuffer from what might be a typed ArrayBuffer.
- Parameters
-
| context | The JS context. |
| obj | The object which might be a typed ArrayBuffer. |
[out] | pbyte_offset | The offset into the buffer at which the typed ArrayBuffer starts. |
[out] | pbyte_length | The length of the buffer. |
[out] | pbytes_per_element | Element size in bytes. |
- Returns
- An ArrayBuffer if obj was a typed ArrayBuffer.
◆ tf_util_utf8_decode()
JSValue tf_util_utf8_decode |
( |
JSContext * |
context, |
|
|
JSValue |
value |
|
) |
| |
Convert UTF-8 bytes in a buffer or Uint8Array or similar to a String.
- Parameters
-
context | The JS context. |
value | The UTF-8 bytes. |
- Returns
- A string representation of the data interpreted as UTF-8 bytes.