Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Rewrite entire project #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions example.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
local jua

if require then
jua = require("jua")
else
os.loadAPI("jua")
end
local jua = require("jua")

-- Local state to store seconds passed
local timePassed = 0

-- Register an event for termination, and don't terminate
jua.on("terminate", function()
print("Recieved terminate event. Ignoring...")
end)

-- Register an event for mouse_click events and print them to the screen
jua.on("mouse_click", function(event, button, x, y)
print("Mouse clicked at X: "..x.." Y:"..y)
print("Mouse clicked at X: "..x.." Y: "..y)
end)

jua.setTimeout(function()
print("The program ran for 5 seconds. Exiting...")
-- After 15 seconds have passed, print to the screen and stop jua
jua.onTimeout(15, function()
print("The program ran for 15 seconds. Exiting...")
jua.stop()
end, 5)
end)

-- After 5 seconds have passed, print to the screen
jua.onTimeout(5, function()
print("The program will exit in 10 seconds.")
end)

jua.setInterval(function()
-- Every 1 second, print the time passed to the screen
jua.onInterval(1, function()
timePassed = timePassed + 1
print(timePassed.." seconds have passed.")
end, 1)
end)

-- Create a promise that resolves after 1 second
jua.promise(function(resolve, reject)
jua.onTimeout(1, function()
resolve("Promise resolved after 1 second!")
end)
end)
.done(function(s) print(s) end)

-- Create a sleeping promise that rejects after 2 seconds
jua.sleep(2, true, "Promise rejected after 2 seconds!")
.fail(function(s) print(s) end)

jua.run()
-- Start jua with a callback (jua.run without callback)
jua.go(function()
print("Hello from Jua! Click on the screen or press Ctrl+T to test events...")
end)
Loading