Skip to main content

BrighterScript

BrighterScript is a superset of Roku's BrightScript language. It adds features like classes, namespaces, imports, enums and type annotations, and compiles them down to plain BrightScript, so your code runs on every Roku device with nothing extra to install.

The compiler is useful even if you never write a line of BrighterScript. It validates entire BrightScript projects too, so you find syntax errors, typos and calls to missing functions on your machine instead of on a device.

Why BrighterScript?​

  • Catch errors before you sideload. The compiler checks your whole project at once, including the script references between your XML components and code files, and reports problems with their exact location.
  • Write less boilerplate. Classes, namespaces, imports, template strings and modern operators cut out the repetitive code that BrightScript requires.
  • Adopt it a file at a time. Every BrightScript file is already valid BrighterScript. Rename a file from .brs to .bs when you want the new features, and leave the rest alone.
  • Great editor support. The BrightScript Language extension for VS Code uses this compiler for real-time errors, completions, go-to-definition and more.
  • Extend it. Plugins can add your own validations or rewrite code as it compiles.

A quick look​

Here's a small BrighterScript program:

namespace catalog
    class Movie
        title as string
        rating as dynamic

        sub new(title as string, rating = invalid)
            m.title = title
            m.rating = rating
        end sub

        function describe() as string
            rating = m.rating ?? "not rated"
            return `${m.title} (${rating})`
        end function
    end class
end namespace

sub main()
    movie = new catalog.Movie("Big Buck Bunny")
    print movie.describe()
end sub
View the transpiled BrightScript code
sub __catalog_Movie_method_new(title as string, rating = invalid)
    m.title = invalid
    m.rating = invalid
    m.title = title
    m.rating = rating
end sub
function __catalog_Movie_method_describe() as string
    rating = m.rating
    if rating = invalid then
        rating = "not rated"
    end if
    return (bslib_toString(m.title) + " (" + bslib_toString(rating) + ")")
end function
function __catalog_Movie_builder()
    instance = {}
    instance.new = __catalog_Movie_method_new
    instance.describe = __catalog_Movie_method_describe
    return instance
end function
function catalog_Movie(title as string, rating = invalid)
    instance = __catalog_Movie_builder()
    instance.new(title, rating)
    return instance
end function

sub main()
    movie = catalog_Movie("Big Buck Bunny")
    print movie.describe()
end sub

Language features​

Used by​

BrighterScript is used to build apps for Roku by teams like these. It also powers the BrightScript Language extension for VS Code and the maestro framework.

fubo Inverted Solutions Applicaster REDspace Tantawowa CorcoPlus Digital Picture Frame Haystack TV TKSS Software Inc

Using BrighterScript in your project? Open an issue to have your logo added.

Get help​