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
.brsto.bswhen 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 subView 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 subLanguage features
- Imports: declare a script's dependencies in the script itself, instead of in XML
<script>tags. - Namespaces and Classes: organize your code, with inheritance and access modifiers.
- Interfaces, Enums and Constants: name your shapes and values, checked at compile time.
- Template Strings:
print `hello ${name}`. - Ternary, Null-Coalescing and Spread operators:
a ? b : c,a ?? band[...a, ...b]. - Callfunc Operator:
node@.someMethod()instead ofnode.callfunc("someMethod"). - Select Case statements and Exceptions without an exception variable.
- A type system: typed assignments, typecasts, typed arrays, union and intersection types, type statements and function types. You can even type check plain BrightScript with comments.
- Regular Expression Literals, Source Literals, Computed Property Names and Annotations.
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.
Using BrighterScript in your project? Open an issue to have your logo added.
Get help
- Ask questions in the Roku Developers Slack.
- Report bugs and request features in GitHub issues.