Install Lua
[X]brew install lua[X]Για την εκτέλεση κάποιου script πηγαίνουμε στο φάκελο που είναι το αρχείο με dired και εκτελούμε την shell-commandluaεπάνω του.[X]Επιπρόσθετες οδηγίες υπαρχουν εδώ.
Lua syntax
| tostring() | convert numbers to string |
| math.sin() | trigonometry |
| math.abs() | Απόλυτη τιμή |
| os.clock() | Ο χρόνος σε δευτερόλεπτα απο τη στιγμή που άρχισε η εφαρμογή |
| os.date("*t",os.time()).sec | Τα δευτερόλεπτα του ρολογιού |
Lua coroutines
co = coroutine.create(function ()
for i=1,10 do
print("co", i)
coroutine.yield()
end
end)
----------------------------------------------------
function setup()
of.setWindowTitle("test11")
of.background(0)
print(coroutine.status(co))
print(co)
coroutine.resume(co)
os.execute("ls")
end
----------------------------------------------------
function update()
end
----------------------------------------------------
function draw()
of.fill()
of.setColor(100,0,130,100)
of.rect(0,0,of.getWidth(), of.getHeight())
of.fill()
of.setColor(0,0,0,100)
of.rect(20,0,of.getWidth(), of.getHeight())
end
function keyPressed(key)
print("script keyPressed \""..tostring(key).."\"")
if key == string.byte("s") then
coroutine.resume(co)
print(coroutine.status(co))
end
end
LUA CODE
co = coroutine.create(
function ()
for i=1,10 do
of.fill()
of.setColor(255,0,0,100)
of.rect(20*i,0,of.getWidth(), of.getHeight())
coroutine.yield()
end
end)
----------------------------------------------------
function setup()
of.setWindowTitle("test11")
of.background(0)
print(coroutine.status(co))
print(co)
coroutine.resume(co)
os.execute("ls")
end
----------------------------------------------------
function update()
end
----------------------------------------------------
function draw()
end
----------------------------------------------------
function keyPressed(key)
print("script keyPressed \""..tostring(key).."\"")
if key == string.byte("s") then
coroutine.resume(co)
print(coroutine.status(co))
end
end