P. 1
TI-Nspire Scripting API Reference Guide En

TI-Nspire Scripting API Reference Guide En

|Views: 1|Likes:
Published by Nuno Fmlg Nunes

More info:

Published by: Nuno Fmlg Nunes on May 20, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/11/2013

pdf

text

original

Sections

  • Standard Libraries
  • 1.1 Basic Library Functions
  • 1.1.1 Coroutine Sub-Library
  • 1.2 Module Library
  • 1.3 String Library
  • 1.4 Table Library
  • 1.5 Math Library
  • 1.6 Unimplemented Libraries and Functions
  • 2D Editor
  • 2.1 newRichText
  • 2.2 createChemBox
  • 2.3 createMathBox
  • 2.4 getExpression
  • 2.5 getExpressionSelection
  • 2.6 getText
  • 2.7 hasFocus
  • 2.8 isVisible
  • 2.9 move
  • 2.10 registerFilter
  • 2.11 resize
  • 2.12 setBorder
  • 2.13 setBorderColor
  • 2.14 setColorable
  • 2.15 setDisable2DinRT
  • 2.16 setExpression
  • 2.17 setFocus
  • 2.18 setFontSize
  • 2.19 setMainFont
  • 2.20 setReadOnly
  • 2.21 setSelectable
  • 2.22 setSizeChangeListener
  • 2.23 setText
  • 2.24 setTextChangeListener
  • 2.25 setTextColor
  • 2.26 setVisible
  • 2.27 setWordWrapWidth
  • Class Library
  • 3.1 class
  • Clipboard Library
  • 4.1 addText
  • 4.2 getText
  • Cursor Library
  • 5.1 set
  • 5.2 hide
  • 5.3 show
  • Document Library
  • 6.1 markChanged
  • Event Handling
  • 7.1 activate
  • 7.2 arrowDown
  • 7.3 arrowKey
  • 7.4 arrowLeft
  • 7.5 arrowRight
  • 7.6 arrowUp
  • 7.7 charIn
  • 7.8 backspaceKey
  • 7.9 backtabKey
  • 7.10 clearKey
  • 7.11 construction
  • 7.12 contextMenu
  • 7.13 copy
  • 7.14 create
  • 7.15 createMathBox
  • 7.16 cut
  • 7.17 deactivate
  • 7.18 deleteKey
  • 7.19 destroy
  • 7.20 enterKey
  • 7.21 escapeKey
  • 7.22 getFocus
  • 7.23 getSymbolList
  • 7.24 grabDown
  • 7.25 grabUp
  • 7.26 help
  • 7.27 loseFocus
  • 7.28 mouseDown
  • 7.29 mouseMove
  • 7.30 mouseUp
  • 7.31 paint
  • 7.32 paste
  • 7.33 resize
  • 7.34 restore
  • 7.35 returnKey
  • 7.36 rightMouseDown
  • 7.37 rightMouseUp
  • 7.38 save
  • 7.39 tabKey
  • 7.40 timer
  • 7.41 varChange
  • Graphics Library
  • 8.1 clipRect
  • 8.2 drawArc
  • 8.3 drawImage
  • 8.4 drawLine
  • 8.5 drawPolyLine
  • 8.6 drawRect
  • 8.7 drawString
  • 8.8 fillArc
  • 8.9 fillPolygon
  • 8.10 fillRect
  • 8.11 getStringHeight
  • 8.12 getStringWidth
  • 8.13 setColorRGB
  • 8.14 setFont
  • 8.15 setPen
  • Image Library
  • 9.1 new
  • 9.2 copy
  • 9.3 height
  • 9.4 rotate
  • 9.5 width
  • Locale Library
  • 10.1 name
  • Math Library Extension
  • 11.1 eval
  • 11.2 evalStr
  • 11.3 getEvalSettings
  • 11.4 setEvalSettings
  • Physics Library
  • 12.1 Miscellaneous routines
  • 12.1.1 INFINITY
  • 12.1.2 momentForBox
  • 12.1.3 momentForCircle
  • 12.1.4 momentForPoly
  • 12.1.5 momentForSegment
  • 12.2 Vectors
  • 12.2.1 Vect
  • 12.2.2 add
  • 12.2.3 clamp
  • 12.2.4 cross
  • 12.2.5 dist
  • 12.2.6 distsq
  • 12.2.7 dot
  • 12.2.8 eql
  • 12.2.9 length
  • 12.2.10 lengthsq
  • 12.2.11 lerp
  • 12.2.12 lerpconst
  • 12.2.13 mult
  • 12.2.14 near
  • 12.2.15 neg
  • 12.2.16 normalize
  • 12.2.17 normalizeSafe
  • 12.2.18 perp
  • 12.2.19 project
  • 12.2.20 rotate
  • 12.2.21 rperp
  • 12.2.22 setx
  • 12.2.23 sety
  • 12.2.24 slerp
  • 12.2.25 slerpconst
  • 12.2.26 sub
  • 12.2.27 toangle
  • 12.2.28 unrotate
  • 12.2.29 x
  • 12.2.30 y
  • 12.3 Bounding Boxes
  • 12.3.1 BB
  • 12.3.2 b
  • 12.3.3 clampVect
  • 12.3.4 containsBB
  • 12.3.5 containsVect
  • 12.3.6 expand
  • 12.3.7 intersects
  • 12.3.8 l
  • 12.3.9 merge
  • 12.3.10 setb
  • 12.3.11 r
  • 12.3.12 setl
  • 12.3.13 setr
  • 12.3.14 sett
  • 12.3.15 t
  • 12.3.16 wrapVect
  • 12.4 Bodies
  • 12.4.1 Body
  • 12.4.2 activate
  • 12.4.3 angle
  • 12.4.4 angVel
  • 12.4.5 applyForce
  • 12.4.6 applyImpulse
  • 12.4.7 data
  • 12.4.8 force
  • 12.4.9 isRogue
  • 12.4.10 isSleeping
  • 12.4.11 local2World
  • 12.4.12 kineticEnergy
  • 12.4.13 mass
  • 12.4.14 moment
  • 12.4.15 pos
  • 12.4.16 resetForces
  • 12.4.17 rot
  • 12.4.18 setAngle
  • 12.4.19 setAngVel
  • 12.4.20 setData
  • 12.4.21 setForce
  • 12.4.22 setMass
  • 12.4.23 setMoment
  • 12.4.24 setPos
  • 12.4.25 setPositionFunc
  • 12.4.26 setTorque
  • 12.4.27 setVel
  • 12.4.28 setVelocityFunc
  • 12.4.29 setVLimit
  • 12.4.30 setWLimit
  • 12.4.31 sleep
  • 12.4.32 sleepWithGroup
  • 12.4.33 torque
  • 12.4.34 updatePosition
  • 12.4.35 updateVelocity
  • 12.4.36 vel
  • 12.4.37 vLimit
  • 12.4.38 wLimit
  • 12.4.39 world2Local
  • 12.5 Shapes
  • 12.5.1 BB
  • 12.5.2 body
  • 12.5.3 collisionType
  • 12.5.4 data
  • 12.5.5 friction
  • 12.5.6 group
  • 12.5.7 layers
  • 12.5.8 rawBB
  • 12.5.9 restitution
  • 12.5.10 sensor
  • 12.5.11 setCollisionType
  • 12.5.12 setData
  • 12.5.13 setFriction
  • 12.5.14 setGroup
  • 12.5.15 setLayers
  • 12.5.16 setRestitution
  • 12.5.17 setSensor
  • 12.5.18 setSurfaceV
  • 12.5.19 surfaceV
  • 12.6 Circle Shapes
  • 12.6.1 CircleShape
  • 12.6.2 offset
  • 12.6.3 radius
  • 12.7 Polygon Shapes
  • 12.7.1 PolyShape
  • 12.7.2 numVerts
  • 12.7.3 points
  • 12.7.4 vert
  • 12.8 Segment Shapes
  • 12.8.1 SegmentShape
  • 12.8.2 a
  • 12.8.3 b
  • 12.8.4 normal
  • 12.8.5 radius
  • 12.9 Spaces
  • 12.9.1 Space
  • 12.9.2 addBody
  • 12.9.3 addConstraint
  • 12.9.4 addCollisionHandler
  • 12.9.5 addPostStepCallback
  • 12.9.6 addShape
  • 12.9.7 addStaticShape
  • 12.9.8 damping
  • 12.9.9 data
  • 12.9.10 elasticIterations
  • 12.9.11 gravity
  • 12.9.12 idleSpeedThreshold
  • 12.9.13 iterations
  • 12.9.14 rehashShape
  • 12.9.15 rehashStatic
  • 12.9.16 removeBody
  • 12.9.17 removeConstraint
  • 12.9.18 removeShape
  • 12.9.19 removeStaticShape
  • 12.9.20 resizeActiveHash
  • 12.9.21 resizeStaticHash
  • 12.9.22 setDamping
  • 12.9.23 setData
  • 12.9.24 setElasticIterations
  • 12.9.25 setGravity
  • 12.9.26 setIdleSpeedThreshold
  • 12.9.27 setIterations
  • 12.9.28 setSleepTimeThreshold
  • 12.9.29 sleepTimeThreshold
  • 12.9.30 step
  • 12.10 Constraints
  • 12.10.1 Damped Rotary Spring
  • 12.10.2 Damped Spring
  • 12.10.3 Gear Joint
  • 12.10.4 Groove Joint
  • 12.10.5 Pin Joint
  • 12.10.6 Pivot Joint
  • 12.10.7 Ratchet Joint
  • 12.10.8 Rotary Limit Joint
  • 12.10.9 Simple Motor
  • 12.10.10 Slide Joints
  • 12.11 Arbiters and Collision Pairs
  • 12.11.2 a
  • 12.11.3 b
  • 12.11.4 bodies
  • 12.11.5 depth
  • 12.11.6 elasticity
  • 12.11.7 friction
  • 12.11.8 impulse
  • 12.11.9 isFirstContact
  • 12.11.10 normal
  • 12.11.11 point
  • 12.11.12 setElasticity
  • 12.11.13 setFriction
  • 12.11.14 shapes
  • 12.11.15 totalImpulse
  • 12.11.16 totalImpulseWithFriction
  • 12.12 Shape Queries
  • 12.12.1 pointQuery
  • 12.12.2 segmentQuery
  • 12.13 Space Queries
  • 12.13.1 pointQuery
  • 12.13.2 pointQueryFirst
  • 12.13.3 segmentQuery
  • 12.13.4 segmentQueryFirst
  • 12.14 SegmentQueryInfo
  • 12.14.1 hitDist
  • 12.14.2 hitPoint
  • Platform Library
  • 13.1 apiLevel
  • 13.2 gc
  • 13.3 hw
  • 13.4 isColorDisplay
  • 13.5 isDeviceModeRendering
  • 13.6 registerErrorHandler
  • 13.7 window
  • 13.7.1 height and width
  • 13.7.2 invalidate
  • 13.7.3 setFocus
  • 13.8 withGC
  • Module Library
  • String Library Extension
  • 15.1 split
  • 15.2 uchar
  • 15.3 usub
  • 16.1 getMilliSecCounter
  • 16.2 start
  • 16.3 stop
  • Tool Palette Library
  • 17.1 register
  • 17.2 enable
  • 17.3 enableCut
  • 17.4 enableCopy
  • 17.5 enablePaste
  • Variable Library
  • 18.1 list
  • 18.2 makeNumericList
  • 18.3 monitor
  • 18.4 recall
  • 18.5 recallAt
  • 18.6 recallStr
  • 18.7 store
  • 18.8 storeAt
  • 18.9 unmonitor

Lua Scripting API Reference Guide

This reference guide applies to TI-NspireTM software version 3.2. To obtain the latest version of the documentation, go to education.ti.com/nspire/scripting.

Important Information Except as otherwise expressly stated in the License that accompanies a program, Texas Instruments makes no warranty, either express or implied, including but not limited to any implied warranties of merchantability and fitness for a particular purpose, regarding any programs or book materials and makes such materials available solely on an ”as-is” basis. In no event shall Texas Instruments be liable to anyone for special, collateral, incidental, or consequential damages in connection with or arising out of the purchase or use of these materials, and the sole and exclusive liability of Texas Instruments, regardless of the form of action, shall not exceed the amount set forth in the license for the program. Moreover, Texas Instruments shall not be liable for any claim of any kind whatsoever against the use of these materials by any other party. c 2011 - 2012 Texas Instruments Incorporated

The TI-NspireTM software uses Lua as scripting environment. For copyright and license information, see http://www.lua.org/license.html. The TI-NspireTM software uses Chipmunk Physics as simulation environment. For license information, see http://chipmunk-physics.net/release/ChipmunkLatest-Docs/. Microsoft R Windows R , and Mac R OS X R are trademarks of their respective owners.

i

Contents
1 Standard Libraries 1.1 Basic Library Functions . . . . . . . . . 1.1.1 Coroutine Sub-Library . . . . . 1.2 Module Library . . . . . . . . . . . . . . 1.3 String Library . . . . . . . . . . . . . . 1.4 Table Library . . . . . . . . . . . . . . . 1.5 Math Library . . . . . . . . . . . . . . . 1.6 Unimplemented Libraries and Functions 2 2D Editor 2.1 newRichText . . . . . 2.2 createChemBox . . . . 2.3 createMathBox . . . . 2.4 getExpression . . . . . 2.5 getExpressionSelection 2.6 getText . . . . . . . . 2.7 hasFocus . . . . . . . 2.8 isVisible . . . . . . . . 2.9 move . . . . . . . . . 2.10 registerFilter . . . . . 2.11 resize . . . . . . . . . 2.12 setBorder . . . . . . . 2.13 setBorderColor . . . . 2.14 setColorable . . . . . 2.15 setDisable2DinRT . . 2.16 setExpression . . . . . 2.17 setFocus . . . . . . . . 2.18 setFontSize . . . . . . 2.19 setMainFont . . . . . 2.20 setReadOnly . . . . . 1 1 2 2 2 2 2 3 4 4 5 5 6 6 7 7 7 7 8 9 9 9 9 10 10 11 11 11 12 ii

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7. . . . . . . . .22 2. . . 7. . .17 deactivate . 7. . . . . . . . . .2 hide . . . . . . . . . . 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4. . 7. . . . .15 createMathBox 7. . . . . . . . . . . . . . . . . . . . . . .1 class . . . . . . . . . . . . . . . .1 markChanged . . . . . . . . . . . . 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21 2. . . . . . setVisible . . . .1 addText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . .10 clearKey . . . setTextChangeListener setTextColor . . . . . .27 setSelectable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 charIn . . . . . . . . . . . . . . . . . . . . setText . . . .1 set . . . . . .2 arrowDown . . . . . . . . . . .25 2. . . . . .18 deleteKey . . . . . . . 7. . . . . . . . . 12 13 13 13 14 14 14 16 16 17 17 17 18 18 18 19 20 20 21 22 22 22 23 23 23 23 24 24 24 24 25 25 25 26 26 26 26 iii 3 Class Library 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 arrowRight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7. . . . setWordWrapWidth . . . . . . . . . . . . . . . . . 7. . . . . .8 backspaceKey . . . . . . . .6 arrowUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 show . . . . . . . . . . . . . . . . . . . . . .13 copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9 backtabKey . . . . . . . . . . . . . . . . . . . . . . . . . . . 7. . . . . . . . . . . . . . . . . .16 cut . . . . . . . . . . . . . . . . . . . . . .26 2. . . . . . . . 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 arrowKey . 7. .24 2. . . . . . . . . . . . . . . . . .11 construction . . . . .1 activate . . . . . . . . . . . . . . . . . . . . . 5 Cursor Library 5. . . . . . 7. . . . 7 Event Handling 7. . . . . . . . . . 7. . . . . . . . 6 Document Library 6. . . .14 create . . . . . . . . . . . . . . . . . . . . . . . . 7. . . . . . . . . . . . . . . . . . . .2 getText . . . . . 4 Clipboard Library 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . setSizeChangeListener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7. . . . . . .12 contextMenu . . . . . . . . . . . . . . . . . .23 2. . . . . . . . . . . 5. . 5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 arrowLeft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . .25 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . save . . . . . . . . . . . mouseDown . . . . . . . . . . . .14 setFont . . . . . . grabUp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . restore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grabDown . . . . . .8 fillArc . . . . . . . . . . . . . . . . . . . . . . . . . . iv . . . . . . . . . . . . . . . . . . paste . . . . . . . . . . . . . . . . . . . . . . . . . . . .29 7. . . . . . . . . . .34 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23 7. . . . . . . .12 getStringWidth . . . . . . . . . . . . . . . . . . . . . . . returnKey . . . . . . . . . . . . . . . . . . . . . . . . . .1 clipRect . . . . . . . . . . . . . . .11 getStringHeight 8. . . . . . . . . 8. . . . . . . . . . . . . . . . . . . . . . getFocus . . 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32 7. . . 8. . . . . . . . . . . . . . . . . . . . . . . 8. . .33 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36 7. . . 8. . . . . . . . .30 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 drawString . . . . . . . . . . . . . . . . . getSymbolList . . . . . . . . . . . . . . .26 7. . . . .37 7. . . . . . . . . . . paint . . . . . . . . . .41 destroy . . . mouseUp . . . . . . .24 7.40 7. . 8. . . . . 8. . .4 drawLine . . 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 drawRect . . . . . . . . . . . . . tabKey . . . . . . . . . . . . . . .2 drawArc . . . . . . . . . loseFocus . . 8. . mouseMove . . . . . . . . . . . . . . . . . . . .35 7. . . . . . . . . . . . . . . . . . . . . . . .28 7. . . . . . . . . . . . . 8. . . . . . . . . . . . . . 8. . . . .13 setColorRGB . . . . . . . . . . . . . . . . . . . . . . . . . help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.19 7. . . . . . . . . . . . . . . . . . 27 27 27 27 27 28 29 29 29 29 30 30 30 30 31 31 31 32 32 33 33 33 33 35 35 36 36 36 37 37 37 38 38 38 38 39 39 39 40 8 Graphics Library 8. . . . . . . . . . . .9 fillPolygon . . . . . . . . . . . . .22 7. . . . . . . . . . . . . . . . . . . . . . . enterKey . . . . . varChange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10 fillRect . . . . . . . . . . . .5 drawPolyLine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8. .3 drawImage . . . . . . . . . . . . .39 7. . . . . . . . . . . . . . . . escapeKey . . . . . . . . . .31 7. . . . . . rightMouseDown rightMouseUp . . . . . . . . . . . . . . . . . . . . . .38 7. . . . . . . . .20 7. . . . . . . . .15 setPen . . . .7. . . resize . . . . . . . . .21 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . 12. . . . . . 12 Physics Library 12. . . . . . . . . 12. . . . . . . .11 lerp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11. . . . . .5 width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . .1. . 11. . . . . . . . . . . . . .3 height . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . 41 41 42 42 42 43 44 44 45 45 47 48 48 51 51 51 51 52 52 53 53 53 54 54 54 55 55 55 56 56 57 57 57 58 58 59 59 59 v 10 Locale Library 10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . .10 lengthsq . . . . . . . . .8 eql . . . . . . . . . . . . . . . . . . . . .5 momentForSegment 12. . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . 11 Math Library Extension 11. . . . . . . . . . . . . . . . . . . . . .9 Image Library 9.2. . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9. . . . . . . . . . . . . . . . . . . .2. . . . . . .1 Miscellaneous routines . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . .13 mult . . . . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . .2.2. . . . . . . . 12. . . . . . . . .2. . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 momentForCircle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 setEvalSettings . . . . . . . . . . . . . . . . . 12. . . . .1 new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 copy . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2. . .3 getEvalSettings . . . . . . . . . . . .2.2. . . . . . . . . . . . .2 Vectors . . . . . . . . . . . . . . . . . . . . . . .1 name .15 neg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 cross . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . . . . . 9. . . . . . . . . . . . . . . . 12. . . . . . . . . . .4 rotate . . . . . 12. . . . . . . . . .16 normalize . .2. . . . . . . . . . . . . . . 11. . . . . . . . . . . .5 dist . . . . . 12. . . . . .7 dot . . . . . . . . . . . . . . . . . . . . . . . . . .4 momentForPoly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 near . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 eval . . . . . . . . . . . .1. . . . .2. . . . .2. .6 distsq . . . . . . . . .2. . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . .1 Vect . . 12. . . . . . . . . 12. . . . 9. . . . .2 momentForBox . . . . . . . . . . . . . . . . 12. . . 9. . . . . . . . . . . 12. . . . . .3 clamp .1 INFINITY . . . . . . . .12 lerpconst .2. . . . . . . . . . . . . . . . . . . . . . . . 12. . . . .1. .2 add . . . . . .2 evalStr . . . . . . . . . . . . . . . . . .17 normalizeSafe . . .9 length . . . 12. . . . 12. . . .

