Lua
Luau is a typed scripting language derived from Lua. Instead of JavaScript, we use Luau to power Web X.
Note: We say "Luau" as it is what we use in our backend, but you do not need to install it. You can write regular Lua and your code will work fine.
SET and GET.
The Luau API is as simple as learning two things: you can SET and you can GET. You can GET to access elements from your page's HTML++, and you can SET to modify them.
GET
In fact, the function to get an element is just called "get".
Note that we use the same function to get items by their tag name or by their class.
Remember the end of the HTML++ page, where we told you to avoid setting a class name with the same name as a tag? It's because of this, get("a")
will get an anchor, so you should not give an item a class name of class="a"
.
What about "
querySelectorAll()
?
Just add "true" to the get
function to get all the elements of the same class / tag name.
When you don't pass true
, if you select a tag or a class name that is repeated, the first one in the HTML++ will be taken.
SET
Now, to interact with the element, you can use get_{prop}
and set_{prop}
functions. Here's an example:
It's that easy! Scroll to the bottom for a list of available SET and GET directives.
Events
The Luau API has also support for detecting events. Similar to JS's onclick
. To use them, create a function that's called on an event, just like you would do in JS. Example:
on_input
is only supported by <input>
and <textarea>
Output from the print()
function will be logged by Napture Logs. As we told you before, you can open them with CONTROL
+ SHIFT
+ P
HTTP Fetching
If you need to make an HTTP request to interact with an API, you can use the fetch
function. It should look like this:
Variable names are self explanatory, you give the function the URL
you want to fetch, the HTTP method you want to use, which can be "GET", "POST", "DELETE", etc..., the headers of the HTTP request, and the body, which would be the content itself of your request.
Full lists
All the get_{x}
, set_{x}
and on_{x}
available functions.
On every function, whenever x
is expected to be a string or a number, it can always be passed both as a string/number directly or as a Lua variable.
GET
GETTING FUNCTIONS
Example usage of GET and GETTING FUNCTIONS
SET
Example usage of SET
EVENTS
Event functions do not have a return. As showed before, put them inside of a function. Every time they get triggered the code of the functions will be executed.
Example usage of EVENTS
OTHER FUNCTIONS
And that's it! You're ready to write fully functional WebX code! However, we're not done yet. Your beautiful code must be published to the WebX somehow, right? Let's find out about that.
Last updated