static int syck_load(lua_State *L) { struct parser_xtra *bonus; SyckParser *parser; SYMID v; int obj; if (!luaL_checkstring(L, 1)) luaL_typerror(L, 1, "string"); parser = syck_new_parser(); parser->bonus = S_ALLOC_N(struct parser_xtra, 1); bonus = (struct parser_xtra *)parser->bonus; bonus->orig = L; bonus->L = lua_newthread(L); syck_parser_str(parser, (char *)lua_tostring(L, 1), lua_strlen(L, 1), NULL); syck_parser_handler(parser, lua_syck_parser_handler); syck_parser_error_handler(parser, lua_syck_error_handler); v = syck_parse(parser); syck_lookup_sym(parser, v, (char **)&obj); syck_free_parser(parser); lua_pop(L,1); //pop the thread, we don't need it anymore. lua_xmove(bonus->L, L, 1); if ( parser->bonus != NULL ) S_FREE( parser->bonus ); return 1; }
rpmSyck rpmSyckLoad(char *yaml) { SyckParser *parser; SYMID v; rpmSyck rs; rs = rpmSyckCreate(); parser = syck_new_parser(); syck_parser_str_auto(parser, yaml, NULL); syck_parser_handler(parser, rpmsyck_parse_handler); syck_parser_error_handler(parser, NULL); syck_parser_implicit_typing(parser, 1); syck_parser_taguri_expansion(parser, 1); if((v = syck_parse(parser))) syck_lookup_sym( parser, v, (char **)&rs->firstNode); rs->syms = parser->syms; parser->syms = NULL; syck_free_parser(parser); return rs; }