In this tutorial, we will be learning how to create Lua-Based JavaScript Documents that can be opened in any lua browser.
Place a blank .lua file with a unique name into the "lua/jsdocs" directory of your addon. This will be the file containing the code for your JavaScript document.
If you would not like to start from scratch, type LUA_JS.Base = "BASE CLASS NAME HERE"
in your file to set the desired base class for your script.
Type LUA_JS.Content = [[JAVASCRIPT CONTENT HERE]]
to set the content of your script.
The following are functions that can be used to do certain things with the script.
Checks to see if the object is valid.
Returns:
- bool isvalid: Whether or not the object is valid.
Returns the unique index of the object.
Returns:
- number index: The unique index of the object.
Removes the object, making it no longer valid or useable.
Returns the class name of the object.
Returns:
- string classname: The class name of the object.
Returns the content of the object.
Returns:
- string content: The content of the object.
Sets the content of the object.
Arguments:
- string content: The new content for the object.
Runs the script in a DHTML panel.
Arguments:
- Panel HTML: The DHTML panel to run the script in.
Runs a new script in this script's current panel.
Arguments:
- string class: The class name of the new script.
- boolean doNotRemove: Set to true to not remove this script when opening the other one.
Returns the current panel of the script.
Returns:
- panel currentpanel: The current panel the script was opened in.
The following are customizable functions that are called whenever certain events happen.
Called when the script is first created.
Called when the script is removed with its LUA_JS:Remove()
function.
Called when the script is ran in a DHTML panel.
Arguments:
- panel HTML: The DHTML panel the script was run in.
After writing your code, save the file, copy your addon into your addons directory, and test it. If there are any errors, they will show up in the console.