1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* Copyright (c) 2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef MJS_CONVERSION_H_
#define MJS_CONVERSION_H_
#include "mjs_internal.h"
#include "mjs_core.h"
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* Tries to convert `mjs_val_t` to a string, returns MJS_OK if successful.
* String is returned as a pair of pointers: `char **p, size_t *sizep`.
*
* Caller must also provide a non-null `need_free`, and if it is non-zero,
* then the string `*p` should be freed by the caller.
*
* MJS does not support `toString()` and `valueOf()`, so, passing an object
* always results in `MJS_TYPE_ERROR`.
*/
MJS_PRIVATE mjs_err_t mjs_to_string(struct mjs *mjs, mjs_val_t *v, char **p,
size_t *sizep, int *need_free);
/*
* Converts value to boolean as in the expression `if (v)`.
*/
MJS_PRIVATE mjs_val_t mjs_to_boolean_v(struct mjs *mjs, mjs_val_t v);
MJS_PRIVATE int mjs_is_truthy(struct mjs *mjs, mjs_val_t v);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* MJS_CONVERSION_H_ */