Changes between Version 1 and Version 2 of documentation/LuaManual/EmbeddingScript
- Timestamp:
- 05/20/12 04:38:20 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
documentation/LuaManual/EmbeddingScript
v1 v2 6 6 == Inline event responses == 7 7 8 The Python plugin installs an event listener instancer to execute inline event responses as Pythoncode. For example, in the following sample the element will run the print command when it is clicked:8 The Lua plugin installs an event listener instancer to execute inline event responses as Lua code. For example, in the following sample the element will run the print command when it is clicked: 9 9 10 10 {{{ 31 31 See the [wiki:documentation/LuaManual/Elements element], [wiki:documentation/LuaManual/Documents document] and [wiki:documentation/LuaManual/Events event] documentation for their full Lua interfaces. 32 32 33 == Embedding Pythoninto RML ==33 == Embedding Lua into RML == 34 34 35 Python code can be embedded into an RML document with the <script> tag. Similarly to Javascript, the script can be included from a separate file with the ''src'' attribute, or otherwise declared inline as loose content within the <script> tag. Any code embedded in this manner will be compiled with the document and will be available to inline event handlers in the RML. For example, the following document declares a Pythonfunction in the <script> tag and calls it from an element's ''onclick'' hander.35 Lua code can be embedded into an RML document with the <script> tag. Similarly to Javascript, the script can be included from a separate file with the ''src'' attribute, or otherwise declared inline as loose content within the <script> tag. Any code embedded in this manner will be compiled with the document and will be available to inline event handlers in the RML. For example, the following document declares a Lua function in the <script> tag and calls it from an element's ''onclick'' hander. 36 36 37 37 {{{ 64 64 65 65 A document can include multiple <script> tags. 66 67 == Scope == 68 The scope of the functions and variables created in the RML files is global. To avoid two functions or variables from having the same name, make sure to put them in a table that is uniquely named. In LuaInvaders, the table is named after the file, to see an example. Alternatively, be incredibly careful with naming everything. 69 70 Because they are global, it is possible to call functions defined in other RML files, or any loose .lua files that have been loaded.