Brightsign BrightScript 2 Reference Guide Manual do Utilizador

Consulte online ou descarregue Manual do Utilizador para Software Brightsign BrightScript 2 Reference Guide. BrightSign BrightScript 2 Reference Guide User Manual Manual do Utilizador

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir

Resumo do Conteúdo

Página 1

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

Página 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

Página 3

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

Página 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

Página 5 - Introduction

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

Página 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

Página 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

Página 8 - Literals (Constants)

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

Página 9

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

Página 10 - Type Conversion (Promotion)

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

Página 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

Página 12 - Array/Function Call Operator

2 Table of Contents INTRODUCTION ... 5 STATEMENT SUMMA

Página 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

Página 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

Página 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

Página 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

Página 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

Página 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

Página 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

Página 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

Página 21 - Threading Model

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

Página 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

Página 23

3 Anonymous Functions ... 32 BU

Página 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:

Página 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

Página 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

Página 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

Página 28 - For example:

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

Página 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

Página 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

Página 31

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

Página 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

Página 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

Página 34

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

Página 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

Página 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

Página 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

Página 38 - Global String Functions

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

Página 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,

Página 40 - Global Math Functions

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

Página 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",

Página 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

Página 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

Página 44

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

Página 45

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

Página 46

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

Página 47

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

Página 48

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

Página 49

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

Página 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

Página 51

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

Página 52

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

Página 53

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

Página 54

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

Página 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

Página 56

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

Página 57

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

Página 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

Página 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

Comentários a estes Manuais

Sem comentários