Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7641 views
1
#ifndef js_builtin_h
2
#define js_builtin_h
3
4
void jsB_init(js_State *J);
5
void jsB_initobject(js_State *J);
6
void jsB_initarray(js_State *J);
7
void jsB_initfunction(js_State *J);
8
void jsB_initboolean(js_State *J);
9
void jsB_initnumber(js_State *J);
10
void jsB_initstring(js_State *J);
11
void jsB_initregexp(js_State *J);
12
void jsB_initerror(js_State *J);
13
void jsB_initmath(js_State *J);
14
void jsB_initjson(js_State *J);
15
void jsB_initdate(js_State *J);
16
17
void jsB_propf(js_State *J, const char *name, js_CFunction cfun, int n);
18
void jsB_propn(js_State *J, const char *name, double number);
19
void jsB_props(js_State *J, const char *name, const char *string);
20
21
typedef struct js_Buffer { unsigned int n, m; char s[64]; } js_Buffer;
22
23
static void js_putc(js_State *J, js_Buffer **sbp, int c)
24
{
25
js_Buffer *sb = *sbp;
26
if (!sb) {
27
sb = js_malloc(J, sizeof *sb);
28
sb->n = 0;
29
sb->m = sizeof sb->s;
30
*sbp = sb;
31
} else if (sb->n == sb->m) {
32
sb = js_realloc(J, sb, (sb->m *= 2) + offsetof(js_Buffer, s));
33
*sbp = sb;
34
}
35
sb->s[sb->n++] = c;
36
}
37
38
static inline void js_puts(js_State *J, js_Buffer **sb, const char *s)
39
{
40
while (*s)
41
js_putc(J, sb, *s++);
42
}
43
44
static inline void js_putm(js_State *J, js_Buffer **sb, const char *s, const char *e)
45
{
46
while (s < e)
47
js_putc(J, sb, *s++);
48
}
49
50
#endif
51
52