void Variable::operator/=(const Variable &aVariable) { if (aVariable.getFloat() == 0.f || !aVariable.getInteger()) { throw "DIVISION BY ZERO"; } if (type == INT) { valueInteger /= aVariable.getInteger(); } else if (type == FLOAT) { valueFloat /= aVariable.getFloat(); } }
void Variable::operator*=(const Variable &aVariable) { if (type == INT) { valueInteger *= aVariable.getInteger(); } else if (type == FLOAT) { valueFloat *= aVariable.getFloat(); } }
void Stack::pushVariable(const Variable &var) { switch (var.getType()) { case kTypeNil: pushNil(); break; case kTypeBoolean: pushBoolean(var.getBool()); break; case kTypeNumber: pushFloat(var.getFloat()); break; case kTypeString: pushString(var.getString()); break; case kTypeTable: pushTable(var.getTable()); break; case kTypeFunction: pushFunction(var.getFunction()); break; case kTypeUserType: pushRawUserType(var.getRawUserType(), var.getExactType()); break; default: warning("Pushing a varible of type \"%s\" not supported", var.getExactType().c_str()); break; } }
Variable::commandPrompResults Variable::CompareWith(const Variable &aVariable) const { Variable::Type type = aVariable.getType(); if (type == FLOAT || type == FLOAT) { return CompareWithFloat(aVariable.getFloat()); } else if (type == INT && type == INT) { return CompareWithInt(aVariable.getInteger()); } else if (type == STRING || type == STRING) { return CompareWithString(aVariable.getString()); } return UNDEFCMP; }
void Variable::operator=(const Variable &aVariable) { Variable::Type type = aVariable.getType(); if (type == INT) { set(aVariable.getInteger()); } else if (type == FLOAT) { set(aVariable.getFloat()); } else if (type == STRING) { set(aVariable.getString()); } else { clear(); } }