lua_api.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. .. contents::
  2. Math
  3. ====
  4. Vector3
  5. -------
  6. **Vector3** (x, y, z) : Vector3
  7. Constructor.
  8. **x** (v) : float
  9. Returns the x value of the vector.
  10. **y** (v) : float
  11. Returns the y value of the vector.
  12. **z** (v) : float
  13. Returns the z value of the vector.
  14. **.x** : float
  15. Returns/assigns the x value of the vector.
  16. **.y** : float
  17. Returns/assigns the y value of the vector.
  18. **.z** : float
  19. Returns/assigns the z value of the vector.
  20. **set_x** (v, x)
  21. Sets the value of the x value of the vector.
  22. **set_y** (v, y)
  23. Sets the value of the y value of the vector.
  24. **set_z** (v, z)
  25. Sets the value of the z value of the vector.
  26. **values** (v) : float, float, float
  27. Returns the x, y and z values of the vector.
  28. **add** (a, b) : Vector3
  29. Adds the vector *a* to *b* and returns the result.
  30. **subtract** (a, b) : Vector3
  31. Subtracts the vector *b* from *a* and returns the result.
  32. **multiply** (a, k) : Vector3
  33. Multiplies the vector *a* by the scalar *k* and returns the result.
  34. **divide** (a, k) : Vector3
  35. Divides the vector *a* by the scalar *k* and returns the result.
  36. **dot** (a, b) : float
  37. Returns the dot product between the vectors *a* and *b*.
  38. **cross** (a, b) : Vector3
  39. Returns the cross product between the vectors *a* and *b*.
  40. **equal** (a, b) : bool
  41. Returns true whether the vectors *a* and *b* are equal.
  42. **length** (a) : float
  43. Returns the lenght of *a*.
  44. **squared_length** (a) : float
  45. Returns the squared length of *a*.
  46. **set_length** (a, len)
  47. Sets the lenght of *a* to *len*.
  48. **normalize** (a) : Vector3
  49. Normalizes *a* and returns the result.
  50. **distance** (a, b) : float
  51. Returns the distance between the points *a* and *b*.
  52. **angle** (a, b) : float
  53. Returns the angle between the vectors *a* and *b*.
  54. Quaternion
  55. ----------
  56. **Quaternion** (v, w) : Quaternion
  57. Constructor.
  58. **negate** (q) : Quaternion
  59. Negates the quaternion *q* and returns the result.
  60. **identity** () : Quaternion
  61. Returns the identity quaternion.
  62. **multiply** (a, b) : Quaternion
  63. Multiplies the quaternions *a* and *b*. (i.e. rotates first by *a* then by *b*).
  64. **multiply_by_scalar** (a, k) : Quaternion
  65. Multiplies the quaternion *a* by the scalar *k*.
  66. **length** (q) : float
  67. Returns the length of *q*.
  68. **conjugate** (q) : Quaternion
  69. Returns the conjugate of quaternion *q*.
  70. **inverse** (q) : Quaternion
  71. Returns the inverse of quaternion *q*.
  72. **power** (q, exp) : Quaternion
  73. Returns the quaternion *q* raised to the power of *exp*.
  74. **elements** (q) : x, y, z, w
  75. Returns the elements of the quaternion.
  76. Matrix4x4
  77. ---------
  78. **Matrix4x4** (m0, m1, ..., m15) : Matrix4x4
  79. Constructor.
  80. **from_quaternion** (q) : Matrix4x4
  81. Returns a new matrix from *q*.
  82. **from_translation** (t) : Matrix4x4
  83. Returns a new matrix from *t*.
  84. **from_quaternion_translation** (q, t) : Matrix4x4
  85. Returns a new matrix from *q* and *t*.
  86. **from_axes** (x, y, z, t) : Matrix4x4
  87. Returns a new matrix from *x*, *y*, *z* and *t*.
  88. **add** (a, b) : Matrix4x4
  89. Adds the matrix *a* to *b* and returns the result.
  90. **subtract** (a, b) : Matrix4x4
  91. Subtracts the matrix *b* from *a* and returns the result.
  92. **multiply** (a, b) : Matrix4x4
  93. Multiplies the matrix *a* by *b* and returns the result. (i.e. transforms first by *b* then by *a*)
  94. **transpose** (m) : Matrix4x4
  95. Transposes the matrix *m* and returns the result.
  96. **determinant** (m) : float
  97. Returns the determinant of the matrix *m*.
  98. **invert** (m) : Matrix4x4
  99. Inverts the matrix *m* and returns the result.
  100. **x** (m) : Vector3
  101. Returns the x asis of the matrix *m*.
  102. **y** (m) : Vector3
  103. Returns the y asis of the matrix *m*.
  104. **z** (m) : Vector3
  105. Returns the z asis of the matrix *m*.
  106. **set_x** (m, x)
  107. Sets the x axis of the matrix *m*.
  108. **set_y** (m, y)
  109. Sets the y axis of the matrix *m*.
  110. **set_z** (m, z)
  111. Sets the z axis of the matrix *m*.
  112. **translation** (a) : Vector3
  113. Returns the translation portion of the matrix *m*.
  114. **set_translation** (t)
  115. Sets the translation portion of the matrix *m*.
  116. **identity** ()
  117. Returns the identity matrix.
  118. **to_string** (a)
  119. Returns a string representing the matrix.
  120. World
  121. =====
  122. **spawn_unit** (world, name, [position, rotation]) : Unit
  123. Spawns a new instance of the unit *name* at the given *position* and *rotation*.
  124. **destroy_unit** (world, unit)
  125. Destroys the given *unit*.
  126. **num_units** (world) : int
  127. Returns the number of units in the *world*.
  128. **units** (world) : Table
  129. Returns all the the units in the world in a table.
  130. **update_animations** (world, dt)
  131. Update all animations with *dt*.
  132. **update_scene** (world, dt)
  133. Updates the scene with *dt*.
  134. **update** (world, dt)
  135. Updates the world with *dt*.
  136. **play_sound** (world, name, [loop, volume, position, range]) : SoundInstanceId
  137. Plays the sound with the given *name* at the given *position*, with the given
  138. *volume* and *range*. *loop* controls whether the sound must loop or not.
  139. **stop_sound** (world, id)
  140. Stops the sound with the given *id*.
  141. **link_sound** (world, id, unit, node)
  142. Links the sound *id* to the *node* of the given *unit*.
  143. After this call, the sound *id* will follow the unit *unit*.
  144. **set_listener_pose** (world, pose)
  145. Sets the *pose* of the listener.
  146. **set_sound_position** (world, position)
  147. Sets the *position* of the sound *id*.
  148. **set_sound_range** (world, range)
  149. Sets the *range* of the sound *id*.
  150. **set_sound_volume** (world, volume)
  151. Sets the *volume* of the sound *id*.
  152. **create_window_gui** (world) : Gui
  153. Creates a new window-space Gui of size *width* and *height*.
  154. **destroy_gui** (world, id)
  155. Destroys the gui with the given *id*.
  156. **create_debug_line** (world, depth_test) : DebugLine
  157. Creates a new DebugLine. *depth_test* controls whether to
  158. enable depth test when rendering the lines.
  159. **destroy_debug_line** (world, line)
  160. Destroys the debug *line*.
  161. **load_level** (world, name) : Level
  162. Loads the level *name* into the world.
  163. **physics_world** (world) : PhysicsWorld
  164. Returns the physics sub-world.
  165. **sound_world** (world) : SoundWorld
  166. Returns the sound sub-world.
  167. Unit
  168. ----
  169. **node** (unit, name)
  170. Returns the node *name*.
  171. **has_node** (unit, name) : int
  172. Returns whether the unit has the node *name*.
  173. **num_nodes** (unit) : int
  174. Returns the number of nodes of the unit.
  175. **local_position** (unit) : Vector3
  176. Returns the local position of the unit.
  177. **local_rotation** (unit) : Quaternion
  178. Returns the local rotation of the unit.
  179. **local_pose** (unit) : Matrix4x4
  180. Returns the local pose of the unit.
  181. **world_position** (unit) : Vector3
  182. Returns the world position of the unit.
  183. **world_rotation** (unit) : Quaternion
  184. Returns the world rotation of the unit.
  185. **world_pose** (unit) : Matrix4x4
  186. Returns the world pose of the unit.
  187. **set_local_position** (unit, position)
  188. Sets the local position of the unit.
  189. **set_local_rotation** (unit, rotation)
  190. Sets the local rotation of the unit.
  191. **set_local_pose** (unit, pose)
  192. Sets the local pose of the unit.
  193. **link_node** (unit)
  194. Links the *child* node to the *parent* node.
  195. After the linking the *child* pose is reset to identity.
  196. Note that *parent* node must be either -1 (meaning no parent), or an index lesser than child.
  197. **unlink_node** (unit, child)
  198. Unlinks *child* from its parent, if any.
  199. **camera** (unit, name)
  200. Returns the camera *name*.
  201. **material** (unit, name)
  202. Returns the material *name*.
  203. **mesh** (unit, name)
  204. Returns the mesh *name*.
  205. **sprite** (unit, name)
  206. Returns the sprite *name*.
  207. **actor** (unit, name)
  208. Returns the actor *name*.
  209. **controller** (unit, name)
  210. Returns the controller *name*.
  211. **is_a** (unit, type)
  212. Returns whether the unit is of the given *type*.
  213. **play_sprite_animation** (unit, name, loop)
  214. Plays the sprite animation *name*.
  215. **stop_sprite_animation** (unit)
  216. Stops the current playing animation.
  217. Camera
  218. ------
  219. **local_position** (camera, position)
  220. Returns the local position of the camera.
  221. **local_rotation** (camera, rotation)
  222. Returns the local rotation of the camera.
  223. **local_pose** (camera, pose)
  224. Returns the local pose of the camera.
  225. **world_position** (camera) : Vector3
  226. Returns the world position of the camera.
  227. **world_rotation** (camera) : Quaternion
  228. Returns the world rotation of the camera.
  229. **world_pose** (camera) : Matrix4x4
  230. Returns the world pose of the camera.
  231. **set_local_position** (camera, unit, position)
  232. Sets the local position of the camera.
  233. **set_local_rotation** (camera, unit, rotation)
  234. Sets the local rotation of the camera.
  235. **set_local_pose** (camera, unit, pose)
  236. Sets the local pose of the camera.
  237. **set_projection_type** (camera, type)
  238. Sets the projection type of the camera.
  239. **projection_type** (camera) : int
  240. Returns the projection type of the camera.
  241. **fov** (camera) : float
  242. Returns the field-of-view of the camera in degrees.
  243. **set_fov** (camera, degrees)
  244. Sets the field-of-view of the camera in degrees.
  245. **aspect** (camera) : float
  246. Returns the aspect ratio of the camera. (Perspective projection only.)
  247. **set_aspect** (camera)
  248. Sets the aspect ratio of the camera. (Perspective projection only.)
  249. **near_clip_distance** (camera) : float
  250. Returns the near clip distance of the camera.
  251. **set_near_clip_distance** (camera, near)
  252. Sets the near clip distance of the camera.
  253. **far_clip_distance** (camera) : float
  254. Returns the far clip distance of the camera.
  255. **set_far_clip_distance** (camera, far)
  256. Sets the far clip distance of the camera.
  257. **set_orthographic_metrics** (camera, left, right, bottom, top)
  258. Sets the coordinates for orthographic clipping planes. (Orthographic projection only.)
  259. **set_viewport_metrics** (camera, x, y, width, height)
  260. Sets the coordinates for the camera viewport in pixels.
  261. **screen_to_world** (camera, pos) : Vector3
  262. Returns *pos* from screen-space to world-space coordinates.
  263. **world_to_screen** (camera, pos) : Vector3
  264. Returns *pos* from world-space to screen-space coordinates.
  265. Sprite
  266. ------
  267. **local_position** (sprite) : Vector3
  268. Returns the local position of the sprite.
  269. **local_rotation** (sprite) : Quaternion
  270. Returns the local rotation of the sprite.
  271. **local_pose** (sprite) : Matrix4x4
  272. Returns the local pose of the sprite.
  273. **set_local_position** (sprite, unit, position)
  274. Sets the local position of the sprite.
  275. **set_local_rotation** (sprite, unit, rotation)
  276. Sets the local rotation of the sprite.
  277. **set_local_pose** (sprite, unit, pose)
  278. Sets the local pose of the sprite.
  279. **set_frame** (sprite, num)
  280. Sets the frame of the sprite.
  281. Mesh
  282. ----
  283. **local_position** (mesh) : Vector3
  284. Returns the local position of the mesh.
  285. **local_rotation** (mesh) : Quaternion
  286. Returns the local rotation of the mesh.
  287. **local_pose** (mesh) : Matrix4x4
  288. Returns the local pose of the mesh.
  289. **set_local_position** (mesh, unit, position)
  290. Sets the local position of the mesh.
  291. **set_local_rotation** (mesh, unit, rotation)
  292. Sets the local rotation of the mesh.
  293. **set_local_pose** (mesh, unit, pose)
  294. Sets the local pose of the mesh.
  295. Material
  296. --------
  297. set_float
  298. TODO
  299. set_vector2
  300. TODO
  301. set_vector3
  302. TODO
  303. Gui
  304. ---
  305. resolution
  306. TODO
  307. move
  308. TODO
  309. screen_to_gui
  310. TODO
  311. draw_rectangle
  312. TODO
  313. draw_image
  314. TODO
  315. draw_image_uv
  316. TODO
  317. draw_text
  318. TODO
  319. Physics World
  320. =============
  321. **gravity** (physics_world) : Vector3
  322. Returns the gravity.
  323. **set_gravity** (physics_world, gravity)
  324. Sets the gravity.
  325. **make_raycast**
  326. TODO
  327. **overlap_test**
  328. TODO
  329. Controller
  330. ----------
  331. **move** (controller, position)
  332. Moves the controller to *position*.
  333. **position** (controller) : Vector3
  334. Returns the position of the controller.
  335. **collides_up** (controller) : bool
  336. Returns whether the contoller collides upwards.
  337. **collides_down** (controller) : bool
  338. Returns whether the controller collides downwards.
  339. **collides_sides** (controller) : bool
  340. Returns whether the controller collides sidewards.
  341. Actor
  342. -----
  343. **world_position** (actor) : Vector3
  344. Returns the world position of the actor.
  345. **world_rotation** (actor) : Quaternion
  346. Returns the world rotation of the actor.
  347. **world_pose** (actor) : Matrix4x4
  348. Returns the world pose of the actor.
  349. **teleport_world_position** (actor, position)
  350. Teleports the actor to the given world position.
  351. **teleport_world_rotation** (actor, rotation)
  352. Teleports the actor to the given world rotation.
  353. **teleport_world_pose** (actor, pose)
  354. Teleports the actor to the given world pose.
  355. **center_of_mass** (actor) : Vector3
  356. Returns the center of mass of the actor.
  357. **enable_gravity** (actor)
  358. Enables gravity for the actor.
  359. **disable_gravity** (actor)
  360. Disables gravity for the actor.
  361. **enable_collision** (actor)
  362. Enables collision detection for the actor.
  363. **disable_collision** (actor)
  364. Disables collision detection for the actor.
  365. **set_collision_filter** (actor, name)
  366. Sets the collision filter of the actor.
  367. **set_kinematic** (actor, kinematic)
  368. Sets whether the actor is kinematic or not.
  369. Note that this call has no effect on static actors.
  370. **move** (actor, position)
  371. Moves the actor to *pos*
  372. Note that this call only affects nonkinematic actors.
  373. **is_static** (actor) : bool
  374. Returns whether the actor is static.
  375. **is_dynamic** (actor) bool
  376. Returns whether the actor is dynamic.
  377. **is_kinematic** (actor) : bool
  378. Returns whether the actor is kinematic (keyframed).
  379. **is_nonkinematic** (actor) : bool
  380. Returns whether the actor is nonkinematic (i.e. dynamic and not kinematic).
  381. **linear_damping** (actor) : float
  382. Returns the linear damping of the actor.
  383. **set_linear_damping** (actor, damping)
  384. Sets the linear damping of the actor.
  385. **angular_damping** (actor) : float
  386. Returns the angular damping of the actor.
  387. **set_angular_damping** (actor, rate)
  388. Sets the angular damping of the actor.
  389. **linear_velocity** (actor) : Vector3
  390. Returns the linear velocity of the actor.
  391. **set_linear_velocity** (actor, velocity)
  392. Sets the linear velocity of the actor.
  393. Note that this call only affects nonkinematic actors.
  394. **angular_velocity** (actor) : Vector3
  395. Returns the angular velocity of the actor.
  396. **set_angular_velocity** (actor, velocity)
  397. Sets the angular velocity of the actor.
  398. Note that this call only affects nonkinematic actors.
  399. **add_impulse** (actor, impulse)
  400. Adds a linear impulse (acting along the center of mass) to the actor.
  401. Note that this call only affects nonkinematic actors.
  402. **add_impulse_at** (actor, impulse, position)
  403. Adds a linear impulse (acting along the world position *pos*) to the actor.
  404. Note that this call only affects nonkinematic actors.
  405. **add_torque_impulse** (actor, impulse)
  406. Adds a torque impulse to the actor.
  407. **push** (actor, velocity, mass)
  408. Pushes the actor as if it was hit by a point object with the given *mass*
  409. travelling at the given *velocity*.
  410. Note that this call only affects nonkinematic actors.
  411. **push_at** (actor, velocity, mass, position)
  412. Like push() but applies the force at the world position *pos*.
  413. Note that this call only affects nonkinematic actors.
  414. **is_sleeping** (actor) : bool
  415. Returns whether the actor is sleeping.
  416. **wake_up** (actor)
  417. Wakes the actor up.
  418. **unit** (actor) : Unit
  419. Returns the unit that owns the actor or nil;
  420. Sound World
  421. ===========
  422. **stop_all** (sound_world)
  423. Stops all the sounds in the world.
  424. **pause_all** (sound_world)
  425. Pauses all the sounds in the world
  426. **resume_all** (sound_world)
  427. Resumes all previously paused sounds in the world.
  428. **is_playing** (sound_world, id) : bool
  429. Returns wheter the sound *id* is playing.
  430. Resource Package
  431. ================
  432. **load** (package)
  433. Loads all the resources in the package.
  434. Note that the resources are not immediately available after the call is made,
  435. instead, you have to poll for completion with has_loaded().
  436. **unload** (package)
  437. Unloads all the resources in the package.
  438. **flush** (package)
  439. Waits until the package has been loaded.
  440. **has_loaded** (package) : bool
  441. Returns whether the package has been loaded.
  442. Device
  443. ======
  444. **platform** () : string
  445. Returns a string identifying what platform the engine is running on.
  446. **architecture** () : string
  447. Returns a string identifying what architecture the engine is running on.
  448. **version** () : string
  449. Returns a string identifying the engine version.
  450. **last_delta_time** () : float
  451. Returns the time in seconds needed to render the last frame
  452. **quit** ()
  453. Quits the application.
  454. **resolution** () : Table
  455. Returns the main window resolution.
  456. **create_world** () : World
  457. Creates a new world.
  458. **destroy_world** (world)
  459. Destroys the given *world*.
  460. **render_world** (world, camera)
  461. Renders the given *world* from the point of view of the given *camera*.
  462. **create_resource_package** (name) : ResourcePackage
  463. Returns the resource package with the given *package_name* name.
  464. **destroy_resource_package** (package)
  465. Destroy a previously created resource *package*.
  466. Note that to unload the resources loaded by the package, you have to call
  467. ResourcePackage.unload() first.
  468. DebugLine
  469. =========
  470. **add_line** (debug_line, start, end)
  471. Adds a line from *start* to *end* with the given *color*.
  472. **add_sphere** (debug_line, center, radius)
  473. Adds a sphere at *center* with the given *radius* and *color*.
  474. **clear** (debug_line)
  475. Clears all the lines.
  476. **commit** (debug_line)
  477. Sends the lines to renderer for drawing.
  478. Input
  479. =====
  480. Keyboard
  481. --------
  482. **modifier_pressed** (modifier) : bool
  483. Returns whether the specified *modifier* is pressed.
  484. **button_pressed** (button) : bool
  485. Returns whether the specified *b* button is pressed in the current frame.
  486. **button_released** (button) : bool
  487. Returns whether the specified *b* button is released in the current frame.
  488. **any_pressed** () : bool
  489. Returns wheter any button is pressed in the current frame.
  490. **any_released** () : bool
  491. Returns whether any button is released in the current frame.
  492. Mouse
  493. -----
  494. **button_pressed** (button) : bool
  495. Returns whether the *b* button is pressed in the current frame.
  496. **button_released** (button) : bool
  497. Returns whether the *b* button is released in the current frame.
  498. **any_pressed** () : bool
  499. Returns wheter any button is pressed in the current frame.
  500. **any_released** () : bool
  501. DReturns whether any button is released in the current frame.ef
  502. **cursor_xy** () : Vector2
  503. Returns the position of the cursor in window space.
  504. **set_cursor_xy** (position)
  505. Sets the position of the cursor in window space.
  506. **cursor_relative_xy** () : Vector2
  507. Returns the relative position of the cursor in window space.
  508. **set_cursor_relative_xy** (position)
  509. Sets the relative position of the cursor in window space.
  510. Touch
  511. -----
  512. **pointer_down** (pointer) : bool
  513. Returns whether the *p* pointer is pressed in the current frame.
  514. **pointer_up** (pointer) : bool
  515. Returns whether the *p* pointer is released in the current frame.
  516. **any_down** () : bool
  517. Returns wheter any pointer is pressed in the current frame.
  518. **any_up** () : bool
  519. Returns whether any pointer is released in the current frame.
  520. **pointer_xy** () : Vector2
  521. Returns the position of the pointer *p* in window space.
  522. Window
  523. ======
  524. **show** ()
  525. Shows the window.
  526. **hide** ()
  527. Hides the window.
  528. **resize** (width, height)
  529. Resizes the window to *width* and *height*.
  530. **move** (x, y)
  531. Moves the window to *x* and *y*.
  532. **minimize** ()
  533. Minimizes the window.
  534. **restore** ()
  535. Restores the window.
  536. **is_resizable** () : bool
  537. Returns whether the window is resizable.
  538. **set_resizable** (resizable)
  539. Sets whether the window is resizable.
  540. **title** () : string
  541. Returns the title of the window.
  542. **set_title** (title)
  543. Sets the title of the window.