Flipper Zero Firmware
Loading...
Searching...
No Matches
mjs_util_public.h
1/*
2 * Copyright (c) 2016 Cesanta Software Limited
3 * All rights reserved
4 */
5
6#ifndef MJS_UTIL_PUBLIC_H_
7#define MJS_UTIL_PUBLIC_H_
8
9#include "mjs_core_public.h"
10#include <stdio.h>
11
12#if defined(__cplusplus)
13extern "C" {
14#endif /* __cplusplus */
15
16typedef void (*MjsPrintCallback)(void* ctx, const char* format, ...);
17
18const char* mjs_typeof(mjs_val_t v);
19
20void mjs_fprintf(mjs_val_t v, struct mjs* mjs, FILE* fp);
21void mjs_sprintf(mjs_val_t v, struct mjs* mjs, char* buf, size_t buflen);
22
23void mjs_disasm_all(struct mjs* mjs, MjsPrintCallback print_cb, void* print_ctx);
24void mjs_dump(struct mjs* mjs, int do_disasm, MjsPrintCallback print_cb, void* print_ctx);
25
26/*
27 * Returns the filename corresponding to the given bcode offset.
28 */
29const char* mjs_get_bcode_filename_by_offset(struct mjs* mjs, int offset);
30
31/*
32 * Returns the line number corresponding to the given bcode offset.
33 */
34int mjs_get_lineno_by_offset(struct mjs* mjs, int offset);
35
36/*
37 * Returns bcode offset of the corresponding call frame cf_num, where 0 means
38 * the currently executing function, 1 means the first return address, etc.
39 *
40 * If given cf_num is too large, -1 is returned.
41 */
42int mjs_get_offset_by_call_frame_num(struct mjs* mjs, int cf_num);
43
44/*
45 * Tries to convert `mjs_val_t` to a string, returns MJS_OK if successful.
46 * String is returned as a pair of pointers: `char **p, size_t *sizep`.
47 *
48 * Caller must also provide a non-null `need_free`, and if it is non-zero,
49 * then the string `*p` should be freed by the caller.
50 *
51 * MJS does not support `toString()` and `valueOf()`, so, passing an object
52 * always results in `MJS_TYPE_ERROR`.
53 */
54mjs_err_t mjs_to_string(struct mjs* mjs, mjs_val_t* v, char** p, size_t* sizep, int* need_free);
55
56/*
57 * Converts value to boolean as in the expression `if (v)`.
58 */
59mjs_val_t mjs_to_boolean_v(struct mjs* mjs, mjs_val_t v);
60
61int mjs_is_truthy(struct mjs* mjs, mjs_val_t v);
62
63#if defined(__cplusplus)
64}
65#endif /* __cplusplus */
66
67#endif /* MJS_UTIL_PUBLIC_H_ */
Definition mjs_core.h:63