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 emitter_xtra, 1); bonus = (struct parser_xtra *)parser->bonus; 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); v = syck_parse(parser); syck_lookup_sym(parser, v, (void *)&obj); syck_free_parser(parser); lua_xmove(bonus->L, L, 1); return 1; }
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; }
static JSBool syck_load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { SyckParser *parser = syck_new_parser(); struct parser_xtra *bonus = xcalloc(1, sizeof(*bonus)); SYMID v; int sobj; char * s = NULL; JSBool ok = JS_FALSE; if (_debug) fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx, obj, argv, (unsigned)argc, rval); ok = JS_ConvertArguments(cx, argc, argv, "s", &s); if (!ok) goto exit; #ifdef NOTYET bonus->L = lua_newthread(L); #endif parser->bonus = bonus; syck_parser_str(parser, s, strlen(s), NULL); syck_parser_handler(parser, js_syck_parser_handler); v = syck_parse(parser); syck_lookup_sym(parser, v, (char **)&sobj); #ifdef NOTYET lua_xmove(bonus->L, L, 1); #endif ok = JS_TRUE; exit: syck_free_parser(parser); return ok; }