print ascii code of a character (ktoi)

This commit is contained in:
2021-05-15 00:02:06 +02:00
parent cdfcc753e4
commit 09250861d9
4 changed files with 20 additions and 7 deletions

6
ml.cpp
View File

@@ -248,7 +248,8 @@ MlValue MlValue::cast_to_int() const {
return *this;
case FLOAT:
return MlValue(long(stack_data.f));
// Only ints and floats can be cast to an int
case STRING:
return MlValue(std::stol(str));
default:
throw MlError(*this, MlEnvironment(), BAD_CAST);
}
@@ -261,7 +262,8 @@ MlValue MlValue::cast_to_float() const {
return *this;
case INT:
return MlValue(float(stack_data.i));
// Only ints and floats can be cast to a float
case STRING:
return MlValue(std::stod(str));
default:
throw MlError(*this, MlEnvironment(), BAD_CAST);
}