void fx_JSON_parse(txMachine* the) { txSlot* aSlot; txStringCStream aCStream; txStringStream aStream; aSlot = fxGetInstance(the, mxThis); if (aSlot->flag & XS_SANDBOX_FLAG) the->frame->flag |= XS_SANDBOX_FLAG; else the->frame->flag |= the->frame->next->flag & XS_SANDBOX_FLAG; if (mxArgc < 1) mxDebug0(the, XS_SYNTAX_ERROR, "JSON.parse: no buffer"); aSlot = fxGetInstance(the, mxArgv(0)); if (mxIsChunk(aSlot)) { aSlot = aSlot->next; aCStream.buffer = aSlot->value.host.data; aCStream.size = aSlot->next->value.integer; aCStream.offset = 0; fxParseJSON(the, &aCStream, fxStringCGetter); } else { fxToString(the, mxArgv(0)); aStream.slot = mxArgv(0); aStream.size = c_strlen(aStream.slot->value.string); aStream.offset = 0; fxParseJSON(the, &aStream, fxStringGetter); } *mxResult = *(the->stack++); }
void fx_JSON_parse(txMachine* the) { volatile txJSONParser* aParser = C_NULL; txSlot* slot; mxTry(the) { if (mxArgc < 1) mxSyntaxError("no buffer"); aParser = c_malloc(sizeof(txJSONParser)); if (NULL == aParser) mxUnknownError("out of memory"); c_memset((txJSONParser*)aParser, 0, sizeof(txJSONParser)); if (mxArgc > 1) { slot = mxArgv(1); if (slot->kind == XS_REFERENCE_KIND) { slot = slot->value.reference; if (slot->next && ((slot->next->kind == XS_CODE_KIND) || (slot->next->kind == XS_CODE_X_KIND) || (slot->next->kind == XS_CALLBACK_KIND))) aParser->reviver = slot; } } slot = mxArgv(0); if (slot->kind == XS_REFERENCE_KIND) { slot = slot->value.reference->next; if (slot && (slot->flag & XS_INTERNAL_FLAG) && (slot->kind == XS_HOST_KIND)) { aParser->data = slot->value.host.data; aParser->offset = 0; mxPushSlot(mxArgv(0)); fxGetID(the, mxID(_length)); aParser->size = fxToInteger(the, the->stack++); } } if (!aParser->data) { fxToString(the, mxArgv(0)); aParser->slot = mxArgv(0); aParser->offset = 0; aParser->size = c_strlen(aParser->slot->value.string); } fxParseJSON(the, (txJSONParser*)aParser); mxPullSlot(mxResult); c_free((txJSONParser*)aParser); // @@ reviver } mxCatch(the) { if (aParser) c_free((txJSONParser*)aParser); fxJump(the); } }