aboutsummaryrefslogtreecommitdiffstats
path: root/init.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-01-31 18:28:10 +0000
committers-ol <s-ol@users.noreply.github.com>2020-01-31 18:28:10 +0000
commit16962e1836251526fa08895b1a76dd72b7fd5ef9 (patch)
treeef60d08e792825407d41fb77c14c26ecb135e2fc /init.moon
parentnested parens in comments (diff)
downloadalive-16962e1836251526fa08895b1a76dd72b7fd5ef9.tar.gz
alive-16962e1836251526fa08895b1a76dd72b7fd5ef9.zip
modularize
Diffstat (limited to 'init.moon')
-rw-r--r--init.moon34
1 files changed, 34 insertions, 0 deletions
diff --git a/init.moon b/init.moon
new file mode 100644
index 0000000..c028e50
--- /dev/null
+++ b/init.moon
@@ -0,0 +1,34 @@
+import Registry from require 'registry'
+
+env = Registry!
+env\add_module 'math'
+env\add_module 'time'
+env\add_module 'util'
+env\add_module 'debug'
+
+if ... == 'init'
+ return env
+
+-- run from CLI
+import clock_gettime, nanosleep, CLOCK_MONOTONIC from require 'posix.time'
+import Copilot from require 'copilot'
+
+delta = do
+ gettime = ->
+ spec = clock_gettime CLOCK_MONOTONIC
+ spec.tv_sec + spec.tv_nsec * 1e-9
+
+ local last, time
+ ->
+ time = gettime!
+ with time - (last or time)
+ last = time
+
+copilot = Copilot arg[1], env
+while true
+ copilot\poll!
+
+ dt = delta!
+ env\update dt
+
+ assert nanosleep tv_sec: 0, tv_nsec: math.floor 1e9 / 60