Table of Contents
Creates a BrightScript Component of class classname specified. Return invalid if the object creation fails. Some Objects have optional parameters in their constructor that are passed after name.
app_mgr = CreateObject("roAppManager") section = CreateObject("roRegistrySection", "Data")
Returns the type of a variable and/or object. See the BrightScript Component specification for a list of types.
Print type(5) 'returns a 2.1 compatible type Print type("my string", 3) 'return a BrightScript 3 type
Each script has a global Associative Array. It can be fetched with this function.
New in BrightScript 3.
Box() will return an object version of an intrinsic type, or pass through an object if given one.
bo = box("string")
bo = box(bo) ' no change to bo
The Run function can be used to compile and run a script dynamically.
If a string is passed in the filename parameter, the file specified by that path is compiled and run.
If an array of strings is passed in the filename parameter, then all files specified are compiled together, then run.
Arguments may be passed to the script's Main function, and that script may return a result value.
Sub Main() Run("pkg:/test.brs") BreakIfRunError(LINE_NUM) Print Run("test2.brs", "arg 1", "arg 2") if Run(["pkg:/file1.brs","pkg:/file2.brs"])<>4 then stop BreakIfRunError(LINE_NUM) stop End Sub Sub BreakIfRunError(ln) el=GetLastRunCompileError() if el=invalid then el=GetLastRunRuntimeError() if el=&hFC or el=&hE2 then return 'FC==ERR_NORMAL_END, E2=ERR_VALUE_RETURN print "Runtime Error (line ";ln;"): ";el stop else print "compile error (line ";ln;")" for each e in el for each i in e print i;": ";e[i] end for end for stop end if End Sub
Eval() is deprecated effective immediately. Use of Eval() will cause compilation or runtime errors, see Roku Channel Manifest.
Eval can be used to run a code snippet in the context of the current function. It performs a compile, and then the bytecode execution.
If a compilation error occurs, no bytecode execution is performed, and Eval returns an roList with one or more compile errors. Each list entry is an roAssociativeArray with ERRNO and ERRSTR keys describing the error.
If compilation succeeds, bytecode execution is performed and the integer runtime error code is returned. These are the same error codes as returned by GetLastRunRuntimeError().
Eval() can be usefully in two cases. The first is when you need to dynamically generate code at runtime.
The other is if you need to execute a statement that could result in a runtime error, but you don't want code execution to stop.
(Note that 20 = &h14 = ERR_DIV_ZERO = Divide by Zero error).
Returns an roList of compile errors, or invalid if no errors. Each list entry is an roAssociativeArray with the keys: ERRNO, ERRSTR, FILESPEC, and LINENO.
Returns an error code result after the last script Run().
These are normal:
ERR_USE_OF_UNINIT_VAR = &hE9 ERR_DIV_ZERO = &h14 ERR_TM = &h18 ERR_USE_OF_UNINIT_VAR = &hE9 ERR_RO2 = &hF4 ERR_RO4 = &hEC ERR_SYNTAX = 2 ERR_WRONG_NUM_PARAM = &hF1