. . . . . . . . 12. . . . . . . . . . . . 12. . . . . . . . . .2. . . . . . . . .4. . . . . . . . . . . . . . . . . 12. . . . . . 12. . . . . . . . . . . . . . .9 merge . 12. . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . 60 60 60 61 61 61 62 62 63 63 64 64 64 65 65 65 65 66 66 66 67 67 67 68 68 68 69 69 69 70 70 70 71 71 71 72 72 72 73 73 74 vi . . . . . . . . . . . . . . . .4.5 applyForce . . . .10 isSleeping . . . . . . . . . . . 12.3. . . . . . . . . . . . . .8 l . . . . . .3. . .3. .2. . . 12. . . . . . 12. . . . . . . . . .28 unrotate . . . . . . . .2. . . . . 12. . . . . . . . . . . . 12. . . . . . . . . . .27 toangle . .2.3. . . . . . . . . . . .21 rperp . . 12. . . . . . . . . . . . . . . . .22 setx . . . . . . . . . . . 12. . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . .5 containsVect 12. .30 y . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . .4 containsBB . . . . . . . . . . . 12. . .11 r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . 12. . . . . . .2. . . . . . . . . . . . . . . . 12. . . . . .6 expand . . . . . . . . . . . . .4. . . . . . . 12. . . . . . . . . . . . . . . . . . . .3. .2 b . . . .13 setr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. .3. . . . . . .23 sety . . . . . . . . . . . . . . . . . . . . . . .10 setb . . . . . . . . . . . . . . . . .29 x . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . .3. . . . . . . . .7 data . . . . .3. . . . . . . . . . . . . . . . . . . . . . .2. . . . 12. . . . . . . . . . . . . . . . 12. . . .3. . . . . .2. . . . . 12. . . . . .4. . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . .3. . . . .3. . . . . . . . . .2 activate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 slerp . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Body . . . . . . . . . . . . . . . . .4 angVel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . 12. . 12. . . . . . . . . . 12. . . .12 setl . . . 12. . .3 Bounding Boxes . . . .3 angle . . . . . . . . . . . . . . . . .18 perp . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . 12. .3. . . . . . . . . . . . . . . . . 12. . . . . 12.26 sub . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 t . . . . . . . . . . . . . . . . . . 12. . . . . . . .19 project . . . . . . . . . . . . . . . . . . . . .25 slerpconst . . . . . .2.2. . . . . . . . . . . . .4. . .14 sett . .3. . . . . . . .3. . . . . . . . . .8 force . . . . . . . . . . . . . . .20 rotate . . . . . . . . . . . . 12. . . . . . . . . . . .7 intersects . . . . . . . . . . . . . . . .9 isRogue .1 BB . . . . . .16 wrapVect . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 applyImpulse 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. .2.12. . . . .4 Bodies . . . . . . . . . . . . . . . . . . .3 clampVect . . . . .

. . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10 12. . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . .34 12. .5. . . . . . . . setCollisionType . . .5. . . . . . BB . . . . . . . . . .36 12. . . . . . mass . . . . . . . . . . . . . . . .24 12. . . . . . . . .31 12.11 local2World . . . . . . . . . . . . . . . . . . . . . . . . sleepWithGroup torque . . . . rot . . . . . . . . . .29 12. . . . . . . . . . . setPositionFunc . . . . . . .5. . . . . . . . . . .14 12. . . . .26 12.4. . . . . . . . . . . . . . . .4. . . . . . . .39 12. . . .11 12. . . .4. . . . . . . . . . . . data . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vel . . . . . moment . . . . restitution . . .25 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . .4. . . . . . . . setAngle . . . . . . . . . . . . . . . . . . . . setPos . . . . . . . .18 12. . . . . . . setData . . . updateVelocity . . . . . . . . . . . . . . . .12 12. . . . . . . . . .16 12. . . . . . . . . . . .4. . . . . . . . . . .4. . . . .23 12. . . . . . . . . . . . . . . . . .4. . .27 12. . . . . . . . . world2Local . .4. . . . . . . . . . . . . . . . . .13 12. sensor . . . kineticEnergy . . . . . . . . . . . .7 12. . . . . . . . . . . . . . . . .4 12.4. . . . . . . . . . . . . . . resetForces . . . . . . . . .30 12. layers . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . .5. . . . . . . . . . . .4. .4. . . . . . . . . .35 12. . .4. . . . . . . . . . . . . . . . . . . . . . setMass .17 12. . . .4. . . . . . . . . . . vLimit . . . . . . . . . . .5. . .19 12. . . . . . . . . . . setTorque . . . . . .4. .12. . . . .6 12. . . . . . setVel . . .21 12. . . . . . .32 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 12.5. . . . . . . . . . . . . . . . . . . . . . .5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . setVLimit . . . . . . . . . . . . . . . . . . . . . . . . .5 12. .37 12. group . . . . . . . . . . . . . . . . . . . . . .9 12. . . . . . setVelocityFunc . . . . . . . . . . . . .1 12. . . . . . . . . .38 12. . . . . . . . . .4. . . . . . . . . . setForce . . . . setAngVel . . . . . . . . .4. . . .33 12. . . . . . . . . . . . . . .4. . . . .4. . . . . . . . collisionType . . . . . . . . . . . . . . . . . . . . . . . . .8 12. . . . . . . . . . . . . rawBB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . wLimit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22 12. . . . . . . .4. . . . . . . .5. . . . . . . . . . . . . . . . . .4. . . . . . . . . . . .28 12. . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . . . . . . . . updatePosition . . . . .5. . . . . . . 74 74 75 75 75 76 76 76 77 77 77 78 78 78 79 79 80 80 81 81 82 82 83 83 84 84 84 85 85 85 86 86 86 87 87 87 88 88 88 89 89 vii . . . . . . . . . . . . friction . .3 12. . . . . setMoment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . setWLimit . . . . . . . . . . . . . . . . . . . . . sleep . . . . . . . .20 12. body . . . . . . .5. . . . . . . .2 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Shapes 12. . pos . . . . . . . . . .4. . . . . .4. . . . . . . . . . . . .

. . . . . . . . . . . . .5. . . . . . . . . . . 12. . . . . 12. . . . . . . . . . . . . . . . .9. . .5 radius . . . . . . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . .5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8. . . . . . . . . .9 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9. . . . . . .16 setRestitution . 12.5. . . . . . . . . . . . . . . . . . . . .5. .5 addPostStepCallback 12. . . . . .4 normal . . . . 12. . . . . . . . . . 12. . . . . . . . . . . .8. . . 12. . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . .4 vert . . . . . . . . . . . . . . . . . . .13 iterations . . . . . . . .12 idleSpeedThreshold . . . . . . . . .14 rehashShape .18 setSurfaceV . . . . . . . . . . . . . . . . . . . . . . . . .16 removeBody . . .3 b . . . . . . . . . . . .5. . .13 setFriction . . . . . . . 12. . . . . . . . . . .9. . . . 89 90 90 90 91 91 92 92 92 92 93 93 93 94 94 94 95 95 95 96 96 97 97 97 97 98 98 98 99 100 100 101 101 101 102 102 102 102 103 103 104 viii . . . . 12. .9. . . . .9. . . . . . . . . . . . . . . . . . . . .6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . .2 a . . . . . . .7. . . . . . Polygon Shapes . . . . . . . . . . . . .2 offset . . .5. . . . .8 damping . . . . . . . . . . . . . . . . . . . . . .1 PolyShape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . .8.7 addStaticShape .3 addConstraint . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . .6 addShape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . Spaces . . . . . . . . . . .12 setData . . . . . . . . . . . . 12.7 12. . . . . . . . . . . .3 points . . . . . .5. . . . . . . . 12. . . . . . . . . 12. . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6. . . . . . 12. . . .7. . . . . . . . . . . . .9. . . . . . . . . . . . .9. . .8. .2 addBody . . . . .1 SegmentShape . . . . . . . . . 12. . 12. . . .6 12. .12. . . . . . . . . . .15 rehashStatic . . . 12. . . . . . . . . .9. . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . .7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6. . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . .11 gravity . . . . . . . . . . . . . . .4 addCollisionHandler 12. . . . . . . .7. . . . . . . . . . . 12. . . . . . . . . . . . . . . . .17 removeConstraint . 12. . . . . . . . .8. . . . . . . .14 setGroup . . . . .1 CircleShape .8 12. . . . . . . . . . . . . . . . . . .17 setSensor . . . . . . . . . . . . .9. . . . . . . . . . . . . . . . . . .19 surfaceV . . .1 Space . . . . . . .9. . . . . . .5. . . . . 12. . . . . . . . . . . 12. . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . .9. . . . . . .2 numVerts . . .3 radius . . . . . . . . . . . . . . . . . . . . . .9 data . Circle Shapes . . . . . . 12. . . . 12. . . . . . . . . . . Segment Shapes . . . . . . . 12. .9. . . . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. .10 elasticIterations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . .15 setLayers . . . . . . . . . . . . . . . . . . . .

. . . . .4 bodies . . . . . . . . . . .9. . .11 Arbiters and Collision Pairs . . . . . . . 12. . . . . .13 setFriction . . . .3 b . . . . . . . . . . . . . . . .8 Rotary Limit Joint . . . . . . . . . . . . . . . . . . . . . . . .9. . . . . . .4 Groove Joint . . . . . . . . . 12. . . . . . . . . . . . . . . . . . .24 setElasticIterations . . . . . . . . . . . . . . . . . . . . 12. . . . . . .26 setIdleSpeedThreshold .30 step . . . . . . . . . . . . .10. . . . .22 setDamping . . .11. . . . . . . 12. . . . . . . .2 Damped Spring . . . . . . . . . . . . . . . . . .14 shapes . . .9. . . . . . . . . .6 Pivot Joint . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . .6 elasticity . . . . . . . .3 Gear Joint . . . . . . . . . . . . .9. . . . . . . . 104 104 105 105 105 106 106 107 107 107 108 108 108 109 109 110 111 111 112 113 113 114 114 115 115 115 116 116 116 117 117 117 118 118 118 119 119 119 120 120 121 ix . 12. 12. . . 12. . . . . . . . . .10. . . . . . . . .5 depth . . . . . . . . . . .10. . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . .11 point . .11. . . . .11. . . . . . .9. . . .21 resizeStaticHash . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11. . . . . . . . . . . . . . . . . . . . .11. . .1 # . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . 12. . . . . . .1 Damped Rotary Spring . . . . . . . .15 totalImpulse . . . . . . . . . . . . . . . .9. . . . . . .11. . . . . . . . . .27 setIterations . .10. .10. . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . .11. . . . . . . . . 12.7 Ratchet Joint .11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 friction . 12. . . . . 12. . 12. . . . . . . . . . . . . . . . . . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9. .11. 12. . . . . . . . . . 12. . .12 setElasticity . . . .11. . .9. . . .10. . . . . . . . . . . . . . . .29 sleepTimeThreshold . . . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20 resizeActiveHash . . . . . . . . . . .9 isFirstContact . . . . . . . . . . . . . . . . . . . .9. . . . . . 12. . . . . . . . . . . . . . . . . .25 setGravity . . . . . . . . . .5 Pin Joint . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . .11. . . . . 12. . . . . .10 Constraints . 12. . .9. . . .28 setSleepTimeThreshold . .10 normal . . . . . . . .16 totalImpulseWithFriction . .10. . . . . . . . . . . . . . . . . 12. . . . . . . . . .8 impulse . . . . . . . . . . . . . . . . . . .18 removeShape . . . . . . . . . . . . . . . . . . . 12. . . . . . 12. . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . .9 Simple Motor . . . . . 12. . . . . . . . . . .10 Slide Joints . . . . . . . . . .11. . . . . . . . . .19 removeStaticShape . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2 a . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . .23 setData . . . 12. . . . . . . . . 12.10.11. . . . . .11. . . . . . . . . . . . . . . . . . . . . . . .10. . . . . . . . . . . . . . . .11. . . . . . . .12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9. 12. . . . .11. . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. .9. . . . . . . . . . . . . . . . . .10. . . . . . . . . . . 12. . . . . . 12. . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 15. . . . 13. . . . . . . . . . . . . . . .12. . . . . . . . . . . . . . . . . . . . . . . . . 13. . . .13. . . .4 isColorDisplay . . . . . 13. . . . . . . . . . 13. 138 138 139 139 140 x . . . . . . . . . . . . . . . . . . .1 split . . . . . . . .3 setFocus . . .3 usub . 12. . . 12. . . . 12. . . . . . . . . . . . . . . . . . . . 17. . . . . . . . . . . . . . . . .6 registerErrorHandler . . . . . . . . . . . . . .1 getMilliSecCounter . . . . . . . . . . . . . . . .3 segmentQuery . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7. . . . . . . . . . . 14 Module Library . . . . . . . . . . . . . .14. . . . . . . 17. . . . . 17. . . . . . . . . . . . . . 12. . . . . . .13. . . . . . . . . 137 17 Tool Palette Library 17. . . . . . . . .14 SegmentQueryInfo . . 134 16 Timer Library 136 16. . . . . . . . . . . . . . . . . . . . . . . . . .13. .1 register . . . . . . . . . . . . . 13. . . . 13. . . . . . . 13. . . .3 hw . . . . . . . . . . . . . . . . . . . . . . .2 enable . 13. . . 15 String Library Extension 134 15. . . .7. . . . . . . . . . . . . . . . .4 segmentQueryFirst 12. . . . . . . . . . .13 Space Queries . . . . . . . . . . . . . . . . . . . . . . . . .8 withGC . . . . . . . . . . . . . . . . . . . . . .4 enableCopy . . . . . . . . . . . . .2 pointQueryFirst . . . . . . .2 start . . . . . . . . . . . 136 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 Shape Queries .2 uchar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 16. . . . . . . 12. . . . . . . . . . . . . . . .2 gc . . . . . . . . . . . . . . . . .1 height and width 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14. . . . . . . . . . . . . . . . . . . . . . . 13 Platform Library 13. . . . . . . . . . . .2 invalidate . . . . . . . . . . . . . . . .5 isDeviceModeRendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7. . . . . . . . . . . . . . . . . . . . . .12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 121 121 122 122 123 123 124 125 125 125 127 127 128 128 129 129 129 130 130 130 131 131 133 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 pointQuery . . . . . . . . . . . . . . . .2 hitPoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 pointQuery . . . . . . . . . . . . . . . .1 apiLevel . . . .12. . . . . . . . . . . . . . . . . . . . . 12. .3 stop . . . . . . . . . . . . . . . . . . . . . 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. . . . .13. . .7 window . . . . . . . . . . . . . . . . . . . . . . . .1 hitDist . . .3 enableCut . . . . . . . . . . . . . .2 segmentQuery .

. . . . . . . .5 recallAt . . . . . . . . . . . 18. . . . . . . . . . . . . . . . . . . . . . . . .7 store . 18.2 makeNumericList . . .8 storeAt . . . . . . . . 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18. . . . . . . . . . . . . . . . . . . . . . . . .9 unmonitor . . . . . . . . . . . . . . . . . . . .6 recallStr . . . . . . . . . . . . . . . . . . . .4 recall . . . . . . . . . . . .3 monitor . . . 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17. . . . . . . . . . . . . . . . . . 18. . . . . . . .1 list . . . . . . . . . . . . . . . . 18. . . . . . . . . 141 141 141 142 142 142 143 143 143 144 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 enablePaste . . . . . . . . . . . . . . . . . . . . . . . . . 18. . . . . . . . . . . . . . . . . . . . . . . . . xi . . 140 18 Variable Library 18. .

1.1 Reference Manual. Lua source code loaded by the use of these functions is not supported in the TI-NspireTM Editor.Chapter 1 Standard Libraries The TI-NspireTM software integrates most Lua standard libraries that come with the Lua distribution. See the (Lua 5. assert ipairs print setmetatable xpcall collectgarbage load rawequal tonumber error loadstring rawget tostring G next rawset type getfenv pairs select unpack getmetatable pcall setfenv VERSION Note about load() and loadstring() Please be cautious with the use of load and loadstring .1 Reference Manual) for definitions of the standard functions.1 Basic Library Functions For further details. 1 . This source code cannot be debugged and error messages resulting from functions loaded using load and loadstring might cause confusing results. please follow this link to the ”Basic Functions” section in the Lua 5.

1.1.1

Coroutine Sub-Library

For further details, please follow this link to the ”Coroutine Manipulation” section in the Lua 5.1 Reference Manual. The following functions are defined inside the coroutine table. Heavy use of coroutines might be difficult to debug inside the TI-NspireTM Editor. create resume running status wrap yield

1.2

Module Library

The implementation of this module is very limited. Please consult the Module Library section for more details.

1.3

String Library

For further details, please follow this link to the ”String Manipulation” section in the Lua 5.1 Reference Manual. String routines lower and upper are not tailored to the current locale. The conversion of strings to upper and lower case letters operates only on the 26 letters of the Latin alphabet. This restriction also applies to the alphabetic matching patterns (%a, %l, %u, and %w) employed by the find , gmatch, and match functions. byte lower char match dump rep find reverse format sub gmatch upper gsub len

1.4

Table Library

For further details, please follow this link to the ”Table Manipulation” section in the Lua 5.1 Reference Manual. concat insert maxn remove sort

1.5

Math Library

For further details, please follow this link to the ”Mathematical Functions” section in the Lua 5.1 Reference Manual. The following functions are defined inside the math table. Infinite and undefined results will convert to the appropriate TI-NspireTM representations 2

and cooperate with the TI-NspireTM math extensions. The reverse conversion of string representation (infinite and undefined) to numerical representation is not supported. abs deg log10 randomseed acos exp max sin asin floor min sinh atan fmod modf sqrt atan2 frexp pi tan ceil huge pow tanh cos ldexp rad cosh log random

1.6

Unimplemented Libraries and Functions

The following standard Lua libraries are not available in the TI-NspireTM software: file io os debug

The following standard functions and standard table entries are not available in the TI-NspireTM software: dofile package.path loadfile package. seeall module package.cpath package.loadlib

3

Chapter 2

2D Editor
The Lua 2D editor bindings enable 2D rich text editors to be created and manipulated within the TI-NspireTM product. 2D rich text editors are created using newRichText(). Info Rich text editors embed formatting information in the text string to indicate the presence of a Math Box (Expression Box) or Chem Box. The functions getExpression, getExpressionSelection, and getText return the below described embedded formatting information if a Math Box or Chem Box is inside the editor. ”\0el {...}” - Denotes a Math Box (Expression Box). Evaluated Math Box expressions result in a pair of ”\0el {...}” separated by a filled in ’>’. See the Guidebook for a list of valid math expressions for the Math Box. ”\0chem {...}” - Denotes a Chem Box. Note Rich text editors embed other formatting information in the text string. This information may change in future releases, so using it is not recommended. It is delimited by ”\1 ...\”.

2.1

newRichText

D2Editor . newRichText ( ) Creates and returns a new 2D rich text editor. 4

