using Toybox.Application as App;
using Toybox.System as Sys;
function test(val) {
if (val instanceof Toybox.Lang.Number) {
Sys.println(val.toString() + " is a number");
}
else if (val instanceof Toybox.Lang.Long) {
Sys.println(val.toString() + " is a long");
}
else if (val instanceof Toybox.Lang.Double) {
Sys.println(val.toString() + " is a double");
}
else if (val instanceof Toybox.Lang.Float) {
Sys.println(val.toString() + " is a float");
}
else if (val instanceof Toybox.Lang.String) {
Sys.println(val.toString() + " is a string");
}
else if (val instanceof Toybox.Lang.Boolean) {
Sys.println(val.toString() + " is a bool");
}
else {
Sys.println(val.toString() + " is of an unknown type");
}
}
class TestApp extends App.AppBase
{
function onStart() {
return false;
}
function getInitialView() {
test(true);
test(false);
test("abc");
test(123);
test(123l); // what is going on here
test(123f);
test(123d);
test(0x123);
test(0x123l); // what is going on here
// should this be 291 as a Float or 4671 as a Number?
// this is actually 291 as a Number which seems wrong.
test(0x123f);
// should this be 291 as a Double or 4669 as a Number?
// this is actually 291 as a Number which seems wrong.
test(0x123d);
return [ new TestView() ];
}
function onStop() {
return false;
}
}
This is the result I see displayed in the console...
true is a bool
false is a bool
abc is a string
123 is a number
is a long
123.000000 is a float
123.000000 is a double
291 is a number
is a long
291 is a number
291 is a number