-
Notifications
You must be signed in to change notification settings - Fork 2
/
bslib.brs
48 lines (44 loc) · 1.37 KB
/
bslib.brs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
' bslib: BrightScript runtime functions for the BrighterScript language
' v0.1.1
'
' Convert a value into a string. For non-primitive values, this will return the type instead of its value in most cases.
' @param dynamic value - the value to be turned into a string.
' @return string - the string representation of `value`
'
function toString(value)
valueType = type(value)
'if the var supports `toStr()`
if valueType = "<uninitialized>" then
return valueType
else if value = invalid then
return "<invalid>"
else if GetInterface(value, "ifToStr") <> invalid then
return value.toStr()
else if valueType = "roSGNode"
return "Node(" + value.subType() + ")"
end if
'TODO add class name for objects once we have reflection implemented
'when all else fails, just return the type
return "<" + valueType + ">"
end function
'
' Simple ternary function. Given a condition, return the
' consequent if true, and the alternate if false
'
function ternary(condition, consequent, alternate)
if condition then
return consequent
else
return alternate
end if
end function
'
' Return consequent if consequent is not invalid, otherwise return alternate
'
function coalesce(consequent, alternate)
if consequent <> invalid then
return consequent
else
return alternate
end if
end function