BRIGHTSCRIPT REFERENCE MANUAL BrightScript version 3.0 Compatible with firmware versions 3.8.x and later BrightSign, LLC. 16780 Lark Ave., Suite B
5 BrightScript Micro Debugger. Enter any BrightScript statement, debug commands, or HELP. BrightScript>
6 BrightScript> ?type(d) String BrightScript> d=1 BrightScript> ?type(d) Integer BrightScript> d=1.0 BrightScript> ?type(d) Float T
7 • Type Float: A number with a decimal (e.g. 2.01), in scientific notation (e.g. 1.23456E+30), or with a Float type designator (e.g. 2!) • Type D
8 Invalid Object Return Many methods (i.e. functions) that return objects can also return Invalid (for example, in cases where there is no object to
9 Division (/) operates using the same rules as above, except that it can never be carried out at the Integer level: When both operators are Integer
10 OPERATORS Operations in the innermost level of parentheses are performed first. Evaluation then proceeds according to the precedence in the follo
11 if a=c and not(b>40) then print "success" On the other hand, if the arguments for these operators are numeric, they will perform bit
12 Associative Arrays When the "." Dot Operator is used on an Associative Array, it is the same as calling the Lookup() or AddReplace() me
13 array=CreateObject("roArray", 10, true) array[2]="two" print array[2] fivevar=five print fivevar() array[1]=fivevar print
14 a=5 If a=5 then print "a is 5" Unlike the C language, BrightScript does not support use of the = assignment operator inside an expressi
TABLE OF CONTENTS Introduction ...
15 OBJECTS, INTERFACES, AND LANGUAGE INTEGRATION BrightScript Objects Though BrightScript operates independently of its object architecture and libr
16 (-5).tostr() if type(5.tostr())<> "String" then stop if (-5).tostr()<>"-5" then stop if (1+2).tostr()<>&qu
17 Interfaces Interfaces in BrightScript operate similarly to Java or Microsoft COM: An interface is a known set of member functions that implement
18 Expression Parsing Any expression that expects a certain type of variable—including Integer, Float, Double, Boolean, or String—can accept an obje
19 • When applied to XML, which is technically case sensitive, the Dot Operator is still case insensitive. If you wish to perform a case-sensitive
20 The following will return an roXMLElement reference to the first photo (id="3131875696"): ? rsp.photos.photo[0] The following will retu
21 Function GetInterestingnessPhotoList(http as Object, page=1 As Integer) As Object print "page=";page http.SetUrl("http://a
22 End Function REM REM newPhotoFromXML REM REM Takes an roXMLElement Object that is an <photo> ... </photo> REM Returns an brs
23 if m.owner<>invalid return m.owner return m.xml@owner End Function Function pGetURL() As String a=m.xml.GetAttributes() url="
24 GARBAGE COLLECTION BrightScript automatically frees strings when they are no longer used, and it will free objects when their reference count goe
Equals Operator ...
25 EVENTS Events in BrightScript center around an event loop and the roMessagePort object. Most BrightScript objects can post to a message port in t
26 end while Note that these two lines, while true msg=wait(0, p) Can be replaced using the following (and substituting end while with end for):
27 THREADING MODEL BrightScript runs in a single thread. In general, BrightScript object calls are synchronous if they return quickly, and asynchron
28 SCOPE BrightScript uses the following scoping rules: • Global variables are not supported; however, there is a single hard-coded global variable
29 INTRINSIC OBJECTS In general, this manual uses the term “object” to refer to “BrightScript components”, which are C or C++ components with interf
30 PROGRAM STATEMENTS BrightScript supports the following statement types. The syntax of each statement is documented in more detail later in this c
31 cavemen.push("betty") for each caveman in cavemen print caveman end for End Function Statement Syntax Each line may contain
32 Example: The first statement will include a library in the same folder as the script, while the second will include a library in a sub-folder. L
33 For x = 1 To 5 For y = 1 To 4 For z = 1 To 6 c[x, y, z] = k k = k + 1 End for End for End for k=0 Fo
34 Example: In each of the following lines, the variable on the left side of the equals operator is assigned the value of the constant or expression
RETURN ...
35 RETURN RETURN expression The RETURN statement returns from a function back to its caller. If the function is not type Void, RETURN can also retu
36 Example: > x=5:print 25; "is equal to"; x ^2 > run 25 is equal to 25 Example: > a$="string" > print a$;a$,a$;&q
37 A trailing semicolon overrides the cursor-return so that the next PRINT statement begins where the last left off. If no trailing punctuation is u
38 POS(x) This statement returns an integer that indicates the current cursor position from 0 to the maximum width of the window. This statement req
39 When program flow reaches the END FOR statement, the counter is incremented by the specified increment amount (or decremented if increment is a
40 For each n in aa Print n;aa[n] aa.delete[n] end for WHILE / EXIT WHILE WHILE expression / EXIT WHILE A WHILE loop executes until the speci
41 Note: This is the single-line form of the IF THEN ELSE statement; see the next section for more details about the block form of the IF THEN ELSE
42 ElseIf BooleanExpression [ Then ] [ Block ] ElseStatement ::= Else [ Block ] Example: vp_msg_loop: msg=wait(tiut, p)
43 endif goto vp_msg_loop Function() As Type / End Function Function name(parameter As Type, …) As Type Note: Each function has it
44 • Integer • Float • Double • String • Object • Dynamic Example: Function cat(a, b) Return a+b 'a, b could be numbers or strings E
Appendix B – Reserved Words ... 58 Appendix C – Example Script
45 End Function “m” Identifier If a function is called from an associative array, then the local variable m is set to the associative array in which
46 Anonymous Functions A function without a name declaration is considered anonymous. Example: The following is a simple anonymous function declara
47 q.starring(myobj, myxml)
48 BUILT-IN FUNCTIONS BrightScript features a set of built-in, module-scope, intrinsic functions. A number of file I/O, string, mathematics, and sys
49 Note: The Rnd() functions utilize a pseudo-random seed number that is generated internally and not accessible to the user. Box() Box(type As Dyna
50 Print Run("test2.brs", "arg 1", "arg 2") if Run(["file1.brs","file2.brs"])<>4 then st
51 Eval() Eval(code_snippet As String) As Dynamic This function runs the passed code snippet in the context of the current function. The function c
52 GetLastRunRuntimeError() GetLastRunRuntimeError() As Integer This function returns the error code that resulted from the last Run() function. T
53 BRIGHTSCRIPT CORE LIBRARY EXTENSION There are a number of built-in functions that are not part of the BrightScript Core Library. You can use the
54 BRIGHTSCRIPT DEBUG CONSOLE If, while a script is running, a runtime error occurs or a STOP statement is encountered, the BrightSign application w
1 INTRODUCTION BrightScript is a powerful scripting language for building media and networked applications for embedded devices. This language featu
55 ld Show line data (source records) next Show the next line to execute. bsc List all allocated BrightScript Component instances. stats Show statis
56 APPENDIX A – BRIGHTSCRIPT VERSIONS BrightScript Version Matrix January 9, 2009 HD20000 1.3 Branch HD2000 2.0 Branch Compact Main Line
57 Type() Change: Now matches declaration names (eg. Integer not roINT32) X Added roBoolean X Added dynamic Type; Type now optional on Sub/F
58 APPENDIX B – RESERVED WORDS AND ENDSUB LINE_NUM RND CREATEOBJECT ENDWHILE M* STEP DIM EXIT NEXT STOP EACH EXITWHILE NOT SUB EACH FALSE OBJF
59 APPENDIX C – EXAMPLE SCRIPT The following code uses GPIO buttons 1, 2, 3, 4 for controls. It will work on any BrightSign model that has a video o
60 REM ******************************************************* REM *************** ********************* REM *************** GAME
61 End Function REM REM gbInit() is a member function of the game_board BrightScript Object. REM When it is called, the "this" pointer
62 if h>MAXHI then h=MAXHI xpix = cint((vidmode.GetResX() - w*CELLWID)/2) ' center game board on screen ypix = cint((vidmod
63 Function gbStartX() As Integer return cint(m.text_field.GetWidth()/2) End Function Function gbStartY() As Integer return cint(m.text_f
64 if m.snake.MoveForward(m.text_field) then return endif endif end while End Function Sub gbDraw() R
2 BrightScript and its component architecture are written in 100% C for speed, efficiency, and portability. Since many embedded processors do not h
65 End Sub Function gbGameOver() As Boolean msg$= " G A M E O V E R " msg0$=" " width = m.tex
66 REM REM construct a new snake BrightScript object REM Function newSnake(x As Integer, y As Integer) As Object ' Create AA BrightScript Comp
67 snake.snake_X=x snake.snake_Y=y snake.body=191 ' use asc("*") if graphics not enabled. snake.dx=1 ' de
68 x=m.snake_X y=m.snake_Y for each seg in m.seg_list x=x+seg.Len*seg.xDelta y=y+seg.Len*seg.yDelta end for tex
69 return m.MakeLonger(text_field) End Function Function snkMakeLonger(text_field As Object) As Boolean m.snake_X=m.snake_X+m.dx m.sn
70 if m.dx<>0 or m.dy<>-1 then m.dx=0:m.dy=-1:m.AddSegment(m.dx, m.dy, 0) 'north End Sub Sub snkTurnSouth() if m.dx&
3 VARIABLES, LITERALS, AND TYPES Identifiers Identifiers are names of variables, functions, and labels. They also apply to BrightScript object metho
4 A variable that does not end in a type declaration may change its type dynamically. For example, the statement a=4 will create an integer, while a
Comentarios a estos manuales