BrighterScript

October 21, 2022 ยท View on GitHub

BrighterScript is a superset of Roku's BrightScript language. Its goal is to provide new functionality and enhanced syntax support to enhance the Roku channel developer experience.

See the following pages for more information:

Annotations

'mostly useful for plugins that change code based on annotations
@logOnException()
sub doSomething()
    '...
end

Callfunc Operator

'instead of `node.callfunc("someMethod", 1, 2, 3)`, you can do this:
node@.someMethod(1, 2, 3)

Classes

class Movie
    public title as string
    private _actors = invalid
    public sub getActors()
        if m._actors = invalid
            m._actors = api_get_actors()
        end if
        return m._actors
    end sub
end class

Constants

const API_URL = "https://api.acme.com/v1/"
sub main()
    print API_URL
end sub

Enums

enum RemoteButton
    up = "up"
    down = "down"
    left = "left"
    right = "right"
end enum

Namespaces

namespace util
    function toUpper(value as string)
        return
    end function
end namespace

sub main()
    print util.toUpper("hello world")
end sub

Imports

import "pkg:/source/util.bs"
sub main()
    print util_toUpper("hello world")
end sub

Null-coalescing operator

userSettings = getSettingsFromRegistry() ?? {}

Plugins

Plugins can be used to manipulate code at any point during the program lifecycle.

Regular Expression Literals

print /hello world/ig

Source Literals

print SOURCE_FILE_PATH
print SOURCE_LINE_NUM
print FUNCTION_NAME
print SOURCE_FUNCTION_NAME
print SOURCE_LOCATION
print PKG_PATH
print PKG_LOCATION

Template Strings (Template Literals)

name = `John Smith`

text = `hello ${name}`

text = `first line text
second line text`

Ternary (Conditional) Operator

authStatus = user <> invalid ? "logged in" : "not logged in"