aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-05-01 21:10:27 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit0bab32aeb2e8759d7457a8f36415c3c830eb01c4 (patch)
tree47d600e01a84d102eb15cb2042c931dff80beeb1
parentfix missing time/ramp evaltime result (diff)
downloadalive-0bab32aeb2e8759d7457a8f36415c3c830eb01c4.tar.gz
alive-0bab32aeb2e8759d7457a8f36415c3c830eb01c4.zip
add basic love2d support
-rw-r--r--README.md10
-rw-r--r--alv-lib/love.moon116
-rw-r--r--alv/copilot/cli.moon5
-rw-r--r--alv/copilot/love.moon29
-rw-r--r--bin/alv-love/main.lua3
-rw-r--r--shell.nix41
6 files changed, 187 insertions, 17 deletions
diff --git a/README.md b/README.md
index 7e35733..a681e39 100644
--- a/README.md
+++ b/README.md
@@ -35,10 +35,17 @@ The latest documentation is publicly available online at [alv.s-ol.nu][docs].
## starting the copilot
- $ moon init.moon <session.alv>
+ $ bin/alv <session.alv>
For more information see the [getting started guide][guide].
+### LÖVE / visuals
+
+To use the 'love' module for relatime 2d graphics, the copilot needs to be
+started using [love2d][love] (0.11+):
+
+ $ love bin/alv-love <session.alv>
+
## running the tests
The tests use the [busted][busted] Lua unit testing framework. To run all
@@ -61,6 +68,7 @@ development, simply pass the files as arguments:
[busted]: https://olivinelabs.com/busted/
[discount]: https://luarocks.org/modules/craigb/discount
[ldoc]: https://github.com/s-ol/LDoc
+[love]: https://love2d.org/
[docs]: https://alv.s-ol.nu
[guide]: https://alv.s-ol.nu/guide.html
diff --git a/alv-lib/love.moon b/alv-lib/love.moon
new file mode 100644
index 0000000..1523011
--- /dev/null
+++ b/alv-lib/love.moon
@@ -0,0 +1,116 @@
+import Constant, Op, PureOp, Input, T, Struct, sig, evt from require 'alv.base'
+
+unpack or= table.unpack
+
+class DrawId
+ new: =>
+
+draw = Constant.meta
+ meta:
+ name: 'draw'
+ summary: "draw a love/shape shape."
+ examples: { '(love/draw shape)' }
+
+ value: class extends Op
+ new: (...) =>
+ super ...
+ @state or= DrawId!
+
+ pattern = sig['love/shape']*0
+ setup: (inputs, scope) =>
+ shapes = pattern\match inputs
+ super [Input.hot shape for shape in *shapes]
+
+ tick: =>
+ shapes = @unwrap_all!
+ COPILOT.drawlist[@state] = shapes
+
+ destroy: =>
+ COPILOT.drawlist[@state] = nil
+
+rectangle = Constant.meta
+ meta:
+ name: 'rectangle'
+ summary: "create a rectangle shape."
+ examples: { '(love/rectangle mode w h)' }
+
+ value: class extends PureOp
+ pattern: sig.str + sig.num + sig.num
+ type: T['love/shape']
+
+ tick: =>
+ { mode, w, h } = @unwrap_all!
+ x, y = -w/2, -h/2
+
+ @out\set ->
+ love.graphics.rectangle mode, x, y, w, h
+
+color = Constant.meta
+ meta:
+ name: 'color'
+ summary: "set color of a shape."
+ examples: { '(love/color r g b [a] shape)' }
+
+ value: class extends PureOp
+ pattern: sig.num\rep(3, 4) + sig['love/shape']
+ type: T['love/shape']
+
+ tick: =>
+ { color, shape } = @unwrap_all!
+ { r, g, b, a } = color
+
+ @out\set ->
+ love.graphics.setColor r, g, b, a
+ shape!
+ love.graphics.setColor 255, 255, 255
+
+translate = Constant.meta
+ meta:
+ name: 'translate'
+ summary: "translate a shape."
+ examples: { '(love/translate x y hape)' }
+
+ value: class extends PureOp
+ pattern: sig.num + sig.num + sig['love/shape']
+ type: T['love/shape']
+
+ tick: =>
+ { x, y, shape } = @unwrap_all!
+
+ @out\set ->
+ love.graphics.push!
+ love.graphics.translate x, y
+ shape!
+ love.graphics.pop!
+
+rotate = Constant.meta
+ meta:
+ name: 'rotate'
+ summary: "rotate a shape."
+ examples: { '(love/rotate angle hape)' }
+
+ value: class extends PureOp
+ pattern: sig.num + sig['love/shape']
+ type: T['love/shape']
+
+ tick: =>
+ { angle, shape } = @unwrap_all!
+
+ @out\set ->
+ love.graphics.push!
+ love.graphics.rotate angle
+ shape!
+ love.graphics.pop!
+
+Constant.meta
+ meta:
+ name: 'love'
+ summary: "LÖVE visuals."
+
+ value:
+ :draw
+
+ :rectangle
+
+ :translate, :rotate
+ :color
diff --git a/alv/copilot/cli.moon b/alv/copilot/cli.moon
index 14bfd6b..67e8450 100644
--- a/alv/copilot/cli.moon
+++ b/alv/copilot/cli.moon
@@ -25,12 +25,15 @@ class CLICopilot extends Copilot
super parse_args arg, { nocolor: false, 'udp-server': false }
assert @args[1], "no filename given"
- run: =>
+ setup: =>
if @args.nocolor
Logger\init @args.log
else
ColorLogger\init @args.log
+ run: =>
+ @setup!
+
while true
@tick!
sleep 1 / 1000
diff --git a/alv/copilot/love.moon b/alv/copilot/love.moon
new file mode 100644
index 0000000..2a7458f
--- /dev/null
+++ b/alv/copilot/love.moon
@@ -0,0 +1,29 @@
+----
+-- löve Copilot entrypoint.
+--
+-- @classmod LoveCopilot
+import CLICopilot from require 'alv.copilot.cli'
+
+class LoveCopilot extends CLICopilot
+ new: (arg) =>
+ table.remove arg, 1
+ super arg
+ @drawlist = {}
+
+ update: =>
+ @tick!
+
+ draw: =>
+ for id, list in pairs @drawlist
+ for fn in *list
+ fn!
+
+ run: =>
+ @setup!
+
+ love.draw = @\draw
+ love.update = @\update
+
+{
+ :LoveCopilot
+}
diff --git a/bin/alv-love/main.lua b/bin/alv-love/main.lua
new file mode 100644
index 0000000..7b95a26
--- /dev/null
+++ b/bin/alv-love/main.lua
@@ -0,0 +1,3 @@
+require('moonscript')
+local Copilot = require('alv.copilot.love').LoveCopilot
+Copilot(arg):run()
diff --git a/shell.nix b/shell.nix
index 90eff5f..c1f9b1f 100644
--- a/shell.nix
+++ b/shell.nix
@@ -2,8 +2,12 @@
}:
let
+ # lua = pkgs.lua5_3;
+ # luaPkgs = pkgs.lua53Packages;
+ lua = pkgs.luajit;
+ luaPkgs = pkgs.luajitPackages;
- luarocks-build-cpp = pkgs.lua53Packages.buildLuarocksPackage rec {
+ luarocks-build-cpp = luaPkgs.buildLuarocksPackage rec {
pname = "luarocks-build-cpp";
version = "0.2.0-1";
@@ -18,7 +22,7 @@ let
rev = "v0.2.0";
sha256 = "PamppWdV3cQMDK+t2V09/cNRskGuRNeuyvUODmopLaQ=";
};
- propagatedBuildInputs = [ pkgs.lua5_3 ];
+ propagatedBuildInputs = [ lua ];
meta = with pkgs.stdenv.lib; {
homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
@@ -27,7 +31,7 @@ let
};
};
- luarocks-fetch-gitrec = pkgs.lua53Packages.buildLuarocksPackage rec {
+ luarocks-fetch-gitrec = luaPkgs.buildLuarocksPackage rec {
pname = "luarocks-fetch-gitrec";
version = "0.2-2";
@@ -35,7 +39,7 @@ let
url = "mirror://luarocks//${pname}-${version}.src.rock";
sha256 = "Dp3bKIG4swrD4+1NNtRTgyj68Di2cSUlh1r7Z2Rkzn0=";
};
- propagatedBuildInputs = with pkgs; [ lua5_3 git ];
+ propagatedBuildInputs = with pkgs; [ lua git ];
meta = with pkgs.stdenv.lib; {
homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
@@ -44,7 +48,7 @@ let
};
};
- fltk4lua = pkgs.lua53Packages.buildLuarocksPackage rec {
+ fltk4lua = luaPkgs.buildLuarocksPackage rec {
pname = "fltk4lua";
version = "0.2-1";
@@ -53,7 +57,7 @@ let
sha256 = "fD31FruqVriMecFcvSV4W7JRia38+bg7j3T5k5pFZec=";
};
buildInputs = with pkgs; [ fltk libjpeg ];
- propagatedBuildInputs = [ pkgs.lua5_3 luarocks-build-cpp luarocks-fetch-gitrec ];
+ propagatedBuildInputs = [ lua luarocks-build-cpp luarocks-fetch-gitrec ];
meta = with pkgs.stdenv.lib; {
homepage = "https://github.com/siffiejoe/lua-fltk4lua/";
@@ -62,7 +66,7 @@ let
};
};
- losc = pkgs.lua53Packages.buildLuarocksPackage rec {
+ losc = luaPkgs.buildLuarocksPackage rec {
pname = "losc";
version = "1.0.0-1";
@@ -71,7 +75,7 @@ let
sha256 = "MArhj51V1awF5k2zToFYEXpS2c6o8bnNDn4wLhooHos=";
};
buildInputs = with pkgs; [ stdenv.cc.cc.lib ];
- propagatedBuildInputs = [ pkgs.lua5_3 ];
+ propagatedBuildInputs = [ lua ];
meta = with pkgs.stdenv.lib; {
homepage = "https://github.com/davidgranstrom/losc";
@@ -80,7 +84,7 @@ let
};
};
- discount = pkgs.lua53Packages.buildLuarocksPackage {
+ discount = luaPkgs.buildLuarocksPackage {
pname = "discount";
version = "0.4-1";
@@ -95,7 +99,7 @@ let
};
buildInputs = [ pkgs.discount ];
- propagatedBuildInputs = [ pkgs.lua5_3 ];
+ propagatedBuildInputs = [ lua ];
meta = with pkgs.stdenv.lib; {
homepage = "https://github.com/craigbarnes/lua-discount";
@@ -104,7 +108,7 @@ let
};
};
- ldoc = pkgs.lua53Packages.buildLuarocksPackage rec {
+ ldoc = luaPkgs.buildLuarocksPackage rec {
pname = "ldoc";
version = "scm-2";
@@ -119,8 +123,8 @@ let
rev = "moonscript";
sha256 = "3jieGp9++cWtLMKccP+xqrtdCiNG/9BYZlHmH1l8XV8=";
};
- propagatedBuildInputs = with pkgs.lua53Packages; [
- pkgs.lua5_3 penlight markdown
+ propagatedBuildInputs = with luaPkgs; [
+ lua penlight markdown
];
meta = with pkgs.stdenv.lib; {
@@ -133,11 +137,18 @@ let
in pkgs.mkShell {
name = "alv-env";
buildInputs = with pkgs; [
- (lua5_3.withPackages (p: with p; [
+ (lua.withPackages (p: with p; [
moonscript lpeg
luafilesystem luasocket luasystem fltk4lua losc bit32
ldoc busted discount
]))
+ love_11
];
- LUA_PATH = "?.lua;?/init.lua";
+ shellHook = ''
+ echo 'setting paths'
+ source <(
+ LUA_PATH="?.lua;?/init.lua" luajit -e \
+ "print(string.format('export LUA_PATH=%q; export LUA_CPATH=%q', package.path, package.cpath))"
+ )
+ '';
}