Source Literals
BrightScript provides the LINE_NUM literal, which represents the runtime 1-based line number of the current line of code. In a similar fashion, BrighterScript provides several more source literals.
These source literals are converted into inline variables at transpile-time, so keep in mind that any post-processing to the transpiled files could cause these values to be incorrect.
SOURCE_FILE_PATH
The absolute path to the source file, including a leading file:/ scheme indicator. i.e. "file:/C:/projects/RokuApp/source/main.bs".
print SOURCE_FILE_PATHView the transpiled BrightScript code
print "file" + ":///C:/projects/RokuApp/source/main.bs"note: the literal is concatenated to keep the roku static analysis tool happy
SOURCE_LINE_NUM
The 1-based line number of the source file.
'I am line 1
print SOURCE_LINE_NUM 'I am line 2View the transpiled BrightScript code
'I am line 1
print 2 'I am line 2FUNCTION_NAME
Basic
The name of the current function
function RunFromZombie()
print FUNCTION_NAME
end functionView the transpiled BrightScript code
function RunFromZombie()
print "RunFromZombie"
end functionNamespaced
if the function is contained in a namespace, that name will be included in the function name
namespace Human.Versus.Zombie
function RunFromZombie()
print FUNCTION_NAME
end function
end namespaceView the transpiled BrightScript code
function Human_Versus_Zombie_RunFromZombie()
print "Human_Versus_Zombie_RunFromZombie"
end functionAnonymous Functions
For anonymous functions, FUNCTION_NAME will include the enclosing function name, followed by anon and the index of the function in its parent. If there are multiple nested anonymous functions, each level will have its own anon[index] in the name. Function indexes start at 0 within each enclosing function.
function main()
zombieAttack = function()
print FUNCTION_NAME
end function
humanAttack = function()
useSword = function()
print FUNCTION_NAME
end function
useSword()
end function
end function
namespace Human.Versus.Zombie
function Eat()
print SOURCE_FUNCTION_NAME
findFood = function()
print FUNCTION_NAME
end function
end function
end namespaceView the transpiled BrightScript code
function main()
zombieAttack = function()
print "main$anon0"
end function
humanAttack = function()
useSword = function()
print "main$anon1$anon0"
end function
useSword()
end function
end function
function Human_Versus_Zombie_Eat()
print "Human.Versus.Zombie.Eat"
findFood = function()
print "Human_Versus_Zombie_Eat$anon0"
end function
end functionSOURCE_FUNCTION_NAME
This works the same as FUNCTION_NAME except that it will use a dot in namespace names instead of the transpiled underscores.
namespace Human.Versus.Zombie
function Eat()
print SOURCE_FUNCTION_NAME
findFood = function()
print SOURCE_FUNCTION_NAME
end function
end function
end namespaceView the transpiled BrightScript code
function Human_Versus_Zombie_Eat()
print "Human.Versus.Zombie.Eat"
findFood = function()
print "Human.Versus.Zombie.Eat$anon0"
end function
end functionSOURCE_NAMESPACE_NAME
This works the same as SOURCE_FUNCTION_NAME except that it does not include the function name.
The SOURCE_NAMESPACE_NAME can be a useful string for debug logs and logging filters.
namespace Human.Versus.Zombie
function Eat()
print SOURCE_NAMESPACE_NAME
end function
end namespaceView the transpiled BrightScript code
function Human_Versus_Zombie_Eat()
print "Human.Versus.Zombie"
end functionSOURCE_NAMESPACE_ROOT_NAME
This works the same as SOURCE_NAMESPACE_NAME except that it only includes the lowest-level namespace.
The SOURCE_NAMESPACE_ROOT_NAME can be a useful string for debug logs and logging filters.
namespace Human.Versus.Zombie
function Eat()
print SOURCE_NAMESPACE_ROOT_NAME
end function
end namespaceView the transpiled BrightScript code
function Human_Versus_Zombie_Eat()
print "Human"
end functionSOURCE_LOCATION
A combination of SOURCE_FILE_PATH and SOURCE_LINE_NUM.
function main()
print SOURCE_LOCATION
end functionView the transpiled BrightScript code
function main()
print "file" + ":///C:/projects/RokuApp/source/main.bs:2"
end functionnote: the literal is concatenated to keep the roku static analysis tool happy
PKG_PATH
The pkg path of the file.
function main()
print PKG_PATH
end functionView the transpiled BrightScript code
function main()
print "pkg:/source/main.brs"
end functionPKG_LOCATION
A combination of PKG_PATH and LINE_NUM. Keep in mind, LINE_NUM is a runtime variable provided by Roku.
print PKG_LOCATIONView the transpiled BrightScript code
print "pkg:/source/main.brs:" + str(LINE_NUM)