Brightsign BrightScript 2 Reference Guide Manuel d'utilisateur

Naviguer en ligne ou télécharger Manuel d'utilisateur pour Logiciel Brightsign BrightScript 2 Reference Guide. BrightSign BrightScript 2 Reference Guide User Manual Manuel d'utilisatio

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer

Résumé du contenu

Page 1

1 BrightScript 2 Reference Jan 9, 2009 Minor updates: April 22, 2010

Page 2 - Table of Contents

10 This example will return a type mismatch (a$ is a string, and can not contain “invalid”). Many functions that return objects can return invalid

Page 3

11 When a single precision number is converted to double precision, only the seven most significant digits will be accurate. Operators Operations i

Page 4

12 When AND and OR are used for logical operations, only the necessary amount of the expression is executed. For example: print true or invalid The

Page 5 - Introduction

13 Examples: aa=CreateObject(“roAssociativeArray”) aa[“newkey”]=”the value” print aa[“newkey”] array=CreateObject(“roArray”, 10, true) array[2]=”two”

Page 6 - Statement Summary

14 Roku Objects, Interfaces, and Language Integration [note: the name of Roku Objects will change to BrightScript Components] The Roku Object archite

Page 7 - Identifiers

15 The for-each statement works on any object that has an “ifEnum” interface. These include: Array, Associative Array, List, and Message Port. Prin

Page 8 - Literals (Constants)

16 BrightScript XML Support BrightScript supports XML via two Roku Objects, and some dedicated language features. The Roku Object roXMLElement pro

Page 9

