void init_smartjs() { v7_val_t res; if (v7_exec_file(v7, "smart.js", &res) != V7_OK) { printf("smart.js execution: "); v7_println(v7, res); } }
void sj_init_conf(struct v7 *v7, char *conf_str) { int i; const char *names[] = {"sys.json", "user.json"}; v7_val_t conf = v7_create_object(v7); v7_set(v7, v7_get_global_object(v7), "conf", ~0, 0, conf); if (conf_str != NULL) { v7_val_t res; enum v7_err err; /* * Usage of strlen in weird here * but we use snprintf as well. * TODO(alashkin): think about providing len * as function argument AND changing of snprintf to * something else */ size_t len = strlen(conf_str); char *f = (char *) malloc(len + 3); snprintf(f, len + 3, "(%s)", conf_str); /* TODO(mkm): simplify when we'll have a C json parse API */ err = v7_exec(v7, &res, f); free(f); if (err != V7_OK) { printf("exc parsing dev conf: %s\n", f); v7_println(v7, res); } else { v7_set(v7, conf, "dev", ~0, 0, res); } } for (i = 0; i < (int) sizeof(names) / sizeof(names[0]); i++) { const char *name = names[i]; v7_set(v7, conf, name, strlen(name) - 5, 0, load_conf(v7, name)); } }
static void process_js(char *cmd) { s_sjp.char_processor = interrupt_char_processor; v7_val_t v; int res = v7_exec(s_sjp.v7, &v, cmd); if (res == V7_SYNTAX_ERROR) { printf("Syntax error: %s\n", v7_get_parser_error(s_sjp.v7)); } else if (res == V7_STACK_OVERFLOW) { printf("Stack overflow: %s\n", v7_get_parser_error(s_sjp.v7)); } else { if (res == V7_EXEC_EXCEPTION) { printf("Exec error:"); } v7_println(s_sjp.v7, v); #if V7_ENABLE__StackTrace if (res == V7_EXEC_EXCEPTION) { v7_fprint_stack_trace(stdout, s_sjp.v7, v); } #endif } v7_gc(s_sjp.v7, 0 /* full */); }
void init_smartjs() { v7_val_t res; if (v7_exec_file(v7, "sys_init.js", &res) != V7_OK) { printf("Init error: "); v7_println(v7, res); } }
static v7_val_t load_conf(struct v7 *v7, const char *name) { v7_val_t res; char *f; enum v7_err err; f = read_json_file(name); if (f == NULL) { printf("cannot read %s\n", name); return v7_create_object(v7); } err = v7_exec(v7, &res, f); free(f); if (err != V7_OK) { v7_println(v7, res); return v7_create_object(v7); } return res; }