mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Tweaked truthiness, fixed int to float coersion
This commit is contained in:
@@ -194,6 +194,14 @@ bool Toy_checkValueIsTruthy(Toy_Value value) {
|
||||
return value.as.boolean;
|
||||
}
|
||||
|
||||
if (value.type == TOY_VALUE_INTEGER) {
|
||||
return value.as.integer != 0;
|
||||
}
|
||||
|
||||
if (value.type == TOY_VALUE_FLOAT) {
|
||||
return value.as.number != 0.0f;
|
||||
}
|
||||
|
||||
//anything else is truthy
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -203,6 +203,11 @@ static void processDeclare(Toy_VM* vm) {
|
||||
//get the value
|
||||
Toy_Value value = Toy_popStack(&vm->stack);
|
||||
|
||||
//BUGFIX: only allowable type coersion
|
||||
if (type == TOY_VALUE_FLOAT && value.type == TOY_VALUE_INTEGER) {
|
||||
value = TOY_VALUE_FROM_FLOAT( (float)TOY_VALUE_AS_INTEGER(value) );
|
||||
}
|
||||
|
||||
//declare it
|
||||
Toy_declareScope(vm->scope, name, value);
|
||||
|
||||
@@ -223,6 +228,11 @@ static void processAssign(Toy_VM* vm) {
|
||||
return;
|
||||
}
|
||||
|
||||
//BUGFIX: only allowable type coersion
|
||||
if (TOY_VALUE_AS_STRING(name)->name.varType == TOY_VALUE_FLOAT && value.type == TOY_VALUE_INTEGER) {
|
||||
value = TOY_VALUE_FROM_FLOAT( (float)TOY_VALUE_AS_INTEGER(value) );
|
||||
}
|
||||
|
||||
//assign it
|
||||
Toy_assignScope(vm->scope, TOY_VALUE_AS_STRING(name), value); //scope now owns the value, doesn't need to be freed
|
||||
|
||||
|
||||
Reference in New Issue
Block a user