aboutsummaryrefslogtreecommitdiffstats
path: root/lib/init.server.moon
blob: 912bbb461b8c059a962dd652a8518ad6d8319e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export MODE, warn, relative, append, on_client
MODE = 'SERVER'

-- warning messages
warn = (...) ->
  io.stderr\write table.concat { ... }, '\t'
  io.stderr\write '\n'

-- relative imports
relative = (...) ->
  _require = require
  path = ...

  (name) ->
    name = path .. name if '.' == name\sub 1, 1
    require name

-- shorthand to append elements to body
buffer = ''
append = (val) ->
  buffer ..= val

import compile, insert_loader from require 'duct_tape'
insert_loader!

on_client = (fn, ...) ->
  args = {...}
  -- warn code
  append "<script type=\"application/lua\">
    MODE = 'HYBRID'
    local fn = #{compile fn}
    fn(#{table.concat [string.format '%q', v for v in *args ], ', '})
  </script>"

{
  -- access / flush the appended data
  flush: ->
    with x = buffer
      buffer = ''
}