定义一个NaN的数据类型
本帖最后由 HeavenZone 于 2025-4-8 09:43 编辑aardio有必要定义这么一个NaN吗?还是已经有类似的?
import console.int;
var NaN = {
show = false;
@{
_type = "number";
_get = function() {
return "NaN"
};
_tostring = function(show) {
if(owner.show) {
return "NaN";
}
if(show) {
return "NaN";
}
return ""
};
_add = function(b) { return owner;}
_sub = function(b) { return owner;}
_mul = function(b) { return owner;}
_div = function(b) { return owner;}
_mod = function(b) { return owner;}
_pow = function(b) { return owner;}
_unm = function(b) { return owner;}
_len = function() {return 0;}
_tonumber = function() { return 0; }
_concat = function(b) {
return tostring(owner) ++ b
}
};
}
console.log("NaN =",NaN)
console.log("NaN len = ",#NaN)
console.log(" =============================")
console.log("NaN tostring =", tostring(NaN))
console.log("NaN tostring show =", tostring(NaN, true))
console.log("NaN tonumber =", tonumber(NaN))
console.log(" =============================")
console.log( type(NaN) )
console.log(type.rget(NaN) == type.number)
console.log(type.rget(NaN))
console.log(" =============================")
var test2 = NaN + 2 -3
console.log("test 2 = ", tostring(test2, 1 ))
console.log("test 2 = ", NaN ++ "a")
console.log(" =============================")
NaN.show = true;
console.log("NaN.show = true: NaN tostring =", tostring(NaN))
console.log("NaN.show = true: test 2 = ", NaN ++ "a")
console.log(" =============================")
NaN.show = false;
console.log("NaN.show = false: NaN tostring =", tostring(NaN))
console.log("NaN.show = false: test 2 = ", NaN ++ "a")
输出
NaN =
NaN len = 0
=============================
NaN tostring =
NaN tostring show = NaN
NaN tonumber =0
=============================
table number
true
number
=============================
test 2 = NaN
test 2 = a
=============================
NaN.show = true: NaN tostring = NaN
NaN.show = true: test 2 = NaNa
=============================
NaN.show = false: NaN tostring =
NaN.show = false: test 2 = a
请按任意键继续 ...
页:
[1]