git.s-ol.nu alive / 46734b2
add basic love2d support s-ol 4 months ago
6 changed file(s) with 187 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
3434
3535 ## starting the copilot
3636
37 $ moon init.moon <session.alv>
37 $ bin/alv <session.alv>
3838
3939 For more information see the [getting started guide][guide].
40
41 ### LÖVE / visuals
42
43 To use the 'love' module for relatime 2d graphics, the copilot needs to be
44 started using [love2d][love] (0.11+):
45
46 $ love bin/alv-love <session.alv>
4047
4148 ## running the tests
4249
6067 [busted]: https://olivinelabs.com/busted/
6168 [discount]: https://luarocks.org/modules/craigb/discount
6269 [ldoc]: https://github.com/s-ol/LDoc
70 [love]: https://love2d.org/
6371
6472 [docs]: https://alv.s-ol.nu
6573 [guide]: https://alv.s-ol.nu/guide.html
2424 super parse_args arg, { nocolor: false, 'udp-server': false }
2525 assert @args[1], "no filename given"
2626
27 run: =>
27 setup: =>
2828 if @args.nocolor
2929 Logger\init @args.log
3030 else
3131 ColorLogger\init @args.log
32
33 run: =>
34 @setup!
3235
3336 while true
3437 @tick!
0 ----
1 -- löve Copilot entrypoint.
2 --
3 -- @classmod LoveCopilot
4 import CLICopilot from require 'alv.copilot.cli'
5
6 class LoveCopilot extends CLICopilot
7 new: (arg) =>
8 table.remove arg, 1
9 super arg
10 @drawlist = {}
11
12 update: =>
13 @tick!
14
15 draw: =>
16 for id, list in pairs @drawlist
17 for fn in *list
18 fn!
19
20 run: =>
21 @setup!
22
23 love.draw = @\draw
24 love.update = @\update
25
26 {
27 :LoveCopilot
28 }
0 import Constant, Op, PureOp, Input, T, Struct, sig, evt from require 'alv.base'
1
2 unpack or= table.unpack
3
4 class DrawId
5 new: =>
6
7 draw = Constant.meta
8 meta:
9 name: 'draw'
10 summary: "draw a love/shape shape."
11 examples: { '(love/draw shape)' }
12
13 value: class extends Op
14 new: (...) =>
15 super ...
16 @state or= DrawId!
17
18 pattern = sig['love/shape']*0
19 setup: (inputs, scope) =>
20 shapes = pattern\match inputs
21 super [Input.hot shape for shape in *shapes]
22
23 tick: =>
24 shapes = @unwrap_all!
25 COPILOT.drawlist[@state] = shapes
26
27 destroy: =>
28 COPILOT.drawlist[@state] = nil
29
30 rectangle = Constant.meta
31 meta:
32 name: 'rectangle'
33 summary: "create a rectangle shape."
34 examples: { '(love/rectangle mode w h)' }
35
36 value: class extends PureOp
37 pattern: sig.str + sig.num + sig.num
38 type: T['love/shape']
39
40 tick: =>
41 { mode, w, h } = @unwrap_all!
42 x, y = -w/2, -h/2
43
44 @out\set ->
45 love.graphics.rectangle mode, x, y, w, h
46
47 color = Constant.meta
48 meta:
49 name: 'color'
50 summary: "set color of a shape."
51 examples: { '(love/color r g b [a] shape)' }
52
53 value: class extends PureOp
54 pattern: sig.num\rep(3, 4) + sig['love/shape']
55 type: T['love/shape']
56
57 tick: =>
58 { color, shape } = @unwrap_all!
59 { r, g, b, a } = color
60
61 @out\set ->
62 love.graphics.setColor r, g, b, a
63 shape!
64 love.graphics.setColor 255, 255, 255
65
66 translate = Constant.meta
67 meta:
68 name: 'translate'
69 summary: "translate a shape."
70 examples: { '(love/translate x y hape)' }
71
72 value: class extends PureOp
73 pattern: sig.num + sig.num + sig['love/shape']
74 type: T['love/shape']
75
76 tick: =>
77 { x, y, shape } = @unwrap_all!
78
79 @out\set ->
80 love.graphics.push!
81 love.graphics.translate x, y
82 shape!
83 love.graphics.pop!
84
85 rotate = Constant.meta
86 meta:
87 name: 'rotate'
88 summary: "rotate a shape."
89 examples: { '(love/rotate angle hape)' }
90
91 value: class extends PureOp
92 pattern: sig.num + sig['love/shape']
93 type: T['love/shape']
94
95 tick: =>
96 { angle, shape } = @unwrap_all!
97
98 @out\set ->
99 love.graphics.push!
100 love.graphics.rotate angle
101 shape!
102 love.graphics.pop!
103
104 Constant.meta
105 meta:
106 name: 'love'
107 summary: "LÖVE visuals."
108
109 value:
110 :draw
111
112 :rectangle
113
114 :translate, :rotate
115 :color
0 require('moonscript')
1 local Copilot = require('alv.copilot.love').LoveCopilot
2 Copilot(arg):run()
11 }:
22
33 let
4 # lua = pkgs.lua5_3;
5 # luaPkgs = pkgs.lua53Packages;
6 lua = pkgs.luajit;
7 luaPkgs = pkgs.luajitPackages;
48
5 luarocks-build-cpp = pkgs.lua53Packages.buildLuarocksPackage rec {
9 luarocks-build-cpp = luaPkgs.buildLuarocksPackage rec {
610 pname = "luarocks-build-cpp";
711 version = "0.2.0-1";
812
1721 rev = "v0.2.0";
1822 sha256 = "PamppWdV3cQMDK+t2V09/cNRskGuRNeuyvUODmopLaQ=";
1923 };
20 propagatedBuildInputs = [ pkgs.lua5_3 ];
24 propagatedBuildInputs = [ lua ];
2125
2226 meta = with pkgs.stdenv.lib; {
2327 homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
2630 };
2731 };
2832
29 luarocks-fetch-gitrec = pkgs.lua53Packages.buildLuarocksPackage rec {
33 luarocks-fetch-gitrec = luaPkgs.buildLuarocksPackage rec {
3034 pname = "luarocks-fetch-gitrec";
3135 version = "0.2-2";
3236
3438 url = "mirror://luarocks//${pname}-${version}.src.rock";
3539 sha256 = "Dp3bKIG4swrD4+1NNtRTgyj68Di2cSUlh1r7Z2Rkzn0=";
3640 };
37 propagatedBuildInputs = with pkgs; [ lua5_3 git ];
41 propagatedBuildInputs = with pkgs; [ lua git ];
3842
3943 meta = with pkgs.stdenv.lib; {
4044 homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
4347 };
4448 };
4549
46 fltk4lua = pkgs.lua53Packages.buildLuarocksPackage rec {
50 fltk4lua = luaPkgs.buildLuarocksPackage rec {
4751 pname = "fltk4lua";
4852 version = "0.2-1";
4953
5256 sha256 = "fD31FruqVriMecFcvSV4W7JRia38+bg7j3T5k5pFZec=";
5357 };
5458 buildInputs = with pkgs; [ fltk libjpeg ];
55 propagatedBuildInputs = [ pkgs.lua5_3 luarocks-build-cpp luarocks-fetch-gitrec ];
59 propagatedBuildInputs = [ lua luarocks-build-cpp luarocks-fetch-gitrec ];
5660
5761 meta = with pkgs.stdenv.lib; {
5862 homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
6165 };
6266 };
6367
64 losc = pkgs.lua53Packages.buildLuarocksPackage rec {
68 losc = luaPkgs.buildLuarocksPackage rec {
6569 pname = "losc";
6670 version = "1.0.0-1";
6771
7074 sha256 = "MArhj51V1awF5k2zToFYEXpS2c6o8bnNDn4wLhooHos=";
7175 };
7276 buildInputs = with pkgs; [ stdenv.cc.cc.lib ];
73 propagatedBuildInputs = [ pkgs.lua5_3 ];
77 propagatedBuildInputs = [ lua ];
7478
7579 meta = with pkgs.stdenv.lib; {
7680 homepage = "https://github.com/davidgranstrom/losc";
7983 };
8084 };
8185
82 discount = pkgs.lua53Packages.buildLuarocksPackage {
86 discount = luaPkgs.buildLuarocksPackage {
8387 pname = "discount";
8488 version = "0.4-1";
8589
9498 };
9599
96100 buildInputs = [ pkgs.discount ];
97 propagatedBuildInputs = [ pkgs.lua5_3 ];
101 propagatedBuildInputs = [ lua ];
98102
99103 meta = with pkgs.stdenv.lib; {
100104 homepage = "https://github.com/craigbarnes/lua-discount";
103107 };
104108 };
105109
106 ldoc = pkgs.lua53Packages.buildLuarocksPackage rec {
110 ldoc = luaPkgs.buildLuarocksPackage rec {
107111 pname = "ldoc";
108112 version = "scm-2";
109113
118122 rev = "moonscript";
119123 sha256 = "3jieGp9++cWtLMKccP+xqrtdCiNG/9BYZlHmH1l8XV8=";
120124 };
121 propagatedBuildInputs = with pkgs.lua53Packages; [
122 pkgs.lua5_3 penlight markdown
125 propagatedBuildInputs = with luaPkgs; [
126 lua penlight markdown
123127 ];
124128
125129 meta = with pkgs.stdenv.lib; {
132136 in pkgs.mkShell {
133137 name = "alv-env";
134138 buildInputs = with pkgs; [
135 (lua5_3.withPackages (p: with p; [
139 (lua.withPackages (p: with p; [
136140 moonscript lpeg
137141 luafilesystem luasocket luasystem fltk4lua losc bit32
138142 ldoc busted discount
139143 ]))
144 love_11
140145 ];
141 LUA_PATH = "?.lua;?/init.lua";
146 shellHook = ''
147 echo 'setting paths'
148 source <(
149 LUA_PATH="?.lua;?/init.lua" luajit -e \
150 "print(string.format('export LUA_PATH=%q; export LUA_CPATH=%q', package.path, package.cpath))"
151 )
152 '';
142153 }