17 Will return an roXMLElement reference to the first photo (id="3131875696”). ? rsp.photos Will return an roXMLList reference containing the p

Page 10 - Type Conversion (Promotion)

18 owner=invalid As dynamic) As Object photolist=CreateObject("roList") for each photo in xmllist photolist.Push(n

Page 11 - Function References

19 Garbage Collection BrightScript will automatically free strings when they are no longer used, and it will free objects when their reference count g

Page 12 - Array/Function Call Operator

2 Table of Contents INTRODUCTION ... 5 STATEMENT SUMMA

Page 13 - = Operator

20 Events Events in BrightScript center around an event loop and the “roMessagePort” Roku object. Any RokuObject can be posted to a message port. Ty

Page 14

21 Threading Model A BrightScript script runs in a single thread. The general rule of thumb is that Roku Object calls are synchronous if they return

Page 15

22 Scope BrightScript uses the following scoping rules:  Currently all related BrightScript code must reside in one file. This set of code is known

Page 16 - BrightScript XML Support

23 Creating and Using Intrinsic Objects In most of this manual we use the term “object” to refer to a “Roku Object”. These are C or C++ components wi

Page 17

24 Program Statements DIM name (dim1, dim2, …, dimK) DIM (“dimension”) is a statement that provides a short cut to creating roArray objects. It sets

Page 18

25 In each case, the variable on the left side of the equals sign is assigned the value of the constant or expression on the right side. END Termina

Page 19 - Garbage Collection

26 execution continues with the statement following the NEXT statement. (If increment was a negative number, loop ends when counter is less than final

Page 20

27 While expression / Exit While The While loop executes until expression is false. The “exit while” statement can be used to terminate a while loo

Page 21 - Threading Model

28 If BooleanExpression [ Then ] [ Block ] [ ElseIfStatement+ ] [ ElseStatement ] End If ElseIfStatement ::= ElseIf BooleanExpress

Page 22

29 PRINT [#output_object], [@location], item list Prints an item or a list of items on the console, or if output_object is specified, to an object

Page 23

3 Anonymous Functions ... 32 BU

Page 24 - Program Statements

30 If the console you are printing to has the interface "ifTextField" then @ specifies exactly where printing is to begin. For example:

Page 25 - RETURN expression

31  Dynamic In addition to the above types, the return type can be:  Void Parameters can have default values and expressions. For example: F

Page 26 - FOR EACH item IN object

32 m.result=m.a+m.b end function If a function is not called from an AssociatiaveArray, then its “m” is set to an AssocicateArray that is global

Page 27

33 Built-In Functions BrightScript has a small number of built-in, module scope, intrinsic functions. They are the following. Type(variable) As Strin

Page 28 - For example:

34 el=GetLastRunCompileError() if el=invalid then el=GetLastRunRuntimeError() if el=&hFC or el=&hE2 then return &ap

Page 29 - Print “this is a five “5”!!”

35 Global Functions BrightScript has a set of standard, module scope, functions. These functions are stored in the global object. If the compiler se

Page 30

36 UpTime(dummy As Integer) As Float Returns the uptime of the system since the last reboot. RebootSystem() As Void Causes a soft reboot. ListDir(path

Page 31

37 A '*' matches zero or more arbitrary characters. The character class '[...]' matches any single character specified within the

Page 32 - Anonymous Functions

38 Global String Functions UCase(s As String) As String Converts the string to all upper case. LCase(s As String) As String Converts the string to al

Page 33 - Built-In Functions

39 Mid (s As String, p As Integer, [n As Integer]) As String Returns a substring of s with length n and starting at position p. n may be omitted, in

Page 34

4 INT(X AS FLOAT) AS INTEGER ... 40 LOG(X AS FLOA

Page 35 - Global Functions

40 Global Math Functions The following math functions are part of global. Trig functions use or return radians, not degrees. Abs (x As Float) As Fl

Page 36

41 Sgn(x As Float) As Integer Sgn(x As Integer) As Integer The "sign" function: returns -1 for X negative, 0 for X zero, and +l for X positi

Page 37

42 Core Roku Objects The following set of core Roku Objects are used extensively by BrightScript, and are therefore incorporated into the language de

Page 38 - Global String Functions

43 PostMessage(msg As Object) As Void roInt, roFloat, roString, roBoolean, roBrSub, roInvalid The intrinsic types Integer (“Integer”), Float (“Float”

Page 39

44 automatically wrapped in an roInt by the language interpreter. When a function that expects a Roku Object as a parameter is passed an int, float,

Page 40 - Global Math Functions

45  CreateObject("roAssociativeArray") The ifAssociativeArray interface provides:  AddReplace(key As String, value As Object) As Void o

Page 41 - Tan(x As Float) As Float

46 The roArray class implements the ifArray and ifEnum interfaces. This object is created with two parameters:  CreateObject("roArray",

Page 42 - Core Roku Objects

47 hex or ascii base 64. Note that if you are converting a byte array to a string, and the byte array contains a zero, the string conversion will end

Page 43

48 ba2.ReadFile("ByteArrayTestFile") if ba.Count()<>ba2.Count() then stop for x=0 to 4000 if ba[x]<>ba2[x] then stop next b

Page 44

49 <emptytag caveman=”barney” /> Would parse such that: Name= emptytag Attributes = roAssociatveArray, with one entry {caveman, barney)

Page 45

5 Introduction Roku BrightScript is a powerful scripting language that makes it easy and quick to build media and networked applications for embedded

Page 46

50 root.AddAttribute("key2","value2") ne=root.AddBodyElement() ne.SetName("sub") ne.SetBody("this i

Page 47

51 GetAttributes() and GetText() are similar to calling xmllist.Simplify().GetText(), xmllist.Simplify().GetAttributes(). Appendix – BrightScript De

Page 48

52 Appendix – Planned Improvements  Iterators for reflection  Ability to use interfaces with intrinsic objects  Teleportation  Switch statemen

Page 49

53 Appendix – BrightScript Versions BrightScript Version Matrix 9-Jan-09 HD20000 1.3 Branch HD2000 2.0 Branch Compact Main Line SnapShot Date

Page 50

54 Appendix – Example Script - Snake The following code will run on any BrightSign and uses GPIO buttons 1,2,3,4 for controls. REM REM The game of S

Page 51

55 Function gbInit() As Void REM REM button presses go to this message port REM m.buttons = CreateObject("roMessagePort")

Page 52

56 if tick_count=6 then tick_count=0 if m.snake.MakeLonger(m.text_field) then return else

Page 53

57 snake.TurnWest=snkTurnWest snake.MoveForward=snkMoveForward snake.MakeLonger=snkMakeLonger snake.AddSegment=snkAddSegment snake

Page 54

58 m.seg_list.RemoveTail() else tail.AddReplace("Len",len) ' same as tail.Len=len endif return m.MakeLon

Page 55

59 Reserved Words INVALID FOR POS AND PRINT LINE_NUM OR GOTO REM EACH IF RETURN NEXT NOT STEP DIM THEN STOP ELSE TO TAB END TAB OBJFUN TYPE

Page 56

6 Statement Summary BrightScript supports the following familiar looking statement types:  If / Then / Else If / Else / End If  For / To / Next /

Page 57

7 Expressions, Variables, and Types Identifiers Identifiers (names of variables, functions, labels, or object member functions or interfaces (appear a

Page 58

8  Dynamic typing – Unless otherwise specified, a variable is dynamically typed. This means that the type is determined by the value assigned to it

Page 59 - Reserved Words

9 Type Invalid: invalid Type String: String in quotes, eg “this is a string” Type Integer: Hex integer, eg. &HFF, or decimal integer, eg. 255 Type

Commentaires sur ces manuels

Pas de commentaire