Get started with Lua cloud functions

Hi everyone, today I'm going to show you how to get started with LazyDB lua cloud functions!

Create a lua cloud function

Creating a lua cloud function is really simple, you only need to db.create("your/path", return "My cool function"). This is how simple it is to create a lua function, of course, you can also use your dashboard to create the file as a string and add your lua code to it!

Here is a simple lua function to get the current amount of registered users.

local registered_users = Database.count("users") return registered_users

Run a lua cloud function in JS

Run a lua cloud function is really simple, you only need the path to your function and you can pass custom if you want to use it in your cloud function.

db.run("my/lua/fun", {}).then(result => { console.log("result of lua function: " + result); })

Run a lua cloud function in an HTML template

if you want, you can run a lua function in your HTML file and directly put the result in your file when someone wants to access it, here is an example of how to use our previous lua function to display registered users on our website.

There is currently {{my/lua/fun}} user online!