void init(void) { parser_init(); lispy = parser_get(); env = lenv_new(); builtins_init(env); _parse("(def {nil} {})"); _parse("(def {true} 1)"); _parse("(def {otherwise} true)"); _parse( "(def {function} (lambda {args body} {\ def (head args) (lambda (tail args) body)\ }))"
static int lyajl_complete_parse (lua_State *L) { yajl_status stat; luvit_parser_t *parser = parser_get(L, 1); /* Process the args */ stat = yajl_complete_parse(parser->handle); /* Unreference the callback */ luaL_unref(L, LUA_REGISTRYINDEX, parser->ref->r); if (stat != yajl_status_ok) { unsigned char * str = yajl_get_error(parser->handle, 1, (const unsigned char*)0, 0); luaL_error(L, (const char *) str); yajl_free_error(parser->handle, str); /* This doesn't actually happen */ } return 0; }
int image_load(const char *path, struct format *output_format, struct fb_image *image) { int fd = 0; int err = 0; char *buf = NULL; size_t len = 0; struct stat stat; parser parse_func; if (NULL == path) return VMM_EFAIL; if (0 > (fd = vfs_open(path, O_RDONLY, 0))) return fd; if (VMM_OK != (err = vfs_fstat(fd, &stat))) { goto out; } if (NULL == (buf = vmm_malloc(stat.st_size))) { err = VMM_ENOMEM; goto out; } len = vfs_read(fd, buf, stat.st_size); if (NULL == (parse_func = parser_get(buf, len))) { vmm_printf("Unsupported format\n"); err = VMM_EFAIL; goto out; } err = parse_func(buf, len, image, output_format); out: if ((VMM_OK != err) && buf) vmm_free(buf); if (fd >= 0) vfs_close(fd); return err; }
static int lyajl_parse (lua_State *L) { size_t len; const char *chunk; luvit_parser_t *parser; yajl_status stat; /* Process the args */ parser = parser_get(L, 1); chunk = luaL_checklstring(L, 2, &len); stat = yajl_parse(parser->handle, (const unsigned char*)chunk, len); if (stat != yajl_status_ok) { unsigned char * str = yajl_get_error(parser->handle, 1, (const unsigned char*)chunk, len); luaL_error(L, (const char *) str); yajl_free_error(parser->handle, str); /* This doesn't actually happen */ } return 0; }
static int lyajl_config (lua_State *L) { const char* option; luvit_parser_t *parser = parser_get(L, 1); option = luaL_checkstring(L, 2); if (strcmp(option, "allow_comments") == 0) { yajl_config(parser->handle, yajl_allow_comments, lua_toboolean(L, 3)); } else if (strcmp(option, "dont_validate_strings") == 0) { yajl_config(parser->handle, yajl_dont_validate_strings, lua_toboolean(L, 3)); } else if (strcmp(option, "allow_trailing_garbage") == 0) { yajl_config(parser->handle, yajl_allow_trailing_garbage, lua_toboolean(L, 3)); } else if (strcmp(option, "allow_multiple_values") == 0) { yajl_config(parser->handle, yajl_allow_multiple_values, lua_toboolean(L, 3)); } else if (strcmp(option, "allow_partial_values") == 0) { yajl_config(parser->handle, yajl_allow_partial_values, lua_toboolean(L, 3)); } else { luaL_error(L, "Invalid config option %s", option); } return 0; }
static int lyajl_parser_gc (lua_State *L) { luvit_parser_t *parser = parser_get(L, 1); yajl_free(parser->handle); free(parser->ref); return 0; }