Introduced in platform.apiLevel = ’2.Note The program must resize the 2D editor before the text editor widget is painted the first time.apiLevel = ’1. 0 ) : setBorder (0) : s e t B o r d e r C o l o r ( 0 x000000 ) : setColorable ( fa l se ) : setDisable2DinRT ( f a l s e ) : s e t F o n t S i z e (< d e f a u l t system s i z e >) : setMainFont(< d e f a u l t system f o n t >) : setReadOnly ( f a l s e ) : setSelectable ( true ) : s e t T e x t C o l o r ( 0 x000000 ) : s e t V i s i b l e ( true ) Introduced in platform.2 createChemBox D2Editor : createChemBox ( ) Inserts a Chem Box in the current cursor position of the editor.0’ 2.3 createMathBox D2Editor : createMathBox ( ) Inserts a Math Box (Expression Box) in the current cursor position of the editor. Returns the text editor object. Returns the text editor object.0’ 2.apiLevel = ’2.0’ 5 . Default 2D Editor Setup A new 2D rich text editor is created with the following defaults: : move ( 0 . Introduced in platform.

e r r o r = D2Editor . e r r o r = D2Editor . and the selection start as an integer. 2 8 ) s t r . s e l .0’ 2. s e l . e r r o r = d2e : g e t E x p r e s s i o n S e l e c t i o n ( ) The above code results in: str = ’This is a test string to see it working. ’ d2e . 1 6 ) s t r .0’ 6 .apiLevel = ’2. e r r o r = d2e : g e t E x p r e s s i o n S e l e c t i o n ( ) The above code results in: str = ’This is a test string to see it working.5 getExpressionSelection D2Editor : g e t E x p r e s s i o n S e l e c t i o n ( ) Returns three values: the contents of the text editor as a UTF-8 encoded string. Introduced in platform. e r r o r = d2e : s e t T e x t ( s t r .apiLevel = ’2. 1 6 . newRichText ( ) r e s u l t .’ pos = 16 (right before the ”s” in ”string”) sel = 28 (between the two e’s in ”see”) s t r = ’ This i s a t e s t s t r i n g t o s e e i t working . ’ d2e . s t r = ’ This i s a t e s t s t r i n g t o s e e i t working . the cursor position as an integer.4 getExpression D2Editor : g e t E x p r e s s i o n ( ) Returns the contents of the text editor as a UTF-8 encoded string. Usage Cursor and selection positions are the borders between characters.2.’ pos = 28 (between the two e’s in ”see”) sel = 16 (right before the ’s’ in ”string”) Introduced in platform. pos . newRichText ( ) r e s u l t . not the position of the characters. The following code snippets serve as examples. e r r o r = d2e : s e t T e x t ( s t r . pos . 2 8 .

Both x and y must be between -32767 and 32767. y ) Sets the parent-relative location of the upper left corner of the text editor.apiLevel = ’2.8 isVisible D2Editor : i s V i s i b l e ( ) Returns true if the editor is visible.7 hasFocus D2Editor : hasFocus ( ) Returns true if the editor has focus.0’ 2.apiLevel = ’2. Introduced in platform.apiLevel = ’1.2. otherwise returns false.0’ 2. Introduced in platform.9 move D2Editor : move ( x .0’ 7 . Introduced in platform.apiLevel = ’1. Returns the text editor object. Introduced in platform.0’ 2. otherwise returns false.6 getText D2Editor : getText ( ) Returns the contents of the text editor as a UTF-8 encoded string.

the tabKey filter function moves the focus to text editor ed2.10 registerFilter D2Editor : r e g i s t e r F i l t e r ( h a n d l e r T a b l e ) This routine registers a table of handler functions that can filter events before they are sent to the 2D editor widget.apiLevel = ’2. arrowKey = f u n c t i o n ( key ) p r i n t ( key ) return f a l s e end . Any event described in the section on Event Handling can be filtered by a function in the handler table. In the example code below. newRichText ( ) −− R e g i s t e r f i l t e r s f o r e v e n t s ed : r e g i s t e r F i l t e r { tabKey = function () ed2 : s e t F o c u s ( ) return true end . The handlerTable is a table of event handler functions. Events charIn and arrowKey simply report which key was pressed and then allow the event to pass on through to the text editor.0’ 8 . } Introduced in platform.2. Returns the text editor object. if the user presses Tab in the text editor ed. or unregisters if nil is passed. charIn = f u n c t i o n ( ch ) p r i n t ( ch ) return f a l s e end . −− C r e a t e an e d i t o r ed = D2Editor .

0’ 2. Introduced in platform. Introduced in platform.0’ 2. Returns the text editor object. Introduced in platform.2.11 resize D2Editor : r e s i z e ( width .apiLevel = ’2.12 setBorder D2Editor : s e t B o r d e r ( t h i c k n e s s ) Sets the editor’s border thickness. Both width and height must be > 0 and < 32768.apiLevel = ’2. Returns the text editor object.0’ 2. Introduced in platform.13 setBorderColor D2Editor : s e t B o r d e r C o l o r ( c o l o r ) Sets the editor’s border color.14 setColorable D2Editor : s e t C o l o r a b l e ( t r u e o r f a l s e ) Makes the expression colorable or uncolorable. The color value must be between 0 and 16777215 (0x000000 and 0xFFFFFF).apiLevel = ’1.0’ 9 . Returns the text editor object. h e i g h t ) Changes the width and height of the text editor.apiLevel = ’2. The thickness value must be between 0 and 10. Returns the text editor object.

’ d2e . s e l e c t i o n [ . c u r s o r [ . If the selection = -1. indicates that all digits of the calculated results should be displayed. both the cursor and the selection start default to -1.2. Text can be selected by specifying a selection index that indicates the end of the selection. no text is selected. full-precision. e r r o r = D2Editor . Returns the text editor object. full-precision indicates that calculated results should be rounded using the editor’s precision setting. 2 8 ) 10 .0’ f 2.15 setDisable2DinRT D2Editor : setDisable2DinRT ( t r u e o r f a l s e ) Turns off 2D layout of math input to the text box. s t r = ’ This i s a t e s t s t r i n g t o s e e i t working . 1 6 . If the cursor < -1 or selection < -1. If true. the final optional parameter. newRichText ( ) r e s u l t .apiLevel = ’2. -1 (end of text). As a result. an error is returned. Usage Cursor and selection positions are the borders between characters. If unspecified. The cursor position is set to 1 (beginning of text). If false.16 setExpression D2Editor : s e t E x p r e s s i o n ( t e x t [ . Introduced in platform. or a value from 1 to the text length plus 1. the string required to get the editor to show home\stuff\work is ”home\\\\stuff\\\\work”. This is in addition to the standard escape rule for special characters. f u l l −p r e c i s i o n ] ] ] ) Sets the text content of the text editor. Note All backslashes sent to the editor must be doubled. The following code snippet highlights the characters ”string to se” and places the cursor before the ’s’ in ”string”. e r r o r = d2e : s e t T e x t ( s t r . not the character positions.

0’ 2. 1 6 ) Returns the text editor object.getFocus event handler. 9.17 setFocus D2Editor : s e t F o c u s ( t r u e o r f a l s e ) Sets the user input focus on the editor if true (the default). s t r = ’ This i s a t e s t s t r i n g t o s e e i t working . e r r o r = D2Editor .0’ 2.The following code snippet highlights the characters ”string to se” and places the cursor before the second ’e’ in ”see”. 11. newRichText ( ) r e s u l t . This is usually called from the on. Introduced in platform. Introduced in platform. The point size is restricted on the TI-NspireTM CX and older handheld devices. 10. ’ d2e . Returns the text editor object. or 24. Choose one of these sizes: 7.apiLevel = ’2.0’ 2. s t y l e ) 11 . Any font size supported by Windows R or Mac R OS X R can be used on the desktop software.apiLevel = ’2.apiLevel = ’2. Introduced in platform. 12. Returns the text editor object. e r r o r = d2e : s e t T e x t ( s t r .18 setFontSize D2Editor : s e t F o n t S i z e ( s i z e ) Sets the text font size in the editor.19 setMainFont D2Editor : setMainFont ( f a m i l y . 2 8 .

0’ Description Regular Bold Italic Bold and Italic 2. or setFormattedExpression use the default font.Sets the main font family (”serif” or ”sansserif”) and style (”r”. ”i”. Returns the text editor object.0’ 2.apiLevel = ’2. defaults to true. Style r b i bi Returns the text editor object.0’ 12 . Subsequent calls to setText. Returns the text editor object. Introduced in platform. ”b”.21 setSelectable D2Editor : s e t S e l e c t a b l e ( t r u e o r f a l s e ) Makes the text editor content selectable (true) or unselectable (false) by the user.20 setReadOnly D2Editor : setReadOnly ( t r u e o r f a l s e ) Makes the text editor content modifiable (false) or unmodifiable (true) by the user. If a Boolean value is not specified. setExpression. If a Boolean value is not specified. ”bi”). defaults to true.apiLevel = ’1.apiLevel = ’1. Note This function affects only previously set text. Introduced in platform. Introduced in platform.

s e l e c t i o n [ .apiLevel = ’2.0’ 2. Info To remove the listener. Introduced in platform.0’ 2. Optimal widget height to fit the expression. Returns the text editor object. It will be passed into the following parameters: Parameter editor w h Description Editor in which the expression changed size. This function will be passed into the editor object. h ) ) Sets the callback function for when the editor contents exceed the current editor size. call D2Editor:setSizeChangeListener(nil) Introduced in platform. Info 13 .2. Returns the text editor object. c u r s o r [ . This function can then resize the editor appropriately. The callback function should be a void function. This allows for processing text input as it occurs.apiLevel = ’1. w. Optimal widget width to fit the expression.24 setTextChangeListener D2Editor : s e t T e x t C h a n g e L i s t e n e r ( f u n c t i o n ( e d i t o r ) ) Sets the callback function for when the text expression changes. when the contents fit on fewer lines. Returns the text editor object. f u l l − p r e c i s i o n ] ] ] ) See setExpression() for details.23 setText D2Editor : s e t T e x t ( t e x t [ .22 setSizeChangeListener D2Editor : s e t S i z e C h a n g e L i s t e n e r ( f u n c t i o n ( e d i t o r . or when the contents fit on a single line of smaller width.

0’ 2. that is the width is < 0.27 setWordWrapWidth D2Editor : setWordWrapWidth ( width ) Sets the rich text editor word-wrapping width in pixels. call D2Editor:setTextChangeListener(nil) Introduced in platform.apiLevel = ’2. Note When word wrapping is disabled. and ellipses are added to cut words.25 setTextColor D2Editor : s e t T e x t C o l o r ( c o l o r ) Sets the editor text color.0’ 2. Returns the text editor object.To remove the listener. To indicate widget width.0’ 2. sets to < 0. The color value must be between 0 and 16777215 (0x000000 and 0xFFFFFF). Ignored if the editor is in 2D mode. Introduced in platform.apiLevel = ’2.apiLevel = ’2. Returns the text editor object. Introduced in platform. To disable wrapping. sets to 0. 14 . the negative value of the width specifies the margin from the right of the widget before ellipses are used.26 setVisible D2Editor : s e t V i s i b l e ( t r u e o r f a l s e ) Sets the visibility of the text editor. The width must be -32767 to 32767.

apiLevel = ’2.0’ 15 .Returns the text editor object. Introduced in platform.

1 class class ([ parent class ]) Returns a new class. If a parent class is specified. the new class inherits the methods of the parent class. .Chapter 3 Class Library The class library implements basic object-oriented class definitions. Introduced in platform. when the script calls Button(). Class Button can override any methods of its parent class. The Button:init() function is called to initialize the button. . a new Button is created.apiLevel = ’1. end With these definitions. end Button = c l a s s ( Widget ) f u n c t i o n Button : i n i t ( ) . Widget = c l a s s ( ) f u n c t i o n Widget : i n i t ( ) . . and the newly minted Button object is returned as the function result of the call.0’ 16 . Class Button in this example inherits all the methods and class variables defined in class Widget. . 3.

this routine returns nil. MIME type ”text/plain”.0’ 4.0’ 17 .apiLevel = ’1.1 addText c l i p b o a r d . Introduced in platform. getText ( ) This routine returns the contents of the clipboard as a string of plain text.2 getText c l i p b o a r d . Introduced in platform. addText ( s t r i n g ) This routine adds the contents of string to the clipboard as plain text.Chapter 4 Clipboard Library 4.apiLevel = ’1. If the clipboard does not contain any text (MIME type ”text/plain”).

hide () 18 . ”hollow pointer”. ”hand open”. ”dotted arrow”. ”rotation”.2 hide cursor . ”drag grab”. ”clear”.apiLevel = ’1.1 set c u r s o r . ”link select”. ”excel plus”. A good practice is to request the expected cursor appearance within on. ”translation”. ”writing”. It can be one of the following strings: ”default”. ”arrow”. ”pencil”. ”resize row”. ”zoom in”. ”diag resize”. ”wait busy”.0’ 5. activate () . ”pointer”. The visibility of the cursor can only be controlled on a handheld. ”zoom out”. ”hand pointer”. Calls on the cursor library are ignored while deactivated (after on. ”text”. ”hide”.deactivate () is received). ”animate”. ”interrogation”. ”show” Introduced in platform. ”hand closed”. ”crosshair”. 5. s e t ( cursorname ) Parameter cursorname is a string that contains the name of the cursor shape to use for the mouse pointer. ”resize column”. ”unavailable”. ”mod label”. ”dilation”.Chapter 5 Cursor Library This cursor library controls the appearance of the mouse pointer. ”zoom box”.

apiLevel = ’1.3 show c u r s o r .This routine hides the mouse pointer on a handheld. show ( ) This routine makes the mouse pointer visible on a handheld. Note: Calls to this routine are ignored if not executed on a handheld.0’ 5. Introduced in platform.0’ 19 .apiLevel = ’1. Introduced in platform. Note: Calls to this routine are ignored if not executed on a handheld.

1 markChanged document .apiLevel = ’1. The user is prompted to save the TI-NspireTM document before closing. markChanged ( ) This routine marks the current document as changed.Chapter 6 Document Library 6.0’ 20 . Introduced in platform.

the application script implements on. ) : end Set Script Event Sequence The following sequence of events are generated when ’Set Script’ is selected. p a i n t ( gc ) gc : drawLine ( .Chapter 7 Event Handling Script applications respond to external stimuli by implementing event handlers. . All the event handlers are grouped in the ”on” module. 21 . Example For example.paint(gc) to be notified when it is time to redraw its window.paint is passed a graphics context that it can use to call drawing routines on its window. on. . f u n c t i o n on .

..restore on. The dimensions of the drawing window cannot be initialized at this point so it is not a good place to create and position graphical elements if they depend on the window size.. arrowKey ( key ) 22 ..1 activate on ..0’ 7.0 on.save() Other calls depending on other active cards or scripts When the script is active on the active card Other calls depending on other applications or scripts When the script receives user input focus Other calls depending on other applications or scripts on.activate .paint() API Level 2.getFocus .API Level 1. a c t i v a t e ( ) This routine is called when the script application is activated.create() was obsoleted in 2. Introduced in platform.0 on.getFocus .resize . Comment on.construction() is new in 2...apiLevel = ’1.restore on. arrowDown ( ) This routine is called when the user presses the down arrow key.2 arrowDown on .3 arrowKey on .0 Only if opening a document and something was saved by on.. Introduced in platform.paint() 7.resize .create() on.0 on. on.construction() on. on.. on..activate ..0’ 7. on.apiLevel = ’1.. on.

0’ 7.4 arrowLeft on . a r r o w L e f t ( ) This routine is called when the user presses the left arrow key. Introduced in platform.7 charIn on .” ”left. The parameter char is normally a one-byte string but because it can contain a UTF-8 encoded character. or other characters.0’ 7.This routine is called when the user presses an arrow key.apiLevel = ’1.0’ 7.6 arrowUp on . c h a r I n ( c h a r ) This routine is called when the user types a letter. arrowUp ( ) This routine is called when the user presses the up arrow key.5 arrowRight on .” or ”right. The key parameter may be ”up.0’ 7.arrowDown for instance) for the particular arrow key type.apiLevel = ’1.apiLevel = ’1. Introduced in platform. Introduced in platform. digit. Introduced in platform.” This routine is not called if the script implements a specific arrow key handler (on.” ”down.apiLevel = ’1. arrowRight ( ) This routine is called when the user presses the right arrow key. 23 .

it may be two or more bytes long.0’ 7.11 construction on . such as ”sin” from the trig menu.apiLevel = ’1.apiLevel = ’1. Introduced in platform.apiLevel = ’1. Introduced in platform.0’ 24 .apiLevel = ’2.apiLevel = ’1.10 clearKey on .9 backtabKey on . c l e a r K e y ( ) This routine is called when the user presses the Clear key on the handheld keypad. backtabKey ( ) This routine is called when the user presses Shift + Tab.0’ 7.0’ 7. Introduced in platform.8 backspaceKey on . Introduced in platform. It may also contain the letters of a function name from one of the short-cut keys. c o n s t r u c t i o n ( ) This function is guaranteed to fire first before any other event. Introduced in platform. backspaceKey ( ) This routine is called when the user presses Backspace on the desktop keyboard or the Del key on the handheld device keypad.0’ 7.

The window size and graphics context are valid at this point.0’ use on.0’ 7.7. Introduced in platform.0’ 25 .12 contextMenu on . This routine is called after resize and before paint when the script application is created.0’ 7.apiLevel = ’1.apiLevel = ’2. It is best to think of this function as an initialization method that fires once automatically. Introduced in platform. The on.enableCopy(enable).apiLevel ≥ ’2.0’ Removed in platform.apiLevel = ’1.13 copy on . contextMenu ( ) This routine is called when the user presses the context Menu key.14 create on .construction() instead.paint event handler will be called soon after this routine finishes. Note Copy is enabled/disabled by toolpalette. Introduced in platform. copy ( ) This routine is called when the user selects the Copy command either from a menu or by pressing Ctrl + C. c r e a t e ( ) Tip For scripts with platform.apiLevel = ’1.

0’ 26 . c u t ( ) This routine is called when the user selects the Cut command either from a menu or by pressing Ctrl + X.enableCut(enable). Introduced in platform.0’ 7. The implementation for this callback should call the corresponding 2d editor to insert a math box if applicable.15 createMathBox on .16 cut on . Introduced in platform.7. Note Cut is enabled/disabled by toolpalette.apiLevel = ’1.0’ 7.18 deleteKey on . Introduced in platform. d e a c t i v a t e ( ) This routine is called when the script is deactivated. This is not the Del key on the handheld keypad.17 deactivate on . Introduced in platform.apiLevel = ’2.apiLevel = ’1.apiLevel = ’1.0’ 7. This happens when the user moves the focus to another page or to another application on the same page. createMathBox ( ) This routine is called when the the user presses Ctrl + M or inserts a Math Box (Expression Box). d e l e t e K e y ( ) This routine is called when the user presses the Delete key on the desktop keyboard.

23 getSymbolList on . enterKey ( ) This routine is called when the user presses the Enter key.0’ 7. escapeKey ( ) This routine is called when the user presses the Esc key.21 escapeKey on . g e t S y m b o l L i s t ( ) 27 . Introduced in platform.22 getFocus on . Introduced in platform.20 enterKey on .0’ 7. d e s t r o y ( ) This routine is called just before the script application is deleted.apiLevel = ’1. Introduced in platform.0’ 7.apiLevel = ’1. g e t F o c u s ( ) This routine is called when the script receives user input focus.apiLevel = ’2.apiLevel = ’1.0’ 7.7.19 destroy on . Introduced in platform. A script app is deleted when it is cut to the clipboard and when the document that contains it is closed.

but not when a problem containing a script app is copied. f u n c t i o n on . g e t S y m b o l L i s t ( ) r e t u r n {” f 1 ”} end Introduced in platform. The TI-NspireTM system copies the names and values of the variables along with the script app.0’ 28 . This is because the entire symbol table is copied when the problem is copied. y ) This routine is called in these situations: • When the user presses and holds the Select key on a device • When the user presses Ctrl + Select on a device • When the user presses the middle mouse button over an active card on the desktop x &y are always zero The grabDown and grabUp events prevent the generation of a mouseUp event in all cases. the following function indicates that it needs variable f1 to be copied with the app to the clipboard.apiLevel = ’1.getSymbolList() is called when a page containing a script app is copied. the system adds the companion variables to the problem symbol table. Then when the user pastes the script app in another problem. They will be preceded by a mouseDown event when generated by pressing and holding the Select key on a device.apiLevel = ’2.0’ 7.24 grabDown on .This routine is called when the script app symbol list is being serialized to the clipboard. The value of f1 will be added to the symbol table when it is pasted into another problem even in another TNS document. Introduced in platform. The script app returns a list of names of variables in the symbol table that it needs to copy with it to the clipboard. For example. Note on. grabDown ( x .

0’ 29 . the Help key is Ctrl + Shift + ?. l o s e F o c u s ( ) This routine is called when the script loses user input focus. On the handheld device.apiLevel = ’1. Introduced in platform. the control key over the Trig button.28 mouseDown on . y ) This routine is called when the mouse button is released while grab is in effect. h e l p ( ) This routine is called when the user presses the Help key.27 loseFocus on .apiLevel = ’1. mouseDown ( x .7.26 help on .0’ 7. it is Ctrl + ?.0’ 7. y ) This routine is called when the user clicks the mouse. On the desktop. Note This event will NOT be generated if the right mouse button is being held down.25 grabUp on . Introduced in platform. x &y are always zero Introduced in platform. x and y are in window-relative pixel coordinates. Introduced in platform. grabUp ( x .apiLevel = ’2.apiLevel = ’1.0’ 7.

0’ 7.apiLevel = ’1.29 mouseMove on .31 paint on . • The preceding mouseDown event was not handled. Note This event will NOT be generated in the following cases: • The preceding mouseDown event was blocked because the right mouse button was down already.0’ 7. Introduced in platform.30 mouseUp on . Introduced in platform. Introduced in platform.32 paste on . mouseUp ( x . p a i n t ( gc ) This routine is called when the script application window needs to be painted.7.apiLevel = ’1. y ) This routine is called when the user moves the mouse pointer. The mouse button does not have to be pressed to receive these events. The gc graphics context is used in the script code to draw on the window.apiLevel = ’1.0’ 7. y ) This routine is called when the user releases the mouse button. mouseMove ( x . p a s t e ( ) 30 .

0’ 7. returnKey ( ) 31 . r e s t o r e ( s t a t e ) This routine is called when the script application is restored from its saved state in a document or when the app is pasted into a document.save handler. Introduced in platform.enablePaste(enable).34 restore on . This is a good place to initialize (or reinitialize) graphical objects based on the window size. The parameter state is the table that the on. Introduced in platform.apiLevel = ’1.isDeviceModeRendering.apiLevel = ’1.0’ 7.restore. Introduced in platform. Note Paste is enabled/disabled by toolpalette.eval and platform. Warning Functionality that is not available during initialization is also not usable within on. See the on. r e s i z e ( width .This routine is called when the user selects the Paste command either from a menu or by pressing Ctrl + V.apiLevel = ’1.0’ 7. Among the functions that cannot be called are math.35 returnKey on . It is called only if the state was saved with the application when it was previously copied to the clipboard or saved in a document.save event handler returned.33 resize on . h e i g h t ) This routine is called when the script application window changes size.

0’ 32 .36 rightMouseDown on . Note Only available on the desktop version. Introduced in platform. x and y are in windowrelative pixel coordinates.apiLevel = ’1. rightMouseDown ( x . Introduced in platform. This event will NOT be generated in the following cases: • The preceding rightMouseDown event was blocked because the left mouse button was already down. Introduced in platform. Note Only available on the desktop version.0’ 7. • The preceding rightMouseDown event was not handled.apiLevel = ’1. y ) This routine is called when the user releases the right mouse button. which means that a rightMouseDown event cannot occur while the left mouse button is being held down and vice versa. y ) This routine is called when the user clicks the right mouse button.apiLevel = ’1.0’ 7.This routine is called when the user presses the Return key (?) on the handheld keypad.37 rightMouseUp on . Mouse events are exclusive. rightMouseUp ( x .

apiLevel = ’1. 33 . Introduced in platform.39 tabKey on . This handler must return a value to indicate if it accepts the new value(s) or vetoes the change.0’ 7.restore event handler is called.7.apiLevel = ’1. Introduced in platform. the system calls this routine each time the timer ticks.0’ 7. Introduced in platform. tabKey ( ) This routine is called when the user presses the Tab key. s a v e ( ) This routine is called when the script app is saved to the document or copied to the clipboard. varChange ( v a r l i s t ) This routine is called when a monitored variable is changed by another application. The varlist is a list of variable names whose values were changed. The script should return a table of whatever data it needs to properly restore when the on.0’ 7.41 varChange on . t i m e r ( ) If the script application implements on.apiLevel = ’1.38 save on .40 timer on .timer.

and this application needs it.Valid return values are: Value 0 -1 -2 -3 Brief Description Success Veto range Veto type Veto existence Comment The script application accepts the change. Introduced in platform. The new value is unsatisfactory because its type cannot be used by the script application. The new value is unsatisfactory because it is outside the acceptable range. that is too low or too high.apiLevel = ’1.0’ 34 . Another application deleted the variable.

Chapter 8

Graphics Library
A graphics context is a module that has a handle to the script’s graphics output window and a library of graphics routines that are used to draw on the window. A graphics context is supplied to the script ”on.paint” event handler each time the window needs to be redrawn. The graphics context employs a pixel-based coordinate system with the origin in the upper left corner of the drawing window.

8.1

clipRect

gc : c l i p R e c t ( op [ , x , [ y , [ width , [ h e i g h t ] ] ] ] ) Sets the clipping rectangle for subsequent graphics operations. Parameter op takes one of the strings ”set,” ”reset,” ”intersect,” or ”null.” Operation reset set Description Sets the clipping rectangle to include the entire window. The remaining parameters are ignored and can be left out. Sets the clipping rectangle to the x, y coordinates with the specified width and height. Unspecified parameters default to the system window location and size. Removed in platform.apilevel = ’2.0’. Sets the clipping rectangle to empty. All subsequent graphics commands are ignored.

intersect null

35

Typically the ”set” operation is called before drawing, such as for a text string. It is important to call the ”reset” operation after drawing the last clipped graphic so that you do not leave a lingering clipping rectangle as a side effect. Introduced in platform.apiLevel = ’1.0’

8.2

drawArc

gc : drawArc ( x , y , width , h e i g h t , s t a r t A n g l e , a r c A n g l e ) Draws an arc in the rectangle with upper left corner (x,y) and pixel width and height. Both the width and height must be ≥ 0. The arc is drawn beginning at startAngle degrees and continues for endAngle degrees. Zero degrees points to the right, and 90 degrees points up (standard mathematical practice but worth mentioning since the y axis is inverted). To draw a circle, the width and height must be equal in length, and the start and end angles must be 0 and 360. If the width and height are different lengths, this routine draws an oval. Introduced in platform.apiLevel = ’1.0’

8.3

drawImage

gc : drawImage ( image , x , y ) Draws an image at (x, y). The image must have been created by a previous call to image.new(...). Introduced in platform.apiLevel = ’1.0’

8.4

drawLine

gc : drawLine ( x1 , y1 , x2 , y2 ) Draws a line from (x1,y1) to (x2,y2). Introduced in platform.apiLevel = ’1.0’

36

8.5

drawPolyLine

gc : drawPolyLine ( { x1 , y1 , x2 , y2 , . . . , xn , yn } ) Draws a series of lines connecting the (x, y) points. The polygon is not closed automatically. The first x-y coordinate pair must be repeated at the end of the array of points to draw a closed polygon. Introduced in platform.apiLevel = ’1.0’

8.6

drawRect

gc : drawRect ( x , y , width , h e i g h t ) Draws a rectangle at (x, y) with the given pixel width and height. Both width and height must be ≥ 0. Introduced in platform.apiLevel = ’1.0’

8.7

drawString

gc : d r a w S t r i n g ( ” t e x t ” , x , y [ , v e r t a l i g n m e n t ] ) Draws text on the window beginning at pixel location (x,y). Vertical alignment may be ”baseline,” ”bottom,” ”middle,” or ”top.” This aligns the text in the height of the characters’ bounding rectangle. If the vertical alignment is unspecified, it defaults to ”none.” Returns the x pixel position after the text. Introduced in platform.apiLevel = ’1.0’

37

8.8

fillArc

gc : f i l l A r c ( x , y , width , h e i g h t , s t a r t A n g l e , endAngle ) Fills an arc with the preset color. Both width and height must be ≥ 0. See setColorRGB to set the fill color. Introduced in platform.apiLevel = ’1.0’

8.9

fillPolygon
. . . xn , yn } )

gc : f i l l P o l y g o n ( { x1 , y1 , x2 , y2 ,

Fills a polygon with the preset color. The array of points bounds the polygon. To set the fill color, see setColorRGB. Introduced in platform.apiLevel = ’1.0’

8.10

fillRect

gc : f i l l R e c t ( x , y , width , h e i g h t ) Fills a rectangle with the preset color. Both the width and height must be ≥ 0. To set the fill color, see setColorRGB. Introduced in platform.apiLevel = ’1.0’

8.11

getStringHeight

gc : g e t S t r i n g H e i g h t ( ” t e x t ” ) Returns the pixel height of the text. The pixel height is determined by the font setting previously set by a call to setFont. Introduced in platform.apiLevel = ’1.0’

38

or 24.8. b l u e ) gc : setColorRGB ( 0xRRGGBB) − p l a t f o r m . and blue components of the color are values in the range of 0 to 255. The point size of the font is restricted on the TI-NspireTM CX and older handheld devices.0. 9.0’ 39 . Any font size supported by Windows R or Mac R OS X R can be used on the desktop software. Family may be ”sansserif” or ”serif”. The pixel width is calculated using the font setting previously set by a call to setFont. 11. Returns the font family. green. style.apiLevel = ’1. 12.14 setFont gc : s e t F o n t ( f a m i l y . a single value can be passed in. Choose one of these sizes: 7. The red.apiLevel = ’1.255.12 getStringWidth gc : g e t S t r i n g W i d t h ( ” t e x t ” ) Returns the pixel width of text. Style may be ”r” for regular. l e v e l = ’ 2 .0’ 8. Introduced in platform. or ”bi” for bold italic. Black is 0.0 and white is 255. green . Introduced in platform.0’ 8. 10. and size previously in effect. ”i” for italic. 0 ’ o n l y Sets the color for subsequent draw and fill routines. s i z e ) Sets the font for drawing text and measuring text size.13 setColorRGB gc : setColorRGB ( red .0’ Extended in platform. ”b” for bold.255.apiLevel = ’2. Introduced in platform. s t y l e .apiLevel = ’1. Alternately. The components of this single value are blue + 255 * (green + 255 * red).

it defaults to ”smooth.” or ”dashed.apiLevel = ’1.0’ 40 .” or ”thick.” ”medium.” If the style is not specified.” The style can be ”smooth.” If the thickness is not specified.” Introduced in platform. s t y l e ] ] ) Sets the pen for drawing lines and borders.” ”dotted. Thickness may be ”thin.15 setPen gc : setPen ( [ t h i c k n e s s [ . it defaults to ”thin.8.

Each pixel is a little endian 16-bit integer with five bits for each color red. Pixels are arranged in rows.1 new img = image . Offset 0 4 8 9 10 12 16 18 Width (bytes) 4 4 1 1 2 4 2 2 Contents Pixel width of image Pixel height of image Image alignment (0) Flags (0) Pad (0) The number of bytes between successive raster lines The number of bits per pixel (16) Planes per bit (1) The image pixel data immediately follows the header. green. arrowheads. and other such graphical adornments. The 41 . 9. new ( s t r ) This function returns a new image object from a string input. All fields are little endian integers. typically small GUI objects such as buttons. The string consists of the image header followed by the binary representation of the image pixels.Chapter 9 Image Library An ”image” object is a container for graphical images. and blue. The header consists of 20 bytes of data arranged as presented in the following table.

0’ 42 . If it is one (1).apiLevel = ’1.0’ 9. 0x801F is blue.apiLevel = ’2. If it is zero (0). the pixel is not drawn.0’ 9.0’ 9.apiLevel = ’1. the pixel is drawn in the RGB color of the remaining 15 bits.3 height h = image : h e i g h t ( ) Returns the pixel height of the image. Introduced in platform.2 copy cimage = image : copy ( width . 0x83E0 is green. 0xFC00 is red. Introduced in platform. Introduced in platform. Introduced in platform.4 rotate rimage = image : r o t a t e ( a n g l e ) Returns a copy of the input image rotated counterclockwise by angle degrees. h e i g h t ) Returns a copy of the input image scaled to fit the specified pixel width and height.apiLevel = ’1. The width and height default to the size of the input image. and 0xFFFF is white. 0x8000 is black.top bit determines if the pixel is drawn.

apiLevel = ’1. Introduced in platform.9.0’ 43 .5 width w = image : width ( ) Returns the pixel width of the image.

Chapter 10 Locale Library 10. The language code may be followed by an underscore and two-letter country code. name ( ) Returns the name of the current locale.apiLevel = ’1.0’ 44 . Introduced in platform. The locale name is a two-letter language code.1 name l o c a l e .

The input expression must be a string that the TI-NspireTM math server can 45 .getEvalSettings() and apply the appropriate precision before displaying the value returned by the TI-NspireTM math server. the math server uses Unicode character U+F02F. there is an interface to the TI-NspireTM math server that allows access to the advanced mathematical features of the TI-NspireTM product. retrieve the current display digits via math. a p i L e v e l = ’ 1 . 0 ’ This function sends an expression or command to the TI-NspireTM math server for evaluation.1 eval math . i. See TI-NspireTM Reference Guide for a list of unicode characters used in TI-NspireTM software. 0 ’ math . e x a c t ] ) −− p l a t f o r m . 11. To limit the precision of the result to the display digits. a p i L e v e l = ’ 2 . (See http://en. for imaginary numbers and another special character for the exponent for a scientific notation. small capital letter ”E”. For example. All results from the TI-NspireTM math server are returned as full-precision expressions. e v a l ( m a t h e x p r e s s i o n [ .wikipedia. UTF-8 character ”\239\128\175”.org/wiki/UTF-8 for a description of how to convert unicode to UTF-8 and vice versa. Note The TI-NspireTM math server uses a number of unicode characters. e v a l ( m a t h e x p r e s s i o n ) −− p l a t f o r m .Chapter 11 Math Library Extension In addition to the functions that come with the standard Lua math library.

) If the math server calculates a symbolic result. except that all evaluations are performed at full precision in approximate mode.eval. the parameter x must be converted to a string. l o c a l mx = t o s t r i n g ( x ) : gsub ( ” e ” . it cannot be represented as a fundamental Lua type. the evaluation is performed using the current document settings.eval(’1 and 2’) returns ”Argument must be a Boolean expression or integer” error Convert to base 10 r.” Example To evaluate f1 for a given value in x.e = math. The second parameter. in which case the math server attempts to calculate an approximate result.eval is not available during script initialization. If true. The current document settings can be overriden by math. or semantic error. If the math server cannot evaluate the expression because of a syntax. .setEvalSettings. it instructs the math server to calculate and return exact numerical results when it can. and then any embedded ”e” must be replaced with Unicode character U+F000. Beginning with platform. things like Boolean logic and some conversions will throw an error: Boolean logic: r. exact. it returns the results as a fundamental Lua data type.apiLevel = ’2. simplification. e v a l ( expr ) Note Because math. Warning math.evalStr works fine in such cases.Error Codes and Messages for math.apiLevel = ’1. so eval returns nil and the string ”incompatible data type. The default value of exact is false.0 only) is meaningful only with the Computer Algebra System.interpret and evaluate. ” ) ” r e t u r n math .eval(”0@>Base10”) returns ”Domain Error” math.eval always does calculations in approximate mode.e = math. s t r i n g . 46 .0’. mx . . eval returns two results: nil and an error number meaningful to the math server. (platform. (The error numbers are documented in the TI-NspireTM Reference Guide . uchar ( 0 xF000 ) ) l o c a l expr = ” f 1 ( ” . If the math server evaluates the expression successfully.

1 . byte ( r e s u l t . z ) − > 1. which is small capital letter ”E”. e r r o r = math . z ) − >?1. e v a l S t r ( ’2 − 3 ’) v . w. r e s u l t . which is a minus sign. Examples The evaluation of ”10∧ 19” in exact mode returns ”1.0’ 11. u . 1 . y .Introduced in platform. w. which can be overriden by math. w.2 evalStr math . evalStr returns two results: nil and an error number meaningful to the math server.0’ Revised to remove the optional argument exact and use current document settings. If the math server evaluates the expression successfully. e r r o r = math . ”\239\128\128” is Unicode character U+F000. 7 ) p r i n t ( r e s u l t . z = s t r i n g .?19 7 49 46 239 128 128 49 57 The evaluation of ”2-3” returns ”-1”. v . t . v . 5 ) p r i n t ( r e s u l t . y . x .apiLevel = ’1. e v a l S t r ( ’ 1 0 ˆ 1 9 ’ ) t . byte ( r e s u l t . ”\226\136\146” is Unicode character U+2212.setEvalSettings. e v a l S t r ( m a t h e x p r e s s i o n ) This function sends an expression or command to the TI-NspireTM math server for evaluation. The result string will be encoded as ”\226\136\146\49”. 19”. #r e s u l t . r e s u l t . simplification. NOTE: All evaluations are performed at full precision regardless of the document settings or overrides. u . w. #r e s u l t . x . y . The evalStr function returns no result if the math server does not return a calculated result. If the math server cannot evaluate the expression because of a syntax. z = s t r i n g . it returns the results as a string. y . and full precision in platform. The evaluation is performed using the current document settings. v . 5 226 136 146 49 46 47 . x . x . or semantic error. approximate mode. The input expression must be a string that the TI-NspireTM math server can interpret and evaluate. A closer look at the result string indicates that it contains ”\049\046\239\128\128\49\57”.apilevel = ’2.

{ ’ Vector Format ’ . s e t E v a l S e t t i n g s ( s e t t i n g S t r u c t u r e ) This function is used to override one or more of the current document settings for all subsequent math evaluations performed by math.3 getEvalSettings math . g e t E v a l S e t t i n g s ( ) Returns a table of tables with the document settings that are currently being used by math.eval. ’ Polar ’ } . 48 . ’ Binary ’ } .Introduced in platform. ’ Eng/US’ } . These settings are equivalent to the current document settings unless a call has been made to setEvalSettings . { ’ Angle Mode ’ .eval and math. ’ Fixed12 ’ } . { ’ C a l c u l a t i o n Mode ’ .evalStr.apiLevel = ’2.0’ 11. It does not change the document context settings. { ’ E x p o n e n t i a l Format ’ . { ’ Base ’ . The setting structure is a table of tables. } } Introduced in platform. ’ C y l i n d r i c a l ’ } . { ’ Real o r Complex Format ’ . { ’ Unit System ’ .0’ 11. ’ E n g i n e e r i n g ’ } . Example This example serves to demonstrate the structure of the table returned by getEvalSettings. ’ Approximate ’ } .apiLevel = ’2. { { ’ D i s p l a y D i g i t s ’ . Each inner table consists of the name of the document setting to override and the name of the value to use instead. ’ Gradian ’ } .4 setEvalSettings math .

’ Eng/US’ } . 49 . 3} . { ’ C a l c u l a t i o n Mode ’ . setEvalSettings also accepts the ordinal number of the setting to override and the ordinal number of the value to use instead. So the following is also valid. {4 . 3} . { 8 . { ’ Real o r Complex Format ’ .setEvalSettings() using a table with ordinal numbers settingsTable = { {2 . 2} } math . The ordinal numbers to use correspond to the order of the settings and their values found at File > Settings > Document Settings. Example Sample call to math. ’ E n g i n e e r i n g ’ } } math . s e t E v a l S e t t i n g s ( s e t t i n g s ) For user convenience. s e t E v a l S e t t i n g s ( s e t t i n g s T a b l e ) In fact. 3} . ’ Polar ’ } . { ’ E x p o n e n t i a l Format ’ . setEvalSettings accepts any combination of names and ordinal numbers. ’ Approximate ’ } .setEvalSettings() settings = { { ’ Unit System ’ . {6 .Example Sample call to math.

The modified document settings are used by math.getEvalSettings() and apply the appropriate precision before displaying the value returned by the TI-NspireTM math server. ’ Exact ’ } . { ’ Angle Mode ’ . they must call math. 2} } math .setEvalSettings may be called at any point in the script app. Note All results from the TI-NspireTM math server are returned as full-precision expressions. s e t E v a l S e t t i n g s ( s e t t i n g s ) The function math.setEvalSettings() using a table with combined names and numbers settings = { { 3 . { 8 . { ’ Real o r Complex Format ’ .0’ 50 . ’ Polar ’ } . 2 } . If users want to limit the display digits.apiLevel = ’2. Introduced in platform.eval for all subsequent calls within the script app (unless modified by a subsequent call to setEvalSettings ).Example Sample call to math.

4-Docs/.apiLevel = 2. INFINITY ( ) Parameter infinity Type out number Description Infinity Returns a number representing infinity in the physics engine. This library is introduced in platform. 12.apiLevel = ’2.4.0.2 momentForBox i n e r t i a = p h y s i c s . Introduced in platform.net/release/Chipmunk-5. For details about this library see http://chipmunk-physics.Chapter 12 Physics Library This is an interface library to Chipmunk Physics version 5.3.3. momentForBox ( mass .x/Chipmunk-5.1.1.0’ 12. misc . h e i g h t ) 51 . misc . To use this library the physics module must be loaded: ”require (’ physics ’)” .1 12. width .1 Miscellaneous routines INFINITY i n f i n i t y = p h y s i c s .

o f f s e t ) Parameter mass vertices offset inertia Type in number in {physics.apiLevel = ’2.) constructor.1.Vect out number Description The mass of the polygon A list of vertices defining the shape of the polygon The offset of the polygon from the center of gravity The inertia of the polygon 52 .0’ 12.Body(.Body(. misc . o u t e r R a d i u s . momentForPoly ( mass . This is a useful helper routine for computing the moment of inertia as an input to the physics..1..Parameter mass width height inertia Type in number in number in number out number Description The The The The mass of the box width of the box height of the box inertia of the box This routine computes the moment of inertia for a solid box. momentForCircle ( mass .) constructor.Vect} in physics. Introduced in platform. A solid circle has an inner radius of 0.. i n n e r R a d i u s .3 momentForCircle i n e r t i a = p h y s i c s .. misc . o ff Bo d y ) Parameter mass innerRadius outerRadius offset inertia Type in number in number in number in physics.4 momentForPoly i n e r t i a = p h y s i c s . v e r t i c e s . Introduced in platform. This is a useful helper routine for computing the moment of inertia as an input to the physics.0’ 12.Vect out number Description The The The The The mass of the circle inner radius of the circle outer radius of the circle offset of the circle from the center of gravity inertia of the circle This routine computes the moment of inertia for a circle.apiLevel = ’2.

2 Vectors A vector is a 2-dimensional object with x and y components. y ) v e c t o r = p h y s i c s .5 momentForSegment i n e r t i a = p h y s i c s . Vect ( x . The end points can be in either world or local coordinates.. Its type is TI.Vect out physics.1.Vect in physics..apiLevel = ’2. Introduced in platform. This is a useful helper routine for computing the moment of inertia as an input to the physics..) constructor. Vect ( v e c t ) Parameter x y angle vect vector Type in number in number in number in physics.0’ 12. momentForSegment ( mass . endPointB ) Parameter mass endPointA endPointB inertia Type in number in physics. Introduced in platform.Body(.apiLevel = ’2. This is a useful helper routine for computing the moment of inertia as an input to the physics.) constructor.Vect Description The x component of the vector The y component of the vector An angle in radians A vector A vector 53 .cpVect.Vect out number Description The The The The mass of the segment point defining one end of the segment point defining the other end of the segment inertia of the segment This routine computes the moment of inertia for a segment. misc . endPointA ..0’ 12.2.Body(.1 Vect v e c t o r = p h y s i c s .This routine computes the moment of inertia for a polygon. 12. Vect ( a n g l e ) v e c t o r = p h y s i c s .

Vect in number out physics. Introduced in platform.apiLevel = ’2.2 add sum = p h y s i c s .Vect Description The input vector A vector to add to self The vector sum of self and vec Returns the vector sum of self and vec.0’ 12. The second form creates a unit vector pointing in direction angle.0’ 12.4 cross c r o s s p r o d = p h y s i c s . Introduced in platform.2.Vect out physics.apiLevel = ’2.Vect in physics.2. Vect : clamp ( l e n ) Parameter self len clamped Type in physics.3 clamp clamped = p h y s i c s .Vect Description The input vector The maximum length of the vector A new vector with a length no longer than len Returns a copy of self clamped to length len . The Vect class also implements the addition operator (+). Introduced in platform. Vect : c r o s s ( vec ) 54 .Creates a vector with initial x and y component values. The third form creates a copy of the input vector. Vect : add ( vec ) Parameter self vec sum Type in physics.apiLevel = ’2. Therefore vectors v1 and v2 can be added with the expression v1 + v2.2.0’ 12.

Parameter self vec zmag

Type in physics.Vect in physics.Vect out number

Description The input vector The vector to cross with self The z magnitude of the cross product of self and vec

Returns the z magnitude of the cross product of self and vec. Introduced in platform.apiLevel = ’2.0’

12.2.5

dist

d i s t = p h y s i c s . Vect : d i s t ( vec ) Parameter self vec dist Type in physics.Vect in physics.Vect out number Description The input vector The vector to which to find the distance from self The distance from self to vec

Returns the distance between self and vec. Introduced in platform.apiLevel = ’2.0’

12.2.6

distsq

d i s t s q = p h y s i c s . Vect : d i s t s q ( vec ) Parameter self vec distsq Type in physics.Vect in physics.Vect out number Description The input vector The vector to which to find the distance squared from self The distance squared from self to vec

Returns the distance squared between self and vec. For distance comparison this routine is faster than physics .Vect: dist . Introduced in platform.apiLevel = ’2.0’

12.2.7

dot

dotprod = p h y s i c s . Vect : dot ( vec ) 55

Parameter self vec dotprod

Type in physics.Vect in physics.Vect out number

Description The input vector The other vector The scalar dot product of self and vec

Returns the scalar dot product of self and vec. Introduced in platform.apiLevel = ’2.0’

12.2.8

eql

i s e q u = p h y s i c s . Vect : e q l ( vec ) Parameter self vec isequ Type in physics.Vect in physics.Vect out boolean Description The input vector The vector against which to compare with self True if the components of self equal the components of vec

Returns true if the x and y components of self equal those of vec. Take the usual precautions when comparing floating point numbers for equality. The Vect class also implements the equal comparison operator (==). Therefore vectors v1 and v2 can be compared with the expression v1 == v2. Introduced in platform.apiLevel = ’2.0’

12.2.9

length

l e n = p h y s i c s . Vect : l e n g t h ( ) Parameter self len Type in physics.Vect out number Description The input vector The length of vector self

Returns the magnitude of self . Introduced in platform.apiLevel = ’2.0’

56

12.2.10

lengthsq

l e n s q = p h y s i c s . Vect : l e n g t h s q ( ) Parameter self lensq Type in physics.Vect out number Description The input vector The length squared of vector self

Returns the length squared of self . This routine is faster than Vect:length() when you only need to compare lengths. Introduced in platform.apiLevel = ’2.0’

12.2.11

lerp

v = p h y s i c s . Vect : l e r p ( vec , f ) Parameter self vec f v Type in physics.Vect in physics.Vect in number out physics.Vect Description The input vector The other vector f is a fractional number from 0 to 1 representing the proportion of distance between self and vec A vector interpolated between self and vec

Returns the linear interpolation between self and vec as a vector. f is the fraction of distance between self and vec. Note May not behave as expected for f larger than 1.0 or less than 0. Introduced in platform.apiLevel = ’2.0’

12.2.12

lerpconst

v = p h y s i c s . Vect : l e r p c o n s t ( vec , d )

57

0’ 58 . Vect : n e a r ( vec .Vect in number out boolean Description The input vector The value to multiply by self The distance from vec True if self is within distance of vec Determines if self is near another vector.14 near i s n e a r = p h y s i c s .13 mult v = p h y s i c s .2.Vect in number out physics.Vect in number out physics.apiLevel = ’2.0’ 12. d i s t a n c e ) Parameter self vec distance isnear Type in physics.0’ 12.apiLevel = ’2.Vect in physics.Vect Description The input vector The other vector The distance from self to vec to interpolate a new vector Returns a vector interpolated from self towards vec with length d.Vect Description The input vector The value to multiply by self The resulting scaled vector Multiplies a vector by a factor.apiLevel = ’2. Introduced in platform.0 or less than 0. Vect : mult ( f a c t o r ) Parameter self factor v Type in physics.Parameter self vec d v Type in physics.2.Vect in physics. Introduced in platform. Introduced in platform. Note May not behave as expected for d larger than 1.

apiLevel = ’2.Vect out physics. The Vect class also implements the unary minus operator (. Introduced in platform. Introduced in platform.Vect out physics.0’ 12. Vect : neg ( ) Parameter self v Type in physics.apiLevel = ’2.Vect Description The input vector The resulting normalized vector Returns a normalized copy of self .2. Protects against division by zero.2. Vect : n o r m a l i z e S a f e ( ) Parameter self normvec Type in physics.16 normalize normvec = p h y s i c s .0’ 59 .15 neg v = p h y s i c s . Introduced in platform.apiLevel = ’2. The length of a normal vector is 1.self ).12.Vect Description The input vector The resulting normalized vector Returns a normalized copy of self . Vect : n o r m a l i z e ( ) Parameter self normvec Type in physics.17 normalizeSafe normvec = p h y s i c s .Vect out physics.Vect Description The input vector The resulting negated vector Returns the negative of self .0’ 12.2.

Introduced in platform.apiLevel = ’2.Vect in physics.2. Vect : perp ( ) Parameter self perpvec Type in physics.Vect out physics.18 perp p e r p v e c = p h y s i c s .0’ 60 .Vect in physics. Introduced in platform.Vect out physics.12.0’ 12.Vect Description The input vector The other vector The resulting rotated vector Uses complex multiplication to rotate self by vec.19 project pvec = p h y s i c s .2.Vect Description The input vector The other vector The vector of self projected onto vec Computes the projection of self onto another vector.20 rotate r v e c = p h y s i c s .2.apiLevel = ’2.Vect Description The input vector The resulting perpendicular vector Returns a vector perpendicular to self . (90 degree rotation) Introduced in platform. Vect : p r o j e c t ( vec ) Parameter self vec pvec Type in physics. Vect : r o t a t e ( vec ) Parameter self vec rvec Type in physics.0’ 12. Scaling will occur if self is not a unit vector.Vect out physics.apiLevel = ’2.

2.Vect Description The vector to modify The new value of the y component of the vector The input vector is returned as the output Changes the value of the y component of self . Vect : r p e r p ( ) Parameter self perpvec Type in physics. Introduced in platform.Vect in number out physics. Vect : s e t x ( x ) Parameter self x self Type in physics. Vect : s e t y ( y ) Parameter self y self Type in physics. (90 degree rotation) Introduced in platform.apiLevel = ’2.0’ 12.12.2. Returns self . Returns self .Vect in number out physics.2.23 sety s e l f = p h y s i c s .22 setx s e l f = p h y s i c s .21 rperp p e r p v e c = p h y s i c s .Vect Description The input vector The resulting perpendicular vector Returns a vector perpendicular to self .0’ 12.apiLevel = ’2. Introduced in platform.Vect out physics.Vect Description The vector to modify The new value of the x component of the vector The input vector is returned as the output Changes the value of the x component of self .apiLevel = ’2.0’ 61 .

24 slerp v = p h y s i c s .0 or less than 0. l o c a l v e c t 1 = p h y s i c s . p i / 2 ) l o c a l r e s u l t = v e c t 1 : s l e r p ( vec t2 .wikipedia.Vect in number out physics. Introduced in platform. and usage of spherical linear interpolation. 62 . Vect : s l e r p ( vec .2.Vect in physics. a n g l e ) Parameter self vec angle v Type in physics. Info See [http://en. May not behave as expected for f larger than 1.Vect Description A unit vector The other unit vector f is a fractional number from 0 to 1 representing the proportion of distance between self and vec A vector interpolated between self and vec Computes a spherical linear interpolation between unit vectors self and vec. f ) Parameter self vec f v Type in physics. Vect : s l e r p c o n s t ( vec . 5 5 ) Note This routine computes meaningful results only when the two inputs are unit vectors.12.apiLevel = ’2. 0 . Vect ( math .Vect in physics.25 slerpconst v = p h y s i c s . p i / 3 ) l o c a l v e c t 2 = p h y s i c s .Vect in number out physics.0’ −− u n i t v e c t o r −− u n i t v e c t o r 12.Vect Description A unit vector The other unit vector The maximum angle between self and vec to interpolate a new vector Returns the spherical linear interpolation from self towards vec but by no more than angle in radians.2. Vect ( math . value.org/wiki/Slerp] for a discussion of the meaning.

apiLevel = ’2.0’ 63 . value.2. Introduced in platform.org/wiki/Slerp for a discussion of the meaning. Introduced in platform. Vect : t o a n g l e ( ) Parameter self angle Type in physics.26 sub d i f f = p h y s i c s .Info See http://en.apiLevel = ’2. Introduced in platform.Vect out physics.Vect out number Description The input vector The angle of self Returns the angle in radians of self . The Vect class also implements the subtraction operator (-).apiLevel = ’2.wikipedia.2. Note This routine computes meaningful results only when the two inputs are unit vectors. Vect : sub ( vec ) Parameter self vec diff Type in physics.Vect in physics.Vect Description The input vector A vector to subtract from self The vector difference between self and vec Returns the vector difference of self and vec.0’ 12.27 toangle a n g l e = p h y s i c s .0’ 12.v2. Therefore vector v2 can be subtracted from v1 with the expression v1 . and usage of spherical linear interpolation.

12. Vect : x ( ) Parameter self x Type in physics.Vect out physics. Vect : u n r o t a t e ( vec ) Parameter self vec uvec Type in physics.0’ 12.2.29 x x = p h y s i c s .Vect in physics.apiLevel = ’2. Introduced in platform.0’ 12.2.30 y y = p h y s i c s .28 unrotate uvec = p h y s i c s .Vect Description The input vector The other vector The resulting unrotated vector Inverse of physics. Vect : y ( ) Parameter self y Type in physics.Vect out number Description The input vector The value of the y component of the vector Returns the value of the y component of the input vector.Vect:rotate(vec).Vect out number Description The input vector The value of the x component of the vector Returns the value of the x component of the input vector.2.apiLevel = ’2. Introduced in platform.0’ 64 . Introduced in platform.apiLevel = ’2.

apiLevel = ’2. and top edges of a box.3 clampVect c v e c = p h y s i c s . bottom. Introduced in platform. Introduced in platform. right.1 BB bb = p h y s i c s .12. right.3 Bounding Boxes A bounding box is a structure the contains the left.3.0’ 12. 12.apiLevel = ’2. r .2 b bottom = p h y s i c s .0’ 12.BB: clampVect ( vec ) 65 .3.BB( l .3. Its type is TI. b .BB: b ( ) Parameter self bottom Type in physics. t ) Parameter l b r t bb Type in number in number in number in number out physics. bottom.BB out number Description The input bounding box The bottom edge of the bounding box Returns the bottom edge of the bounding box.BB Description left bottom right top A bounding box with boundaries left. and top Returns a new bounding box with the given initial edges.cpBB.

3.Vect out boolean Description The input bounding box A vector True if self contains vector vec Determines if a bounding box contains a vector.6 expand bb = p h y i c s .5 containsVect b o o l = p h y s i c s .Parameter self vec cvec Type in physics.BB in physics.BB: expand ( vec ) 66 .apiLevel = ’2. Introduced in platform.BB out boolean Description The input bounding box The other bounding box True if self completely contains the other bounding box Determines if a bouding box contains another bounding box.3.apiLevel = ’2.0’ 12.BB in physics.BB: c o n t a i n s V e c t ( vec ) Parameter self vec bool Type in physics.4 containsBB b o o l = p h y s i c s .BB in physics. Introduced in platform.0’ 12.Vect out physics.3. Introduced in platform.Vect Description The input bounding box A vector A vector clamped to the bounding box Returns a copy of vec clamped to the bounding box.BB: containsBB ( o t h e r ) Parameter self other bool Type in physics.0’ 12.apiLevel = ’2.

7 intersects b o o l = p h y s i c s .BB: i n t e r s e c t s ( o t h e r ) Parameter self other bool Type in physics.BB: merge ( o t h e r ) 67 .BB in physics.apiLevel = ’2. Introduced in platform.BB out number Description The input bounding box The left edge of the bounding box Returns the left edge of the bounding box.apiLevel = ’2.apiLevel = ’2.0’ 12.BB: l ( ) Parameter self left Type in physics.BB in physics.3.0’ 12.3.BB Description The input bounding box A vector The bounding box self expanded to include vector vec Returns the bounding box that contains both self and vec.BB out boolean Description The input bounding box The other bounding box True if self intersects the other bounding box Determines if two bounding boxes intersect. Introduced in platform.Vect out physics.3.8 l l e f t = p h y s i c s .Parameter self vec bb Type in physics.9 merge bb = p h y s i c s . Introduced in platform.0’ 12.

0’ 12. Introduced in platform. Introduced in platform.3.0’ 12. Introduced in platform.Parameter self other bb Type in physics.BB: s e t l ( l e f t ) 68 . Returns self .BB: s e t b ( bottom ) Parameter self bottom self Type in physics.10 setb s e l f = p h y s i c s .BB out number Description The input bounding box The right edge of the bounding box Returns the right edge of the bounding box.BB in physics.apiLevel = ’2.3.3.apiLevel = ’2.BB in number out physics.11 r r i g h t = p h y s i c s .BB out physics.12 setl s e l f = p h y s i c s .BB: r ( ) Parameter self right Type in physics.apiLevel = ’2.0’ 12.BB Description The input bounding box The new value for the bottom edge of the bounding box The input bounding box is returned as the output Sets the bottom edge of the bounding box to a new value.BB Description The input bounding box The other bounding box The bounding box that contains both self and the other bounding box Returns the bounding box that contains both self and the other bounding box.

15 t top = p h y s i c s .13 setr s e l f = p h y s i c s .BB Description The input bounding box The new value for the left edge of the bounding box The input bounding box is returned as the output Sets the left edge of the bounding box to a new value.14 sett s e l f = p h y s i c s .BB: s e t t ( top ) Parameter self top self Type in physics.Parameter self left self Type in physics.BB in number out physics. Introduced in platform.BB Description The input bounding box The new value for the right edge of the bounding box The input bounding box is returned as the output Sets the right edge of the bounding box to a new value.BB in number out physics.BB in number out physics.3.0’ 12.apiLevel = ’2. Introduced in platform.0’ 12.0’ 12.3.3.apiLevel = ’2. Returns self . Returns self . Introduced in platform.apiLevel = ’2.BB: s e t r ( r i g h t ) Parameter self right self Type in physics.BB Description The input bounding box The new value for the top edge of the bounding box The input bounding box is returned as the output Sets the top edge of the bounding box to a new value. Returns self .BB: t ( ) 69 .

Body Description Mass of the body The inertia of the body A new Body with the supplied mass and inertia Returns a new Body with the given mass and moment of inertia.3. 70 .cpBody. position.apiLevel = ’2.4.BB: wrapVect ( vec ) Parameter self vec wvec Type in physics.) of an object. etc. velocity.1 Body body = p h y s i c s .Vect Description The input bounding box A vector A vector wrapped to the bounding box Returns a copy of vec wrapped to the bounding box. Introduced in platform.apiLevel = ’2. Its type is TI.16 wrapVect wvec = p h y s i c s . Use the provided helper functions to compute the moment of inertia.Vect out physics. rotation.BB out number Description The input bounding box The top edge of the bounding box Returns the top edge of the bounding box. 12. Introduced in platform. i n e r t i a ) Parameter mass inertia body Type in number in number out physics.Parameter self top Type in physics.BB in physics. It does not have a shape until you attach one (or more) to it. Body ( mass .0’ 12.4 Bodies A body holds the physical properties (mass.0’ 12.

3 angle a n g l e = p h y s i c s .apiLevel = ’2.Introduced in platform.Body out physics.4-Docs/ for an explanation of this routine. Introduced in platform.net/release/Chipmunk-5.4.x/Chipmunk-5. Body : angVel ( ) Parameter self avel Type in physics.0’ 12.4.0’ 12.Body Description The input Body The input Body is returned as the output Activates a sleeping body.Body out number Description The input Body The angular velocity of the Body in radians per unit time 71 .3.4.2 activate s e l f = p h y s i c s .apiLevel = ’2. Body : a n g l e ( ) Parameter self angle Type in physics.4 angVel a v e l = p h y s i c s .Body out number Description The input Body The angle of the Body in radians Returns the angle in radians of the orientation of the body. Body : a c t i v a t e ( ) Parameter self self Type in physics. Info See http://chipmunk-physics. Introduced in platform.0’ 12.apiLevel = ’2.

Introducted in platform.apiLevel = ’2. Introduced in platform.0’ 12.4. Body : a p p l y I m p u l s e ( impulseVect .apiLevel = ’2. Introducted in platform.0’ 12.Vect out physics. Body : a p p l y F o r c e ( f o r c e V e c t .4.7 data o b j = p h y s i c s .apiLevel = ’2.Body in physics.Body in physics.Vect in physics.Body Description The input Body A force vector Vector offset of the force relative to the Body The input Body is returned as the output Apply force vector on self at a relative offset from the center of gravity. r O f f s e t ) Parameter self forceVect rOffset self Type in physics.Returns the angular velocity of the body in radians per unit time.Body Description The input Body Impulse force on the Body Vector offset of the force relative to the Body The input Body is returned as the output Apply the impulse vector to self at a relative offset from the center of gravity.Vect out physics. r O f f s e t ) Parameter self impulseVect rOffset self Type in physics.6 applyImpulse s e l f = p h y s i c s .Vect in physics.5 applyForce s e l f = p h y s i c s .4.0’ 12. Body : data ( ) 72 .

Body out physics.0’ 12.4.net/release/Chipmunk-5.apiLevel = ’2.Parameter self obj Type in physics.x/Chipmunk-5.apiLevel = ’2.8 force f v e c = p h y s i c s .4-Docs/ for an explanation of rogue bodies. Body : isRogue ( ) Parameter self bool Type in physics. Info See http://chipmunk-physics. never having been added to the simulation Space.9 isRogue b o o l = p h y s i c s .Body out Lua object Description The input Body An object previously set on the Body by the programmer Returns the contents of the programmer data field of the Body.3.0’ 12. Introducted in platform.apiLevel = ’2.0’ 73 . Introduced in platform.Vect Description The input Body The force vector on the Body Returns the force vector on the body. Body : f o r c e ( ) Parameter self fvec Type in physics.4.Body out boolean Description The input Body True if the Body is a rogue Body Returns true if the Body is a rogue Body. Introduced in platform.

x/Chipmunk-5.Vect Description The input Body A vector relative to the position of the Body A vector in world coordinates Converts lvec from body-relative coordinates to world coordinates.Body out number Description The input Body The total kinetic energy of the Body Returns the kinetic energy of the body.0’ 12.4. 74 . Body : k i n e t i c E n e r g y ( ) Parameter self ke Type in physics.apiLevel = ’2. Body : l o c a l 2 W o r l d ( l v e c ) Parameter self lvec wvec Type in physics.4.net/release/Chipmunk-5.10 isSleeping b o o l = p h y s i c s . Info See http://chipmunk-physics.4-Docs/ for an explanation of sleeping bodies.0’ 12.Body in physics.Vect out physics.12.3. Introduced in platform. Introduced in platform.4.11 local2World wvec = p h y s i c s .Body out boolean Description The input Body True if the Body is sleeping Returns true if the body is sleeping.12 kineticEnergy ke = p h y s i c s . Body : i s S l e e p i n g ( ) Parameter self bool Type in physics.apiLevel = ’2. Returns the converted vector.

Body out number Description The input Body The moment of inertia of the Body Returns the moment of inertia of the body.0’ 75 .apiLevel = ’2. Introduced in platform.4.0’ 12. Body : pos ( ) Parameter self p Type in physics.4.apiLevel = ’2.13 mass m = p h y s i c s .0’ 12.apiLevel = ’2.14 moment m = p h y s i c s . Body : mass ( ) Parameter self m Type in physics.15 pos p = p h y s i c s . Body : moment ( ) Parameter self m Type in physics.Vect Description The input Body The position of the Body Returns the vector position of the body.Body out physics.Body out number Description The input Body The mass of the Body Returns the mass of the body.apiLevel = ’2.0’ 12.Introduced in platform. Introduced in platform. Introduced in platform.4.

Body : r e s e t F o r c e s ( ) Parameter self self Type in physics.0’ 76 .apiLevel = ’2.Body Description The input Body The angle of rotation in radians of the Body The input Body is returned as the output Updates the angle of rotation in radians of the body.Body Description The input Body The input Body is returned as the output Zero both the force and torque accumulated on self .0’ 12.18 setAngle s e l f = p h y s i c s .0’ 12.4.4.apiLevel = ’2. This is a unit vector cached from the last calculated angle of the Body. Introduced in platform.4. Introduced in platform.17 rot r v e c = p h y s i c s .12.apiLevel = ’2.16 resetForces s e l f = p h y s i c s .Vect Description The input Body The unit vector orientation of the Body Returns the vector orientation of the body. Body : s e t A n g l e ( a n g l e ) Parameter self angle self Type in physics. Returns the Body. Introducted in platform.Body out physics.Body in number out physics. Body : r o t ( ) Parameter self rvec Type in physics.Body out physics.

Body Description The input Body A programmer-supplied Lua object The input Body is returned as the output Sets the programmer data field of the Body.4. Body : s e t F o r c e ( v e c t o r ) Parameter self vector self Type in physics.apiLevel = ’2.20 setData s e l f = p h y s i c s .Body in physics. This is a handy place to store a reference to a simulation object. Returns the Body.apiLevel = ’2.Vect out physics.Body Description The input Body The vector of force on the Body The input Body is returned as the output 77 . Introduced in platform.Body in number out physics. The angular velocity is in radians per unit time.21 setForce s e l f = p h y s i c s .Body in object out physics.Body Description The input Body The angular velocity in radians per unit time of the Body The input Body is returned as the output Updates the angular velocity of the body.0’ 12. The programmer can store any Lua object in this field. Introduced in platform. Body : setAngVel ( v e l ) Parameter self vel self Type in physics. Returns the Body.19 setAngVel s e l f = p h y s i c s .4.12. Body : s e t D a t a ( v a l u e ) Parameter self value self Type in physics.4.0’ 12.

Returns the Body.Body in number out physics.Body in number out physics. Body : setMass ( mass ) Parameter self mass self Type in physics. Returns the Body. Introduced in platform. Introduced in platform.4.4.apiLevel = ’2.4. Body : s e t P o s ( v e c t o r ) 78 .apiLevel = ’2.apiLevel = ’2.Updates the force vector on the body.0’ 12.0’ 12. Returns the Body.0’ 12.Body Description The input Body The moment of inertia of the Body The input Body is returned as the output Updates the moment of inertia of the body.22 setMass s e l f = p h y s i c s .Body Description The input Body The mass of the Body The input Body is returned as the output Updates the mass of the body. Use the provided helper functions to compute the moment of inertia. Introduced in platform. Body : setMoment ( moment ) Parameter self moment self Type in physics.23 setMoment s e l f = p h y s i c s .24 setPos s e l f = p h y s i c s .

25 setPositionFunc s e l f = p h y s i c s .0’ 12. Returns the Body.apiLevel = ’2.26 setTorque s e l f = p h y s i c s .Body Description The input Body The position of the Body The input Body is returned as the output Updates the position of the body. 79 . Returns the Body.apiLevel = ’2. Body : s e t P o s i t i o n F u n c ( f u n c ) Parameter self func self Type in physics. dt) out physics.Vect out physics.Body in function(body. Returns the Body.Body Description The input Body The torque of the Body The input Body is returned as the output Updates the torque on the body. The position function must be a function that accepts a Body and a time step value and at some point calls body:updatePosition to update the position of the body. Torque is a numeric magnitude.Body in physics.4. Introduced in platform.Parameter self vector self Type in physics. Body : s e t T o r q u e ( t o r q u e ) Parameter self torque self Type in physics.Body Description The input Body A callback function that updates the position of the Body on each time step The input Body is returned as the output Sets the position function of the body.Body in number out physics. Introduced in platform.4.0’ 12.

4.28 setVelocityFunc s e l f = p h y s i c s . dt) Description The input Body A callback function that updates the velocity of the Body on each time step The input Body is returned as the output self out physics.apiLevel = ’2. damping. Returns the Body.4.Body Sets the velocity function of the body.Introduced in platform. Introduced in platform.Body in function(body. Returns the Body. 80 .27 setVel s e l f = p h y s i c s . Body : s e t V e l ( v e c t o r ) Parameter self vector self Type in physics.Body in physics. a numeric damping factor.apiLevel = ’2. Body : s e t V e l o c i t y F u n c ( f u n c ) Parameter self func Type in physics. grav.0’ 12. The velocity function must be a function that accepts a Body.0’ 12. The function should call body:updateVelocity to adjust the velocity of the body.Vect out physics. a gravity vector.Body Description The input Body The velocity vector of the Body The input Body is returned as the output Updates the velocity of the body. and a time step value.

g r a v i t y .Body in number out physics. Returns the Body. Body : s e t V L i m i t ( l i m i t ) Parameter self limit self Type in physics.apiLevel = ’2.4.apiLevel = ’2.Example f u n c t i o n s a m p l e V e l o c i t y F u n c ( body .4.30 setWLimit s e l f = p h y s i c s . dt ) l o c a l pos = body : pos ( ) l o c a l s q d i s t = pos : l e n g t h s q ( ) local g = pos : mult(− G r a v i t y S t r e n g t h / ( s q d i s t ∗ math .0’ 12.Body Description The input Body The maximum angular velocity of the Body The input Body is returned as the output Updates the limit of the angular velocity of the body. Body : setWLimit ( l i m i t ) Parameter self limit self Type in physics.0’ 12. 81 .Body Description The input Body The maximum speed of the Body The input Body is returned as the output Sets the limit for the maximum speed of the body. s q r t ( s q d i s t ) ) ) body : u p d a t e V e l o c i t y ( g . damping . Angular velocity is in radians per unit time.29 setVLimit s e l f = p h y s i c s . damping .Body in number out physics. Introduced in platform. dt ) end body : s e t V e l o c i t y F u n c ( s a m p l e V e l o c i t y F u n c ) Introduced in platform.

3.32 sleepWithGroup s e l f = p h y s i c s .0’ 12. If this parameter is not supplied.4-Docs/ for an explanation of sleeping bodies.Body out physics. Note The body must be added to a Space before it can be put to sleep. Introduced in platform. Introduced in platform.Body in physics. 82 .Body out physics. Info See http://chipmunk-physics.net/release/Chipmunk-5.x/Chipmunk-5.3.4-Docs/ for an explanation of this routine. Body : s l e e p ( ) Parameter self self Type in physics.31 sleep s e l f = p h y s i c s .4.apiLevel = ’2. a new group is created The input Body is returned as the output Puts the Body to sleep and adds it to a group of other sleeping bodies.Body Description The input Body A sleeping body.0’ 12. Body : sleepWithGroup ( [ group ] ) Parameter self group self Type in physics. Calling this function within a query or callback is not allowed.Body Description The input Body The input Body is returned as the output Puts the body to sleep.apiLevel = ’2.Returns the Body.x/Chipmunk-5.net/release/Chipmunk-5.4. Info See http://chipmunk-physics.

Introduced in platform.4.0’ 83 . Body : t o r q u e ( ) Parameter self torque Type in physics. This routine will raise an exception if group is not sleeping. Info See http://chipmunk-physics.0’ 12.Body out number Description The input Body The torque on the Body Returns the torque on the body.0’ 12.apiLevel = ’2.net/release/Chipmunk-5. Introduced in platform.4-Docs/ for an explanation of this routine.x/Chipmunk-5. Calling this function within a query or callback is not allowed.33 torque t = p h y s i c s .Body in number Description The input Body The time interval in seconds Updates the position of the body using Euler integration.34 updatePosition p h y s i c s .apiLevel = ’2. Introduced in platform.apiLevel = ’2. Body : u p d a t e P o s i t i o n ( dt ) Parameter self dt Type in physics.4.Note The body must be added to a Space before it can be put to sleep.3.

Introduced in platform.4.0’ 12.Vect Description The input Body The velocity of the Body Returns the vector velocity of the body. Info See http://chipmunk-physics. Body : u p d a t e V e l o c i t y ( grav .36 vel v v e l = p h y s i c s . damp . dt ) Parameter self grav damp dt Type in in in in physics.x/Chipmunk-5. Introduced in platform.Vect physics.12. Body : vLimit ( ) Parameter self vmax Type in physics. Body : v e l ( ) Parameter self vvel Type in physics.Body out physics.4. 84 .Body physics.net/release/Chipmunk-5.Vect Description The The The The input Body force of gravity damping factor time interval in seconds Updates the velocity of the body using Euler integration.35 updateVelocity p h y s i c s .37 vLimit vmax = p h y s i c s .apiLevel = ’2.0’ 12.Vect physics.Body out number Description The input Body The maximum speed of the Body Returns the speed limit of the body.3.apiLevel = ’2.4.4-Docs/ for an explanation of this routine.

Introduced in platform. The angular velocity is in radians per unit time.0’ 12.5 Shapes Shapes contain the surface properties of an object such as how much friction or elasticity it has.Body out number Description The input Body The maximum angular velocity of the Body in radians per unit time Returns the angular velocity limit of the body. 85 . Returns the converted vector.Vect out physics. Introduced in platform.Body in physics.apiLevel = ’2. Body : w o r l d 2 L o c a l ( wvec ) Parameter self wvec lvec Type in physics.apiLevel = ’2.0’ 12.38 wLimit wmax = p h y s i c s . All collision shapes implement the following accessor routines.Vect Description The input Body A vector in world coordinates A vector relative to the position of the Body Converts wvec from world coordinates to body-relative coordinates. Body : wLimit ( ) Parameter self wmax Type in physics.apiLevel = ’2.Introduced in platform.0’ 12.39 world2Local l v e c = p h y s i c s .4.4.

If the shape is static. Shape : c o l l i s i o n T y p e ( ) Parameter self coll Type in physics.0’ 86 .apiLevel = ’2.Shape in physics.5.0’ 12.2 body body = p h y s i c s .12. Shape : body ( ) Parameter self body Type in physics.apiLevel = ’2. Introduced in platform.Shape out physics.5. Shape :BB( ) Parameter self bb Type in physics.BB Description The input Shape Bounding box of the Shape Returns the bounding box of the shape.Body Description The input Shape The Body associated with the Shape Returns the body attached to the shape.apiLevel = ’2. Introduced in platform.0’ 12. Introduced in platform.Shape out number Description The input Shape The programmer-assigned integer collision type Returns the integer collision type of the Shape.1 BB bb = p h y s i c s .3 collisionType c o l l = p h y s i c s .5. then it will return nil.

0’ 87 .6 group g = p h y s i c s . Introducted in platform.Shape out number Description The input Shape The coefficient of friction for this Shape Returns the friction coefficient of the shape.apiLevel = ’2.5. Shape : group ( ) Parameter self g Type in physics.0’ 12.Shape out number Description The input Shape The assigned group number Returns the group number of the shape. Introduced in platform.12. Note The group number is converted to a positive whole number when stored.5.apiLevel = ’2.4 data o b j = p h y s i c s .5. Shape : f r i c t i o n ( ) Parameter self f Type in physics.0’ 12.Shape out Lua object Description The input Shape The programmer-assigned data object assigned to this Shape Returns the contents of the programmer data field of the Shape.apiLevel = ’2. Introduced in platform.5 friction f = p h y s i c s . Shape : data ( ) Parameter self obj Type in physics.

Shape:BB() or physics.BB Description The input Shape The bounding box of the Shape Returns the bounding box of the shape.12.apiLevel = ’2.0’ 12.Space:step().0’ 12.apiLevel = ’2.9 restitution r = p h y s i c s . Only valid after a call to physics. Introduced in platform.0’ 88 .apiLevel = ’2. Shape : rawBB ( ) Parameter self bb Type in physics.7 layers l a y e r s = p h y s i c s . Shape : l a y e r s ( ) Parameter self layers Type in physics.5. Introduced in platform.8 rawBB bb = p h y s i c s .Shape out number Description The input Shape The restitution of the Shape Returns the restitution (or elasticity) of the shape.Shape out physics.5.Shape out number Description The input Shape A bitmap of the layers this shape occupies Returns the bitmap of layers the shape occupies.5. Introduced in platform. Shape : r e s t i t u t i o n ( ) Parameter self r Type in physics.

The programmer can store any Lua object in this field. Shape : s e n s o r ( ) Parameter self s Type in physics.Shape in number out physics.11 setCollisionType s e l f = p h y s i c s . Introduced in platform. It is used to determine which handler to call when a collision occurs.0’ 12. Shape : s e t D a t a ( o b j ) Parameter self obj self Type in physics. Introduced in platform.0’ 89 . Introduced in platform.12.5. Returns self .apiLevel = ’2.0’ 12. Returns self .5.5.Shape Description The input Shape An object defined by the programmer The input Shape is returned as the output Sets the programmer data field of the Shape.Shape Description The input Shape Programmer-defined type of collision The input Shape is returned as the output Assigns a collision type (an integer value of your choosing) to the shape.12 setData s e l f = p h y s i c s .Shape out boolean Description The input Shape True if the Shape is a sensor Returns true if the shape is a sensor.10 sensor s = p h y s i c s .apiLevel = ’2.apiLevel = ’2. Shape : s e t C o l l i s i o n T y p e ( c o l l i s i o n T y p e ) Parameter self collisionType self Type in physics.Shape in Lua object out physics.

Shape in number out physics.14 setGroup s e l f = p h y s i c s .Shape Description The input Shape Group number The input Shape is returned as the output Sets the group (a number defined by the programmer) of the shape.Shape in number out physics. Note The group number is converted to a positive whole number when stored. Returns self .13 setFriction s e l f = p h y s i c s .15 setLayers s e l f = p h y s i c s .5. Shapes in the same group do not generate collisions.0 or less than 0. Shape : setGroup ( group ) Parameter self group self Type in physics.apiLevel = ’2.0’ 12. Introduced in platform. Shape : s e t L a y e r s ( l a y e r s ) 90 .5.apiLevel = ’2.12. Introduced in platform. Returns self .5. Note May not behave as expected for f larger than 1.0’ 12. Shape : s e t F r i c t i o n ( f ) Parameter self f self Type in physics.Shape Description The input Shape Coefficient of friction for the surface of the Shape The input Shape is returned as the output Sets the friction coefficient for the shape.

Shape : s e t S e n s o r ( b o o l ) Parameter self bool self Type in physics.0’ 91 .0 gives a perfect bounce.16 setRestitution s e l f = p h y s i c s .5.Shape Description The input Shape True if the shape is a sensor The input Shape is returned as the output Determines if the shape is a sensor (true) or not (false). Sensors call collision handlers but do not generate collisions.Shape Description The input A bitmap mentation The input Shape of integer layer numbers. Returns self . layers is an integer bitmap of all the layers that the shape occupies.0 or less than 0. Returns self . Shapes only collide if they are in the same layer.5.Shape in boolean out physics. A value of 0.apiLevel = ’2. Shape : s e t R e s t i t u t i o n ( r ) Parameter self r self Type in physics.0’ 12. Returns self . Note May not behave as expected for r larger than 1.Shape Description The input Shape The new value for the shape’s restitution The input Shape is returned as the output Sets the restitution (or elasticity) of the shape.17 setSensor s e l f = p h y s i c s .Shape in number out physics.Parameter self layers self Type in physics.Shape in number out physics. Introduced in platform.apiLevel = ’2. This implepermits 32 layers Shape is returned as the output Sets the layers that the shape inhabits. Introduced in platform.0 gives no bounce and a value of 1. 12.

Shape : s e t S u r f a c e V ( v e l ) Parameter self vel self Type in physics.5. C i r c l e S h a p e ( body .18 setSurfaceV s e l f = p h y s i c s . Its type is TI.Shape out physics.0’ 12.6.cpCircleShape.6 Circle Shapes A CircleShape is a subclass of Shape.Vect Description The input Shape The surface velocity of the Shape Returns the surface velocity vector of the shape. Shape : s u r f a c e V ( ) Parameter self sv Type in physics.5.0’ 12.apiLevel = ’2.1 CircleShape c s = p h y s i c s .Shape in physics. 12.Shape Description The input Shape The new vector for the surface velocity The input Shape is returned as the output Sets the surface velocity of the shape. Returns self . Introduced in platform. o f f s e t ) Parameter body radius offset cs Type in physics. r a d i u s .apiLevel = ’2.Body in number in physics.Vect out physics.CircleShape Description A Body or nil The radius of the circle The offset of the circle from the Body A new CircleShape 92 .12.Vect out physics. Introduced in platform.19 surfaceV sv = p h y s i c s .

and offset vector from the body’s center of gravity in body-local coordinates.2 offset ovec = p h y s i c s .Vect Description The input CircleShape The offset of the shape from the Body Returns the offset vector of the shape from the body’s center of gravity.7 Polygon Shapes Polygon shapes are bounded by a set of line segments. Introduced in platform.6. Specify nil for the body to use the space’s static body.apiLevel = ’2.CircleShape out physics.apiLevel = ’2.cpPolyShape.apiLevel = ’2. Introduced in platform. Poygon shapes are of type TI.6.3 radius r = physics .0’ 12. The enclosed area of the polygon must be convex and the vertices must be defined in counterclockwise order. Introduced in platform. CircleShape : radius () Parameter self r Type in physics.Returns a new CircleShape with the given body. C i r c l e S h a p e : o f f s e t ( ) Parameter self ovec Type in physics. 93 . radius.CircleShape out number Description The input CircleShape The radius of the shape Returns the radius of the shape.0’ 12.0’ 12.

Vect out physics.PolyShape out {physics. The vertices are translated to the polygon’s current world coordinates 94 .PolyShape Returns a new PolyShape with the given body.7.apiLevel = ’2. o f f s e t ) Parameter body vertices Type in physics.PolyShape out number Description The input PolyShape The number of vertices in the PolyShape Returns the number of vertices in the table of polygon vertices. Introduced in platform. PolyShape : numVerts ( ) Parameter self nv Type in physics.2 numVerts nv = p h y s i c s . PolyShape : p o i n t s ( ) Parameter self points Type in physics.1 PolyShape ps = p h y s i c s . table of vertices. and offset from the body’s center of gravity.3 points p o i n t s = p h y s i c s . Specify nil for the body to use the space’s static body. PolyShape ( body .0’ 12. Introduced in platform.Body in {physics.0’ 12.Vect} Description The input PolyShape A table of vertices that define the boundary of the polygon.7. v e r t i c e s .7.apiLevel = ’2.12.Vect} Description A Body or nil The list of vertices that define the boundaries of the polygon defined in counterclockwise order The offset of the PolyShape from the Body A new PolyShape offset ps in physics.

PolyShape:points() will have x and y equal to 0. SegmentShape ( body . If the shape is static then the vertex values are in world coordinates. Returns nil if n is less than 1 or greater than the number of vertices in the polygon.7.0’ 12. The coordinates of the vector are relative to the shape’s Body Returns vertex number n of the table of vertices defining the bounds of the polygon. it has no world coordinates.8. Introduced in platform.0’ 12. 12.1 SegmentShape s s = p h y s i c s . r a d i u s ) 95 .apiLevel = ’2. In this case. The vertices are translated to the polygon’s current world coordinates.8 Segment Shapes A segment shape is defined by two end points and a radius. otherwise the vertex coordiates are relative to the shape’s body.Returns a copy of the table of vertices defining the bounds of the polygon. Introduced in platform. each vertex returned by physics.Vect Description The input PolyShape The nth vertex of the polygon.cpSegmentShape.4 vert v = p h y s i c s .apiLevel = ’2. b . a .PolyShape out physics. Its type is TI. PolyShape : v e r t ( n ) Parameter self v Type in physics. Note When a PolyShape has not been added to a Space.

Introduced in platform.Vect Description A Body or nil The first end point of the segment.Body in physics.2 a avec = p h y s i c s . SegmentShape : b ( ) Parameter self bvec Type in physics.8.Vect in number ss out physics.apiLevel = ’2.0’ 96 . Introduced in platform.0’ 12.apiLevel = ’2. Introduced in platform.0’ 12. The end point is in coordinates relative to the Body The second end point of the segment relative to the Body The distance of the border of the segment from the line between the end points of the segment A new SegmentShape b radius in physics.SegmentShape out physics.Parameter body a Type in physics. SegmentShape : a ( ) Parameter self avec Type in physics.3 b bvec = p h y s i c s .Vect Description The input SegmentShape The first end point of the segment Returns the a vector defining one of the end points of the segment.8.apiLevel = ’2. radius defines the thickness of the segment.Vect Description The input SegmentShape The second end point of the segment Returns the b vector defining one of the end points of the segment.SegmentShape Returns a new SegmentShape with end point vectors a and b.SegmentShape out physics.

Introduced in platform.Vect Description The input SegmentShape The unit normal vector of the segment Returns the computed unit normal vector to the segment.8. SegmentShape : normal ( ) Parameter self nvec Type in physics.SegmentShape out physics. Space ( ) Parameter s Type out physics.0’ 97 . SegmentShape : r a d i u s ( ) Parameter self r Type in physics.apiLevel = ’2. 12.Space Description A new simulation Space Returns a new physics simulation Space.5 radius r = p h y s i c s .4 normal nvec = p h y s i c s .0’ 12. Introduced in platform.apiLevel = ’2. Introduced in platform.1 Space s = p h y s i c s .12.0’ 12.9 Spaces A physics Space is the basic unit of simulation.apiLevel = ’2.SegmentShape out number Description The input SegmentShape The radius of the segment Returns the radius of the segment.9.8.

apiLevel = ’2.0’ 12. callbacksTable ) Parameter self collisionTypeA collisionTypeB callbacksTable self Type in in in in physics. Introduced in platform.9. Returns self . Returns self . Space : a d d C o l l i s i o n H a n d l e r ( c o l l i s i o n T y p e A .Space in physics.apiLevel = ’2.2 addBody s e l f = p h y s i c s .Body out physics. Space : addBody ( body ) Parameter self body self Type in physics.Space Description The input simulation Space Adds the Body to the simulation Space The input Space is returned as the output Adds a Body to the Space.Space Description The input simulation Space Adds a Constraint to the simulation Space The input Space is returned as the output Adds a Constraint to the Space.Space number number table of functions Description The input simulation Space Type of first collision Type of second collision A table of functions to call during collision detection and handling The input Space is returned as the output 98 out physics.12. collisionTypeB . Space : a d d C o n s t r a i n t ( c o n s t r a i n t ) Parameter self constraint self Type in physics.0’ 12.3 addConstraint s e l f = p h y s i c s .Space in physics.9.4 addCollisionHandler s e l f = p h y s i c s .Constraint out physics. Introduced in platform.9.Space .

. further collision calculations are bypassed.5 addPostStepCallback s e l f = p h y s i c s . .. Shapes. Returns self . Info See http://chipmunk-physics.. Introduced in platform.apiLevel = ’2. . end ) 99 .4-Docs/ for an explanation of collision processing and collision handler callbacks. end . If they return true. end .Registers a table of callback functions to handle collisions between shapes of collisionTypeA and shapes of collisionTypeB. callbacksTable ) callbacksTable ) callbacksTable ) callbacksTable ) . . .. end . space space space space .3. Space : a d d P o s t S t e p C a l l b a c k ( body | shape | c o n s t r a i n t . the collision processing proceeds as normal. or Constraints from the Space. . f u n c t i o n ( space . o b j e c t ) .. . The callbacksTable is a table of the form: { begin preSolve postSolve separate } If the begin handler or preSolve handler return false.0’ = = = = function ( arbiter function ( arbiter function ( arbiter function ( arbiter .net/release/Chipmunk-5. . end 12.. It is not necessary to provide handlers for all callback table entries.x/Chipmunk-5. . One important point to note is that these callback handlers must not add or remove Bodies. .. . Default handling will be provided for unspecified handlers.. . See the post-step callback functions for the right way to remove (or add) objects as the result of a collision.9.

Space in physics. One callback may be registered per Body.Shape out physics.0’ 12.Body or physics.apiLevel = ’2.Space in physics. Introduced in platform.apiLevel = ’2.Space Description The input simulation Space A simulation object that will receive attention after the simulation step function self The callback function to run against the simulation object at the end of the simulation step The input Space is returned as the output Adds a callback function to be called when the current step is finished.Space in physics.Parameter self body or shape or constraint Type in physics. Any attempt to register another callback for the same object is ignored. Returns self .Space Description The input simulation Space Adds the Shape to the simulation Space The input Space is returned as the output Adds a Shape to the Space. Introduced in platform. object) out physics.7 addStaticShape s e l f = p h y s i c s .0’ 12.Space Description The input simulation Space Adds the static Shape to the simulation Space The input Space is returned as the output 100 .Shape out physics. Shape.6 addShape s e l f = p h y s i c s . Space : addShape ( shape ) Parameter self shape self Type in physics.Constraint in function(space.9. Returns self . or Constraint. Only the first callback for a given object is registered.9. Space : a d d S t a t i c S h a p e ( s t a t i c S h a p e ) Parameter self staticShape self Type in physics.Shape or physics.

Space out number Description The input simulation Space The number of iterations to use in the impulse solver to solve elastic collisions Introduced in platform.apiLevel = ’2. Space : e l a s t i c I t e r a t i o n s ( ) Parameter self iters Type in physics.apiLevel = ’2. Space : damping ( ) Parameter self d Type in physics.8 damping d = p h y s i c s .0’ 12.10 elasticIterations i t e r s = p h y s i c s .Space out Lua object out physics.9 data o b j = p h y s i c s .0’ 101 . Introduced in platform. Returns self .apiLevel = ’2.Space Description The input simulation Space The programmer specified object associated with the Space The input Space is returned as the output Introduced in platform.0’ 12.9.Space out number Description The input simulation Space The amount of damping of the simulation Space Introduced in platform.apiLevel = ’2.0’ 12.9. Space : data ( ) Parameter self obj self Type in physics.Adds a static Shape to the Space.9.

9. Introduced in platform. Space : i t e r a t i o n s ( ) Parameter self iters Type in physics.9.apiLevel = ’2.13 iterations i t e r s = p h y s i c s .12.9.Space out number Description The input simulation Space The number of iterations the solver takes to update one step of the simulation Introduced in platform.apiLevel = ’2.apiLevel = ’2.12 idleSpeedThreshold s p e e d = p h y s i c s .Space out physics.0’ 12. Space : i d l e S p e e d T h r e s h o l d ( ) Parameter self speed Type in physics.9. Space : rehashShape ( shape ) 102 . Space : g r a v i t y ( ) Parameter self grav Type in physics.Space out number Description The input simulation Space Threshold speed Introduced in platform.14 rehashShape s e l f = p h y s i c s .0’ 12.11 gravity grav = p h y s i c s .Vect Description The input simulation Space The gravity force vector applied to all Bodies in the simulation Space.0’ 12.

Returns self .apiLevel = ’2.9.apiLevel = ’2.16 removeBody s e l f = p h y s i c s . Returns self .Space in physics.apiLevel = ’2.0’ 12.9. Introduced in platform.0’ 103 . Introduced in platform. Space : r e h a s h S t a t i c ( ) Parameter self self Type in physics. Space : removeBody ( body ) Parameter self body self Type in physics. You must call this if you move any static shapes or Chipmunk won’t update their collision detection data.Body out physics.Space out physics.15 rehashStatic s e l f = p h y s i c s .Space in shape out physics.Parameter self shape self Type in physics.0’ 12. Returns self . Introduced in platform.Space Description The input simulation Space The shape to rehash The input Space is returned as the output Update an individual static shape that has moved.Space Description The input simulation Space The input Space is returned as the output Rehashes the shapes in the static spatial hash.Space Description The input simulation Space A Body to remove from the simulation Space The input Space is returned as the output Removes a Body from the Space.

19 removeStaticShape p h y s i c s . Space : r e m o v e C o n s t r a i n t ( c o n s t r a i n t ) Parameter self constraint self Type in physics. Space : r e m o v e S t a t i c S h a p e ( s t a t i c S h a p e ) Parameter self staticShape self Type in physics.0’ 104 .12. Returns self .Shape out physics.apiLevel = ’2. Introduced in platform.Constraint out physics.9.0’ 12.Space in physics.Space in physics.apiLevel = ’2.0’ 12.Space Description The input simulation Space A Shape to remove from the simulation Space The input Space is returned as the output Removes a Shape from the Space.Shape out physics. Returns self .17 removeConstraint s e l f = p h y s i c s . Returns self . Introduced in platform.Space in physics.apiLevel = ’2. Space : removeShape ( shape ) Parameter self shape self Type in physics.9.Space Description The input simulation Space A static Shape to remove from the simulation Space The input Space is returned as the output Removes a static Shape from the Space.18 removeShape s e l f = p h y s i c s . Introduced in platform.Space Description The input simulation Space A Constraint to remove from the simulation Space The input Space is returned as the output Removes a Constraint from the Space.9.

20 resizeActiveHash s e l f = p h y s i c s .21 resizeStaticHash s e l f = p h y s i c s . Space : r e s i z e A c t i v e H a s h ( dim . count ) Parameter self dim count self Type in physics. Introduced in platform. Default is 1000 The input Space is returned as the output This routine configures the spatial hash of static Shapes.9 means that each body will lose 10 s e l f = p h y s i c s .22 setDamping Damping drains speed from bodies in the simulation. dim establishes the size of a hash cell (default 100).Space Description The input simulation Space The length of one side of a hash cell.12.apiLevel = ’2.apiLevel = ’2.9. Space : r e s i z e S t a t i c H a s h ( dim . A good rule of thumb is to set count to about ten times the number of Shapes in the space. Default is 100 The number of cells in the hash table. dim should approximate the side length of a typical Shape. count ) Parameter self dim count self Type in physics. Introduced in platform. and count sets the number of hash cells (default 1000).9.Space in number in number out physics. Default is 100 The number of cells in the hash table.0’ 12. Space : setDamping ( d ) 105 . Default is 1000 The input Space is returned as the output The spatial hash of active shapes can be tuned to improve collision detection.9.0’ 12. Configure this similarly to resizeActiveHash but for static Shapes. A value of 0.Space Description The input simulation Space The length of one side of a hash cell.Space in number in number out physics.

Space in Lua object out physics.23 setData s e l f = p h y s i c s .0’ 106 .apiLevel = ’2.0’ 12.apiLevel = ’2. Defaults to 0 The input Space is returned as the output Introduced in platform. Introduced in platform.9.Space in number out physics. Space : s e t D a t a ( o b j ) Parameter self obj self Type in physics.9.Space Description The input simulation Space A programmer specified object The input Space is returned as the output The programmer can store any Lua object in this field. Note May not behave as expected for d larger than 1.0’ 12.Space in number out physics.24 setElasticIterations s e l f = p h y s i c s .0 or less than 0. Introduced in platform.Space Description The input simulation Space The new amount of damping for the simulation Space The input Space is returned as the output Amount of viscous damping to apply to the Space.apiLevel = ’2. Space : s e t E l a s t i c I t e r a t i o n s ( i t e r s ) Parameter self iters self Type in physics.Parameter self d self Type in physics.Space Description The input simulation Space The number of iterations to use in the impulse solver to solve elastic collisions.

27 setIterations s e l f = p h y s i c s . Space : s e t G r a v i t y ( grav ) Parameter self grav self Type in physics.apiLevel = ’2. Introduced in platform. Defaults to physics. Can be overridden on a per body basis by writing custom integration functions. 0) The input Space is returned as the output Global gravity applied to the Space.25 setGravity s e l f = p h y s i c s .Space Description The input simulation Space Threshold speed The input Space is returned as the output The idleSpeedThreshold is the speed below which a body is considered to be idle.9.26 setIdleSpeedThreshold s e l f = p h y s i c s .Space Description The input simulation Space The gravity force vector applied to all Bodies in the simulation Space. Space : s e t I d l e S p e e d T h r e s h o l d ( s p e e d ) Parameter self speed self Type in physics.9.Vect(0.12.9.Space Description The input simulation Space Number of iterations to refine the accuracy of the solver.0’ 12. Default is 10 The input Space is returned as the output 107 .apiLevel = ’2. Space : s e t I t e r a t i o n s ( i t e r s ) Parameter self iters self Type in physics.Vect out physics. This value is used to determine when a body can be put to sleep.0’ 12.Space in number out physics. Introduced in platform.Space in number out physics.Space in physics.

Introduced in platform.28 setSleepTimeThreshold s e l f = p h y s i c s .9.Space Description The input simulation Space The amount of time (seconds) below which time if a Shape has not moved.9.Space in number out physics.30 step s e l f = p h y s i c s .9.Space in number out physics.apiLevel = ’2.apiLevel = ’2. Introduced in platform.0’ 12. Space : s e t S l e e p T i m e T h r e s h o l d ( s l e e p ) Parameter self sleep self Type in physics.This value allows the programmer to control the accuracy of the solver.Space Description The input simulation Space The length of time (seconds) of one step of the simulation The input Space is returned as the output 108 .apiLevel = ’2. it is put to sleep The input Space is returned as the output Sleep time threshold is used to calculate when a Body can be put to sleep.0’ 12.0’ 12. Space : s l e e p T i m e T h r e s h o l d ( ) Parameter self sleep Type in physics. Space : s t e p ( dt ) Parameter self dt self Type in physics.Space out number Description The input simulation Space The threshold time used to determine when a Shape can be put to sleep Introduced in platform. Default is 10.29 sleepTimeThreshold s l e e p = p h y s i c s .

Body number Description The first Body that the Constraint acts on The second Body that the Constaint acts on The fraction of error corrected each step of the simulation.1. damping ) 109 . requiring an order of magnitude fewer iterations and lower CPU usage. divide by the time step passed to physics.Body physics. Introduced in platform.0’ 12.10. Defaults to INFINITY Lua object number setMaxBias. A fixed time step is recommended and increases the efficiency of the contact persistence. To convert this to the magnitude of the force. maxBias setMaxForce. biasCoef setData. DampedRotarySpring ( a . Accessors bodyA bodyB setBiasCoef. data impulse Type physics. Defaults to 0.apiLevel = ’2. A programmer-defined object Calculated impulse applied by the Constraint in the last simulation step. Defaults to INFINITY Magnitude of maximum force the Constraint can use to act on the two Bodies. r e s t A n g l e . May not behave as expected for numbers larger than 1.10 Constraints All Constraints share common accessors.Space:step() Maximum speed the Constraint can apply error correction.1 Damped Rotary Spring s p r i n g = p h y s i c s . s t i f f n e s s . Returns self . b .0 or less than 0. maxForce number number 12.Updates the Space for the given time step dt.

anchr1 . but works in an angular fashion. stiffness is the spring constant. stiffness setDamping. restAngle setStiffness. damping Type number number number Introduced in platform. s t i f f n e s s .2 Damped Spring s p r i n g = p h y s i c s . restAngle is the relative angle in radians that the Bodies want to have.Body in number in number in number out physics.0’ 12. anchr2 . DampedSpring ( a .Body physics.Vect number Description First Body Second Body Anchor point to first Body Anchor point to second Body The distance the spring want to maintain between its Bodies The spring constant How soft to make the damping of the spring New DampedSpring in number in number out physics.DampedSpring Defined much like a SlideJoint. and damping is how soft to make the damping of 110 .10. damping ) Parameter a b anchr1 anchr2 restLength stiffness damping spring Type in in in in in physics.Body in physics. b . r e s t L e n g t h .Parameter a b restAngle stiffness damping spring Type in physics.DampedRotarySpring Description First Body Second Body Relative angle in radians that the Bodies want to maintain The spring constant How soft to make the damping of the spring New DampedRotarySpring Like a damped spring. stiffness and damping work basically the same as on a damped spring.Body physics.Vect physics. restLength is the distance the spring wants to be.apiLevel = ’2. Accessors setRestAngle.

b . restLength setStiffness. phase . ratio Type number number Introduced in platform. r a t i o ) Parameter a b phase ratio joint Type in physics. Accessors setAnchr1. phase is the initial angular offset of the two bodies.Body in physics.10.apiLevel = ’2.Vect physics. b .3 Gear Joint j o i n t = p h y s i c s .0’ 12.apiLevel = ’2. phase setRatio.0’ 12.10.the spring. G e a r J o i n t ( a .4 Groove Joint j o i n t = p h y s i c s . damping Type physics. Accessors setPhase. G r o o v e J o i n t ( a .Vect number number number Introduced in platform. grooveA .Body in number in number out physics. grooveB . stiffness setDamping. ratio is always measured in absolute terms. anchr2 ) 111 . anchr1 setAnchr2.GearJoint Description First Body Second Body The initial angular offset in radians of the two Bodies Ratio of velocities between the two Bodies New GearJoint Keeps the angular velocity ratio of a pair of Bodies constant. anchr2 setRestLength.

Body in physics.Vect physics. anchr1 .Vect in physics. grooveB grooveN Type physics. and the pivot is attached to anchr2 on Body b.10. If you want to set a specific distance.PinJoint Description First Body Second Body The anchor point on Body a The anchor point on Body b New PinJoint a and b are the two bodies to connect.0’ 12. The distance between the two anchor points is measured when the joint is created.Vect in physics.Vect out physics.Vect physics.Vect number Introduced in platform.0’ 112 . Accessors setAnchr2. anchr2 setGrooveA.apiLevel = ’2. dist Type physics.GlooveJoint Description First Body Second Body One end point of the groove The other end point of the groove The pivot point of Body b New GlooveJoint The groove goes from grooveA to grooveB on Body a.apiLevel = ’2. anchr1 setAnchr2.Vect physics. b . All coordinates are body local.Vect in physics.Vect out physics. grooveA setGrooveB. Accessors setAnchr1.5 Pin Joint j o i n t = p h y s i c s . anchr2 setDist.Body in physics. P i n J o i n t ( a .Body in physics.Body in physics.Vect physics. anchr2 ) Parameter a b anchr1 anchr2 joint Type in physics. use the setter function to override it. and anchr1 and anchr2 are the anchor points on those bodies.Parameter a b grooveA grooveB anchr2 joint Type in physics.Vect Introduced in platform.

but make sure you have the bodies in the right place as the joint will fix itself as soon as you start simulating the Space. 113 .Body in physics.Vect physics.Body in physics.10.Vect Introduced in platform.0’ 12. b . PivotJoint (a . anchr2 ) Parameter a b pivot anchr1 anchr2 joint Type in physics. pivot ) j o i n t = p h y s i c s . Because the pivot location is given in world coordinates. Accessors setAnchr1.Vect in physics.12. anchr1 . ratchet is the distance between clicks.10.6 Pivot Joint joint = physics . R a t c h e t J o i n t ( a .Vect in physics.Body physics.PivotJoint Description First Body Second Body Point of pivot between the two Bodies The anchor point on Body a The anchor point on Body b New PivotJoint a and b are the two bodies to connect. r a t c h e t ) Parameter a b phase ratchet joint Type in in in in physics.7 Ratchet Joint j o i n t = p h y s i c s . anchr2 Type physics. phase .Body number number Description First Body Second Body Initial offset in radians The distance in radians between clicks of the ratchet New RatchetJoint out physics. phase is the initial offset to use when deciding where the ratchet angles are. b . anchr1 setAnchr2. and pivot is the point in world coordinates of the pivot. you must have the bodies moved into the correct positions already.Vect out physics. P i v o t J o i n t ( a . Alternatively you can specify the joint based on a pair of anchor points.apiLevel = ’2. b .RatchetJoint Works like a socket wrench.

ratchet Type number number number Introduced in platform. phase setRatchet. min setMax.0’ 12. r a t e ) Parameter a b rate motor Type in physics.Body in number out physics. SimpleMotor ( a . R o t a r y L i m i t J o i n t ( a . b .Body in physics. angle setPhase.9 Simple Motor motor = p h y s i c s .10. max) Parameter a b min max joint Type in physics.Body in number in number out physics. Accessors setMin. b .apiLevel = ’2. max Type number number Introduced in platform.SimpleMotor Description First Body Second Body The relative angular velocity New SimpleMotor 114 . min and max are the angular limits in radians. It is implemented so that it is possible for the range to be greater than a full revolution.apiLevel = ’2.RotaryLimitJoint Description First Body Second Body The minimum angular distance in radians The maximum angular distance in radians New RotaryLimitJoint Constrains the relative rotations of two bodies. min .0’ 12.Accessors setAngle.Body in physics.10.8 Rotary Limit Joint j o i n t = p h y s i c s .

Vect number number Introduced in platform. rate Type number Introduced in platform.Body in physics.Vect in number in number out physics. rate is the desired relative angular velocity. and min and max define the allowed distances of the anchor points. S l i d e J o i n t ( a .apiLevel = ’2.11. Accessors setRate.apiLevel = ’2.Vect in physics.Keeps the relative angular velocity of a pair of bodies constant. max Type physics.Body in physics.0’ 12.SlideJoint Description First Body Second Body The anchor point on Body a The anchor point on Body b Minimum distance between Bodies Maximum distance between Bodies New SlideJoint a and b are the two bodies to connect. Accessors setAnchr1. anchr1 and anchr2 are the anchor points on those bodies.11 Arbiters and Collision Pairs The Arbiter class encapsulates information about each pair of collisions. max) Parameter a b anchr1 anchr2 min max joint Type in physics.10. anchr1 . anchr2 setMin. min setMax.Vect physics. b . anchr2 .10 Slide Joints j o i n t = p h y s i c s . anchr1 setAnchr2.0’ 12. 12.1 # 115 . min .

Arbiter out physics. A r b i t e r : a ( ) Parameter self shape Type in physics.Body Description The input Arbiter The first Body in the collision pair The second Body in the collision pair 116 .apiLevel = ’2. A r b i t e r Returns the number of contact points in this Arbiter.count = #p h y s i c s .11.4 bodies bodyA . Introduced in platform. A r b i t e r : b ( ) Parameter self shape Type in physics.0’ 12.Shape Description The input Arbiter The first Shape in the collision pair Returns Shape a (the first shape) in a collision pair.Arbiter out physics.3 b shape = p h y s i c s .0’ 12. Introduced in platform. A r b i t e r : b o d i e s ( ) Parameter self bodyA bodyB Type in physics.Shape Description The input Arbiter The second Shape in the collision pair Returns Shape b (the second shape) in a collision pair. Introduced in platform.0’ 12.apiLevel = ’2.2 a shape = p h y s i c s .11. bodyB = p h y s i c s .Arbiter out physics.11.Body out physics.apiLevel = ’2.

Arbiter in number out number Description The input Arbiter A contact point number The penetration depth of the ith contact point Returns the penetration depth of the ith contact or nil if i is out of range of the number of contact points.Arbiter out number Description The input Arbiter The calculated elasticity of the collision Returns the calculated elasticity of this collision pair.5 depth d = p h y s i c s .11.apiLevel = ’2. Arbiter : f r i c t i o n () Parameter self f Type in physics.0’ 12. Arbiter : e l a s t i c i t y () Parameter self e Type in physics.6 elasticity e = physics . 117 .apiLevel = ’2. Introduced in platform. A r b i t e r : depth ( i ) Parameter self i d Type in physics.apiLevel = ’2.7 friction f = physics .Arbiter out number Description The input Arbiter The calculated friction of the collision Returns the calculated friction of this collision pair.11.11. Introduced in platform.Returns bodyA and bodyB in the collision pair.0’ 12. Introduced in platform.0’ 12.

9 isFirstContact bool = physics . Arbiter : isFirstContact () Parameter self bool Type in physics.11. Introduced in platform. Introduced in platform.10 normal nvec = p h y s i c s . then the calculated friction is taken into account.11.Vect Description The input Arbiter If true.0’ 12.Arbiter in boolean out physics. This information only persists until a step when the shapes are no longer touching.apiLevel = ’2. A r b i t e r : normal ( i ) Parameter self i nvec Type in physics.Arbiter in number out physics. the calculated friction is included in the calculation The vector impulse applied to resolve the collision Returns the vector impulse that was applied this step to resolve the collision.Introduced in platform. Arbiter : impulse ( [ f r i c t i o n ] ) Parameter self friction ivec Type in physics.apiLevel = ’2.11.Arbiter out boolean Description The input Arbiter True if this is the first step that the Shapes touched Returns true if this is the first step that the Shapes touched. If friction is true (default false).0’ 12. Once they are no longer touching this flag is reset.Vect Description The input Arbiter A contact point number Vector normal to the ith contact point 118 .apiLevel = ’2.8 impulse i v e c = physics .0’ 12.

Returns the collision normal vector for the ith contact point.Arbier Description The input Arbiter Elasticity of the collision The input Arbiter is returned as the output Overrides the calculated elasticity of the collision.11 point pvec = p h y s i c s .13 setFriction s e l f = physics .Vect Description The input Arbiter A contact point number The position of the ith contact point Returns the position of the ith contact point.apiLevel = ’2. Introduced in platform. Arbiter : s e t E l a s t i c i t y ( e ) Parameter self e self Type in physics.apiLevel = ’2.apiLevel = ’2.11.0 or less than 0.0’ 12.0’ 12. Note May not behave as expected for e larger than 1. Introduced in platform.12 setElasticity s e l f = physics .11.Arbiter in number out physics.Arbiter in number out physics. Returns nil if i is out of the range of the number of contact points. Returns nil if i is out of the range of the number of contact points. Introduced in platform. A r b i t e r : p o i n t ( i ) Parameter self i pvec Type in physics. Arbiter : setFriction ( f r i c t i o n ) 119 .11.0’ 12.

11.Shape Description The input Arbiter The first Shape in the collision The second Shape in the collision Returns shapeA and shapeB in the order they were defined in the collision handler associated with this Arbiter.0’ 12. Arbiter : totalImpulse () Parameter self ivec Type in physics. Introduced in platform. shapeB = p h y s i c s .0’ 12.11. Introduced in platform.14 shapes shapeA .apiLevel = ’2.Arbiter out physics.Shape out physics.apiLevel = ’2.0 or less than 0. A r b i t e r : s h a p e s ( ) Parameter self shapeA shapeB Type in physics.Arbier Description The input Arbiter Friction in the collision The input Arbiter is returned as the output Overrides the calculated friction of the collision.Arbiter out physics.apiLevel = ’2. Note May not behave as expected for f larger than 1. Introduced in platform.Arbiter in number out physics.0’ 120 .Parameter self f self Type in physics.15 totalImpulse ivec = physics .Vect Description The input Arbiter The vector impulse applied to resolve the collision Returns the vector impulse that was applied this step to resolve the collision.

2 segmentQuery i n f o = p h y s i c s . v e c t b ) 121 .12. Arbiter : totalImpulseWithFriction () Parameter self ivec Type in physics.1 Shape Queries pointQuery b o o l = p h y s i c s .0’ 12. The calculated friction is taken into account.Vect Description The input Arbiter The vector impulse applied to resolve the collision Returns the vector impulse that was applied this step to resolve the collision.0’ 12. Shape : segmentQuery ( v ecta .11.apiLevel = ’2.Vect out boolean Description The input Shape A point True if point lies within the bounds of Shape Returns true if point lies within the Shape.Arbiter out physics.16 totalImpulseWithFriction ivec = physics . Shape : pointQuery ( p o i n t ) Parameter self point bool Type in physics.12.apiLevel = ’2. Introduced in platform. Introduced in platform.12 12.Shape in physics.12.

Parameter self vecta vectb info Type in physics. f u n c t i o n ( shape ) . Note If a segment query starts inside of a shape then the result is somewhat undefined. end ) 122 . Introduced in platform. l a y e r s .0’ 12. use a separate point query to determine if the segment query starts inside of a shape. . Space : pointQuery ( p o i n t .13. and segments will report an incorrect point and normal if they do detect a collision with that shape.13 12.Shape in physics.apiLevel = ’2. Nil if no intersection Checks if the line segment from vecta to vectb intersects the Shape. .1 Space Queries pointQuery p h y s i c s .Vect out physics. Circles and polygons will not report a collision with that shape. Info See the SegmentQueryInfo methods below for helper routines to convert the results to world coordinates or absolute distance. group .Vect in physics. Returns a SegmentQueryInfo object with the result of the query or nil if no intersection.SegmentQueryInfo Description The input Shape One end point of the segment The other end point of the segment Information about where the segment and Shape intersect. To get around this deficiency.

Parameter self point layers group function Type in physics. t . s t o p v e c t . . end ) 123 . l a y e r s .13. Match if shape.Space in physics. Space : segmentQuery ( s t a r t v e c t . Returns nil if no Shape was found. f u n c t i o n ( shape .layers intersects layers The group number to check. Match if Shape is not in group A function to call providing each Shape in turn that matches the criteria Queries the Space for all shapes that contain point and match layers but not in group.13.Vect in number in number Description The input Space A point A bitmap of the layers. Introduced in platform.apiLevel = ’2. The function is called with each matching Shape. normal ) . group ) Parameter self point layers group Type in physics. Space : p o i n t Q u e r y F i r s t ( p o i n t .apiLevel = ’2.0’ 12.Vect in number in number function(shape) Description The input Space A point A bitmap of the layers. Match if Shape is not in group Queries Space at point and returns the first Shape that matches the given layers and and not in group. Introduced in platform. . Sensor Shapes are included.3 segmentQuery p h y s i c s .0’ 12.layers intersects layers The group number to check. l a y e r s . Match if shape.2 pointQueryFirst shape = p h y s i c s . Sensor Shapes are ignored.Space in physics. group .

layers intersects layers The group number to check. and the surface normal vector of the intersection point of the Shape. s t o p v e c t . Math if shape.Space physics. Matches if shape.13. normal) Queries the Space for all Shapes that intersect the line segment from startvect to stopvect and match layers and not in group.SegmentQueryInfo Queries Space along the line segment from startvect to stopvect and returns the first intersecting Shape that matches layers and not in group. group ) Parameter self startvect stopvect layers group info Type in in in in physics. 124 . proportion of distance along the line segment (a fraction from 0 to 1).Vect physics.Parameter self startvect stopvect layers group function Type in in in in physics.Vect number Description The input Space An end point of the segment Other end point of the segment A bitmap of the layers.apiLevel = ’2. Introduced in platform. t. Match if object is not in group A function to call providing each Shape in turn that matches the criteria in number function(shape. Nil if no intersection in number out physics.Space physics. Returns a SegmentQueryInfo object with the first Shape that matches the query or nil if no intersection.4 segmentQueryFirst i n f o = p h y s i c s .0’ 12. Sensor Shapes are included.Vect number Description The input Space An end point of the segment Other end point of the segment A bitmap of the layers.layers intersects layers The group number to check. The function is called with each matching Shape. The callback function is called with each Shape. l a y e r s . Matches if Shape is not in group Information about where the segment and Shape intersect.Vect physics. Space : s e g m e n t Q u e r y F i r s t ( s t a r t v e c t .

14 SegmentQueryInfo A SegmentQueryInfo object is a Lua dictionary table with three fields.. 1) from the start of the line segment to the intersection of the Shape.14.Vect in physics.Vect out number Description The input SegmentQueryInfo An end point of the segment Other end point of the segment Hit distance Returns the absolute distance where the segment first hit the Shape.apiLevel = ’2. This object also has the following helper routines which convert information in a SegmentQueryInfo object to world coordinates or an absolute distance along the line segment.2 hitPoint p = SegmentQueryInfo : h i t P o i n t ( s t a r t v e c t .SegmentQueryInfo in physics.1 hitDist d = SegmentQueryInfo : h i t D i s t ( s t a r t v e c t .0’ 12. s t o p v e c t ) Parameter self startvect stopvect p Type in physics. s t o p v e c t ) Parameter self startvect stopvect d Type in physics. Fractional distance (0 .0’ 12.Introduced in platform.Vect out physics. Key shape t n Value Shape object found in a query.apiLevel = ’2. 12. Introduced in platform.Vect Description The input SegmentQueryInfo An end point of the segment Other end point of the segment Hit point 125 .Vect in physics.14. Surface normal vector of the Shape at the intersection point.SegmentQueryInfo in physics.

Introduced in platform.0’ 126 .Returns the hit point in world coordinates where the segment between startvect and stopvect first intersects the Shape.apiLevel = ’2.

0 ’ Note −− Change t h e API l e v e l t o ’ 1 . apiLevel = ’ 1 . print ( platform . The following list indicates the currently supported script API revisions: • ’1. 0 ’ 127 .1 apiLevel platform . apiLevel ) Setting the API level allows scripts written in previous TI-NspireTM versions to run on the current version.apiLevel. The default value is set to highest revision value supported in the current TI-NspireTM version. apiLevel Uniquely identifies the Script API revision offered by a TI-NspireTM software version.0’ To know the current revision of the script API. 13.Chapter 13 Platform Library Platform specific information is available through the platform library. read the platform.0’ • ’2. Platform .

apiLevel = ”2.3 hw p l a t f o r m . This graphics context should not be used to draw graphics because it is not guaranteed to be associated with a window. It is typically used to measure pixel lengths and heights of strings when a normal graphics context is not available. • Dynamically loaded scripts (dostring() ) will use the same ’platform.apiLevel = ”2. Introduced in platform.0” Removed in platform. gc ( ) Returns a dummy graphics context.X’ statement should be in the main part of the script only. the platform. hw ( ) 128 . gc ( ) gc : b e g i n ( ) l o c a l width = gc : g e t S t r i n g W i d t h ( a s t r i n g ) l o c a l h e i g h t = gc : g e t S t r i n g H e i g h t ( a s t r i n g ) gc : f i n i s h ( ) It is important to use gc:begin() to set up the graphics context before using it in the getString function and to call gc:finish() to relinquish it when finished with it.2 gc p l a t f o r m . A graphics context is available only during paint events. Here is an example of using the dummy graphics context to get the string pixel length and height.apiLevel = ”1. Introduced in platform. This may be the case when creating new text elements when the script app is initialized. It should not be inside any function.• If present. and that may be too late to create and size the containers for text fields.apiLevel = ’X.apiLevel = ’X.0” 13. l o c a l gc = p l a t f o r m . It is advisable to place it on the first line of the script.0” 13.X” as the main script.

end ) 129 . . r e g i s t e r E r r o r H a n d l e r ( f u n c t i o n ( lineNumber . The higher the number.6 registerErrorHandler p l a t f o r m .Returns a numeric value that indicates the CPU speed of the host hardware.4 isColorDisplay platform . Note platform.apiLevel = ”1.0” 13.apiLevel = ”2. isDeviceModeRendering ( ) Returns true if the script is running on the handheld device or in the emulator of the desktop software.apiLevel = ”1.5 isDeviceModeRendering p l a t f o r m . e r r o r M e s s a g e . l o c a l s ) . level 3 7 host hardware TI-NspireTM B&W and CX handheld devices Microsoft R Windows R .isDeviceModeRendering is not available during script initialization or within on. Mac R or web player Introduced in platform.0” 13.0” 13. Returns false if the script is running in the normal view of the desktop software. . Introduced in platform. isColorDisplay () Returns true if the display of the host platform is color. the faster the hardware. Introduced in platform. c a l l S t a c k .restore . Returns false if the display is grayscale.

window : width ( ) Routines height() and width() return the pixel height and width respectively of the display window. Note The error handler callback function is not called for errors that occur during initialization or within on. window Returns the window object that the script application currently owns.7 window p l a t f o r m .7.apiLevel = ”1. The 130 . window : i n v a l i d a t e ( x . Introduced in platform. x and y default to (0. y . Introduced in platform.0” 13.apiLevel = ”2. h e i g h t ) This function invalidates a region of the window and forces it to repaint.1 height and width p l a t f o r m . The window consists of the portion of the page allotted to the script app.0” 13. Returning a true value prevents reporting the Error to the user. width .This function sets the error handler callback function for the script. The script will continue executing on the next event. Several applications can be visible when the page is arranged in a split layout.0” 13.7. 0) and width and height default to the pixel width and height of the window.restore . Introduced in platform. Each visible application has its own window.2 invalidate p l a t f o r m . The window object has several methods of particular interest.apiLevel = ”1. window : h e i g h t ( ) p l a t f o r m . Setting an error handler callback function provides control over what happens when an error is encountered in the script.

withGC ( getHeightWidth . f u n c t i o n s e t F o n t ( f a m i l y . s i z e . Here is an example of using withGC() to get the pixel length and height of a string.apiLevel = ”2. window : s e t F o c u s ( t r u e o r f a l s e ) This function sets the focus to the main window.window:invalidate(). width = p l a t f o r m . withGC ( f u n c t i o n . s t y l e . gc ) f . ’ H e l l o World ’ ) 131 . Any focus of other objects is removed (D2Editor). When creating new text elements. this may be the case when the script app is initialized. Introduced in platform. s .8 withGC p l a t f o r m . Introduced in platform. This graphics context cannot be used to draw. which allows all parameters to take their default values. ’ s e r i f ’ . 1 2 ) h e i g h t . s i z e ) end f u n c t i o n getHeightWidth ( s t r .7. width end −− S e t t h e f o n t −− P p i x e l l e n g t h o f s t r −− P i x e l h e i g h t o f s t r p l a t f o r m . and that may be too late to create and size the containers for text fields. ’ b ’ . A graphics context is available only during paint events. a r g s ) Executes function(args) within a dummy graphics context and returns all return values from function(). withGC ( setFont .entire window can be forced to repaint with a call to platform. gc ) width = gc : g e t S t r i n g W i d t h ( s t r ) h e i g h t = gc : g e t S t r i n g H e i g h t ( s t r ) r e t u r n h e i g h t .0” 13.0” 13.3 setFocus p l a t f o r m . s t y l e . z = gc : s e t F o n t ( f a m i l y . It is used typically to measure the pixel lengths and heights of strings when a normal graphics context is not available.apiLevel = ”1.

Introduced in platform.apiLevel = ”2.Note: Although you could combine the two functions above into a single function to avoid calling withGC() twice.0” 132 . that is not required because the dummy graphics context remembers its state.

”magenta”. ”red”. ”blue”.apiLevel = ’2.Chapter 14 Module Library r e q u i r e ’ < l i b r a r y name > ’ Use require to load predefined libraries in TI-NspireTM software. Please see the following table. ”white”.0’ 133 . ”navy”. ”dodgerblue” Introduced in platform. ”brown”. Library color physics Description Table defining colors used in TI-NspireTM software to color objects via the color picker. User-defined libraries are not supported. The behavior of require is the same as in standard Lua but the available libraries are restricted. ”green”. ”orange”. ”gray”. ”darkgray”. Colors defined in color table: ”black”. ”lightgray”. ”mediumgray”. ”yellow”. Loads the physics module.

uchar ( chnum .Chapter 15 String Library Extension In addition to the standard Lua string functions. ) Unicode characters can be included in strings by encoding them in UTF-8.apiLevel = ’1. . s p l i t ( s t r [ . a few routines aid handling Unicode strings.apiLevel = ’1.1 split s t r i n g . returning a list of the substrings. 15.0’ 15.0’ 15.2 uchar s t r i n g . . . Introduced in platform. This routine converts one or more Unicode character numbers into a UTF-8 string. delim ] ) Divides str into substrings based on a delimiter. Introduced in platform.3 usub 134 . The default pattern for the delimiter is white space (”%s+”).

s t a r t p o s . 2 . 3 ) ) −− p r i n t s ” bc ” This routine returns a substring of str.sub. 2 ) ) −− p r i n t s ”b” p r i n t ( s t r i n g . endpos ) p r i n t ( s t r i n g . 1 ) ) −− p r i n t s ” a ” p r i n t ( s t r i n g . endpos ) or s t r : usub ( s t a r t p o s . It is the Unicode version of string. It allocates a temporary memory buffer during its operation. It accounts for multi-byte characters encoded in UTF-8. 1 . Introduced in platform. Caution This is an expensive routine. usub ( s t r . usub ( ” abc ” . usub ( ” abc ” . 2 .apiLevel = ’1.0’ 135 . usub ( ” abc ” .s t r i n g .

The timer resolution depends on the platform.2 start timer . Please be cautious with short timer periods on the handheld. Introduced in platform. It is about 0.02 second on the handheld.timer() function to respond to timer expiration. s t a r t ( period ) 136 .0’ 16.Chapter 16 Timer Library Each script application has one timer at its disposal. The timer is stopped automatically when the document containing the script application is closed or if the script application is deleted from the document.1 getMilliSecCounter timer . The counter rolls over to zero when it passes 232 milliseconds. getMilliSecCounter () Returns the value of the internal millisecond counter. 16. The script application should implement the on.apiLevel = ’1. The timer continues to send ticks to the script application even when its window is not visible on the screen.

timer() event completes.apiLevel = ’1. 16.apiLevel = ’1.0’ 137 . Introduced in platform.timer() event unless it is the final statement before the on.start() should not be called when processing an on. If the timer is already running when this routine is called.Starts the timer with the given period in seconds.3 stop timer . stop () Stops the timer. the timer is reset to the new period.0’ Caution timer. Introduced in platform. The period must be ≥ 0.01 (10 ms).

binopOr } . −− Menu item ” Decimal ” c a l l s s e t D e c ( ) { ” Hexadecimal ” . r e g i s t e r ( menu ) 138 . { ”Or ” . }. 17. and the function to call when the user invokes the menu item. } t o o l p a l e t t e . the menus that appear in each tool box. { ” Boolean ” . }. binopAnd } . r e g i s t e r ( menuStructure ) The script app uses this routine to register its tool palette with the TI-NspireTM framework. This example serves to demonstrate the layout of a tool palette’s menu structure. The menu structure is a table describing the name of each toolbox. −− Tool box ”Mode” { ” Decimal ” . s e t S i g n e d } . s e t D e c } .Chapter 17 Tool Palette Library The tool palette provides a menu of commands from which the user can select commands that invoke functionality of the script app. menu = { { ”Mode ” . ” − ”. { ”And” .1 register t o o l p a l e t t e . s e t U n s i g n e d } . { ” Unsigned ” . −− S e c t i o n d i v i d e r {” S i g n e d ” . setHex } .

0’ 17.toolpalette. Introduced in platform.enable().3 enableCut t o o l p a l e t t e . It returns nil if the toolname / itemname pair cannot be found in the registered menu items. e n a b l e ) This routine enables or disables a menu item in the tool palette. Parameter itemname is a string containing the name of the menu item. e n a b l e ( toolname . Parameter toolname is a string containing the name of the top level tool box. Introduced in platform.apiLevel = ’1. Info Beginning with platform.register(nil) deactivates the toolpalette. Calling toolpalette. This routine returns true if the menu item was properly enabled or disabled. Once registered. Introduced in platform. register () mist be called prior to toolpalette . Parameter enable is a Boolean value that enables the command if true or disables the menu item if false. Note toolpalette . the tool palette is managed automatically by the TI-NspireTM framework. Up to 15 toolboxes can be created with up to 30 menu items each. itemname .register can be called once in the top level flow of the script app. Parameter enable is a Boolean value that enables the menu item if true or disables the menu item if false. the associated function is called with two parameters: the name of the toolbox and the name of the menu item. the names of the tool palette items can be changed dynamically while the program is running.0’ 139 .apiLevel = ’1.0’ 17.2 enable t o o l p a l e t t e . enableCut ( e n a b l e ) This routine enables or disables the Edit > Cut menu command. When the user chooses an item from a tool box.apiLevel = ’2.0’.apiLevel = ’1.

apiLevel = ’1. enablePaste ( enable ) This routine enables or disables the Edit > Paste menu command. enableCopy ( e n a b l e ) This routine enables or disables the Edit > Copy menu command.apiLevel = ’1. Introduced in platform. Introduced in platform.17.4 enableCopy t o o l p a l e t t e . Parameter enable is a Boolean value that enables the command if true or disables the menu item if false.5 enablePaste t o o l p a l e t t e .0’ 17. Parameter enable is a Boolean value that enables the command if true or disables the menu item if false.0’ 140 .

But many important variable types are supported: real and integer numbers.2 makeNumericList var . Introduced in platform.0’ 18. The list is optimized to hold numeric values.1 list var . Not all variables in the symbol table have compatible types in Lua. matrices (represented in Lua as lists of lists). This library gives scripts access to the variables stored in the symbol table. and lists of numbers and strings.Chapter 18 Variable Library A symbol table is used by the TI-NspireTM math engine to calculate and store variables. strings. Routines storeAt and recallAt operate much more efficiently on lists that are created with this function. and boolean constants true and false. makeNumericList ( name ) Creates a list in the symbol table with the given name.apiLevel = ’1. 18. l i s t ( ) This function returns a list of names of variables currently defined in the symbol table. 141 .

Routines var. 2 } . r e c a l l A t ( ” mat ” . var . r e c a l l A t ( name . 4 } } ) var . r e c a l l ( name ) Returns the value of a math variable with the given name. If the type of the named variable has no compatible Lua type. row is a 1-based row number. s t o r e A t ( ” mat ” .4 recall var .5 recallAt var . 1 .apiLevel = ’2.Usage Note This function cannot be used to create a numeric matrix.apiLevel = ’1.0’ −− c r e a t e s matrix mat 18. 1 ) v a l = var .apiLevel = ’1. { { 1 . { 3 . row is only required when recalling a value from a matrix. Introduced in platform.0’ 18. row ] ) Recalls a value from a cell of a list or matrix in the symbol table. col is a 1-based column number of the matrix or list.recallAt and var. 1 ) Introduced in platform. 142 . monitor ( name ) Turns on monitoring of the math variable with given name. s t o r e ( ” mat ” . 1 3 .varChange below. Introduced in platform. 3 . See the description of on. this script application’s on.0’ 18.varChange handler is called.3 monitor var . c o l [ .storeAt documented below will work with matrices but only if they are created by some other means. Any other return value from 0 is an error value. 1 . then nil and an error message are returned. Whenever another application changes the math variable.

row ] ) Stores a numeric value into an element of a math list or matrix with the given name. an error message is returned. this function returns nil and an error message string.0’ 18. Otherwise.This function is optimized to work with numeric values and normally returns a number.apiLevel = ’1.0’ 18. row is a 1-based row number. s t o r e ( name . nil is returned. The value must be numeric. If the value cannot be stored. Some math types have no compatible Lua type but all math types can be represented as a string. Introduced in platform. 143 . r e c a l l S t r ( name ) Returns the value of a math variable with the given name as a string. Introduced in platform. If the value of the recalled cell is not numeric.apiLevel = ’2. c o l [ .0’ 18. v a l u e ) Stores value as a math variable with the given name. New values can be appended to a list by storing to one column past the end of the list.8 storeAt var . this function returns nil and an error message. Introduced in platform.6 recallStr var . This function is useful particularly as an optimization when adding new values to a list during a simulation. If the value cannot be recalled even as a string.apiLevel = ’1.7 store var . row is only required when storing a value into a matrix. Any other type raises an error. col is a 1-based column number of the matrix or list. numericValue . s t o r e A t ( name .

0’ 144 .9 unmonitor var .0’ 18.apiLevel = ’2. unmonitor ( name ) Turns off monitoring of the named math variable.Returns nil on success or ”cannot store” if the value cannot be stored at the given index. Introduced in platform. Introduced in platform.apiLevel = ’1.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->