Esempio n. 1
0
void fxSerializeJSONNumber(txMachine* the, txJSONSerializer* theSerializer, txNumber theNumber)
{
	int fpclass = c_fpclassify(theNumber);
	if ((fpclass != FP_NAN) && (fpclass != FP_INFINITE)) {
		char aBuffer[256];
		fxNumberToString(the, theNumber, aBuffer, sizeof(aBuffer), 0, 0);
		fxSerializeJSONChars(the, theSerializer, aBuffer);
	}
	else
		fxSerializeJSONChars(the, theSerializer, "null");
}
Esempio n. 2
0
void fx_Number_prototype_toPrecision(txMachine* the)
{
	char buffer[256];
	int precision;
	txSlot* slot = fxCheckNumber(the, mxThis);
	if (!slot) mxTypeError("this is no number");
	if (mxArgc > 0) 
		precision = fxToInteger(the, mxArgv(0));
	else	
		precision = 0;
	fxNumberToString(the->dtoa, slot->value.number, buffer, sizeof(buffer), 'g', precision);
	fxCopyStringC(the, mxResult, buffer);
}
Esempio n. 3
0
void fx_Number_toPrecision(txMachine* the)
{
	txSlot* aNumber;
	txSlot* aProperty;
	int aPrecision;
	char aBuffer[256];
	
	aNumber = fxGetInstance(the, mxThis);
	mxCheckNumber(aNumber);
	aProperty = aNumber->next;
	if (mxArgc > 0) 
		aPrecision = fxToInteger(the, mxArgv(0));
	else	
		aPrecision = 0;
	fxNumberToString(the, aProperty->value.number, aBuffer, sizeof(aBuffer), 'g', aPrecision);
	fxCopyStringC(the, mxResult, aBuffer);
}
Esempio n. 4
0
txString fxToString(txMachine* the, txSlot* theSlot)
{
	char aBuffer[256];
again:
	switch (theSlot->kind) {
	case XS_UNDEFINED_KIND:
		fxCopyStringC(the, theSlot, "undefined");
		break;
	case XS_NULL_KIND:
		fxCopyStringC(the, theSlot, "null");
		break;
	case XS_BOOLEAN_KIND:
		if (theSlot->value.boolean == 0)
			fxCopyStringC(the, theSlot, "false");
		else
			fxCopyStringC(the, theSlot, "true");
		break;
	case XS_INTEGER_KIND:
		fxCopyStringC(the, theSlot, fxIntegerToString(the->dtoa, theSlot->value.integer, aBuffer, sizeof(aBuffer)));
		break;
	case XS_NUMBER_KIND:
		fxCopyStringC(the, theSlot, fxNumberToString(the->dtoa, theSlot->value.number, aBuffer, sizeof(aBuffer), 0, 0));
		break;
	case XS_SYMBOL_KIND:
		mxTypeError("Cannot coerce symbol to string");
		break;
	case XS_STRING_KIND:
	case XS_STRING_X_KIND:
		break;
	case XS_REFERENCE_KIND:
		fxToPrimitive(the, theSlot, XS_STRING_HINT);
		goto again;
	default:
		mxTypeError("Cannot coerce to string");
		break;
	}
	return theSlot->value.string;
}
Esempio n. 5
0
void fxKeyAt(txMachine* the, txID id, txIndex index, txSlot* slot)
{
	if (id) {
		txSlot* key = fxGetKey(the, id);
		if (key && (key->flag & XS_DONT_ENUM_FLAG)) {
			if (key->kind == XS_KEY_KIND) {
				slot->kind = XS_STRING_KIND;
				slot->value.string = key->value.key.string;
			}
			else{
				slot->kind = XS_STRING_X_KIND;
				slot->value.string = key->value.key.string;
			}
		}
		else {
			slot->kind = XS_SYMBOL_KIND;
			slot->value.symbol = id;
		}
	}
	else {
		char buffer[16];
		fxCopyStringC(the, slot, fxNumberToString(the->dtoa, index, buffer, sizeof(buffer), 0, 0));
	}
}