Brightsign BrightScript 2 Reference Guide Uživatelský manuál

Procházejte online nebo si stáhněte Uživatelský manuál pro Software Brightsign BrightScript 2 Reference Guide. BrightSign BrightScript 2 Reference Guide User Manual Uživatelská příručka

  • Stažení
  • Přidat do mých příruček
  • Tisk

Shrnutí obsahu

Strany 1

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

Strany 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

Strany 3

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

Strany 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

Strany 5 - Introduction

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

Strany 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

Strany 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

Strany 8 - Literals (Constants)

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

Strany 9

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

Strany 10 - Type Conversion (Promotion)

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

Strany 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

Strany 12 - Array/Function Call Operator

2 Table of Contents INTRODUCTION ... 5 STATEMENT SUMMA

Strany 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

Strany 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

Strany 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

Strany 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

Strany 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

Strany 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

Strany 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

Strany 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

Strany 21 - Threading Model

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

Strany 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

Strany 23

3 Anonymous Functions ... 32 BU

Strany 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:

Strany 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

Strany 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

Strany 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

Strany 28 - For example:

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

Strany 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

Strany 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

Strany 31

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

Strany 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

Strany 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

Strany 34

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

Strany 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

Strany 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

Strany 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

Strany 38 - Global String Functions

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

Strany 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,

Strany 40 - Global Math Functions

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

Strany 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",

Strany 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

Strany 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

Strany 44

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

Strany 45

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

Strany 46

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

Strany 47

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

Strany 48

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

Strany 49

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

Strany 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

Strany 51

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

Strany 52

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

Strany 53

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

Strany 54

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

Strany 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

Strany 56

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

Strany 57

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

Strany 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

Strany 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

Komentáře k této Příručce

Žádné komentáře