How to use the DOMAPI extension
When to use DOMAPI
Beware, with great power comes great responsibility; exposing the entire page to Lua can be dangerous.
Simply add the following code to your page, making sure you edit it to point at your distilled Lua script.
<script src="/path/to/moonshine/vm/moonshine.min.js"></script> <script src="/path/to/moonshine/extensions/DOMAPI/DOMAPI.moonshine.js"></script> <script>new shine.VM(shine.DOMAPI).load('./your-script.lua.json');</script>
window:alert 'hello' window.document:createElement 'div' window.navigator.geolocation:getCurrentPosition(successCallback, failCallback)
Extracting the properties of window
The above examples are all well and good, but you wouldn't usually fully-qualify some of these variables. You can quickly extract all the properties of the window table into the Lua global namespace, by calling its extract() method.
window.extract() alert 'hello' document:createElement 'div' navigator.geolocation:getCurrentPosition(successCallback, failCallback)
There is no keyword in Lua to intantiate a new object, therefore a new() method is added to classes.
local ws = WebSocket.new 'ws://127.0.0.1'
See the DOMAPI map example.