slightly better-working SDL integration test, ditch nix

This commit is contained in:
Jeremy Penner 2023-12-11 22:37:17 -05:00
parent 7c931f4cf5
commit 1d6d033e5d
7 changed files with 25 additions and 113 deletions

View file

@ -1,5 +1,5 @@
; todo: can we implement portable logic for finding dynamic libraries?
(terralib.linklibrary "/nix/store/hzfvp1pay5sqq96l20i4ahi7yrajjgfy-SDL2-2.28.4/lib/libSDL2.so")
(terralib.linklibrary "/usr/lib64/libSDL2.so")
(fn load-sdl-headers [headers]
(let [includes (table.concat (icollect [_ h (ipairs headers)]

4
boot.t
View file

@ -10,7 +10,3 @@ _G._3 = nil
debug.traceback = fennel.traceback
table.insert(package.loaders, fennel.searcher)
if rawget(_G, "arg") and arg[0] == "boot.t" then
fennel.repl()
end

View file

@ -1,75 +0,0 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixgl": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1685908677,
"narHash": "sha256-E4zUPEUFyVWjVm45zICaHRpfGepfkE9Z2OECV9HXfA4=",
"owner": "guibou",
"repo": "nixGL",
"rev": "489d6b095ab9d289fe11af0219a9ff00fe87c7c5",
"type": "github"
},
"original": {
"owner": "guibou",
"repo": "nixGL",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1660551188,
"narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1701861573,
"narHash": "sha256-9mZL4N+G/iAADDdR6vKDFwiweYLO8hAmjnDHvfVhYCY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "325eb628b89b9a8183256f62d017bfb499b19bd9",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixgl": "nixgl",
"nixpkgs": "nixpkgs_2"
}
}
},
"root": "root",
"version": 7
}

View file

@ -1,20 +0,0 @@
{
description = "Garden";
inputs = {
nixgl.url = "github:guibou/nixGL";
};
outputs = { self, nixgl, nixpkgs }:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ nixgl.overlay ];
};
in
{
devShells."x86_64-linux".default = pkgs.mkShell {
buildInputs = [ pkgs.terra pkgs.SDL2 pkgs.nixgl.auto.nixGLDefault ];
};
};
}

26
go.fnl
View file

@ -1,19 +1,25 @@
; export LIBGL_ALWAYS_INDIRECT=1
; LIBGL_ALWAYS_INDIRECT=1
(local fennel (require :fennel))
(import-macros {: def : q : ttype : static : printform} :terra)
(import-macros {: def : q : ttype : static : eval : printform} :terra)
(local SDL (require :SDL))
(local CreateWindowAndRenderer (printform (def [w int h int flags uint32]
(local CreateWindowAndRenderer (def [w int h int flags uint32]
(var window [SDL.Window] nil)
(var renderer [SDL.Renderer] nil)
(var result (SDL.CreateWindowAndRenderer w h flags (& window) (& renderer)))
(return result window renderer))))
(return result window renderer)))
(fn rect [x y w h]
(SDL.Rect {: x : y : w : h}))
(local last-event (printform (static SDL.Event (q (SDL.Event {type 0})))))
(fn event-loop [f]
(while (not= (SDL.PollEvent (last-event:getpointer)) 0) (f (last-event:get))))
(local rect (def [x int y int w int h int]
(return (SDL.Rect {x x y y w w h h}))))
(SDL.Init SDL.INIT_EVERYTHING)
(let [windowflags SDL.WINDOW_RESIZABLE ;(bit.bor SDL.WINDOW_RESIZABLE SDL.WINDOW_OPENGL)
(window renderer) (CreateWindowAndRenderer 640 480 windowflags)]
(SDL.RenderFillRect renderer (rect 0 0 640 480))
{: window : renderer})
(let [windowflags SDL.WINDOW_RESIZABLE
(ok window renderer) (unpacktuple (CreateWindowAndRenderer 640 480 windowflags))]
(SDL.SetRenderDrawColor renderer 0 0 0 255)
(SDL.RenderClear renderer)
(SDL.RenderPresent renderer)
{: window : renderer : rect : event-loop})

4
repl.t Normal file
View file

@ -0,0 +1,4 @@
require "boot"
local fennel = require "fennel"
fennel.repl()

View file

@ -45,7 +45,7 @@
(where l (list? l)) (extract.quotes-in-table (list) l inputs locals)
(where s (sequence? s)) (extract.quotes-in-table (sequence) s inputs locals)
(where t (kv-table? t)) (extract.quotes-in-table {} t inputs locals)
(where t (kv-table? t)) (extract.quotes-in-table (setmetatable {} (getmetatable t)) t inputs locals)
_ form))
@ -261,7 +261,7 @@
(indent :end scope)))))
(fn comp.global [[typ initial-val] scope]
(.. "global(" (comp.type typ scope) "," (comp.expr initial-val scope) ")"))
(.. "global(" (comp.type typ scope) "," (scope:expr initial-val) ")"))
(fn build [expr compiler]
(let [scope (new-scope)
@ -277,6 +277,7 @@
(fn tquote [...] (build [...] comp.quote))
(fn def [...] (build [...] comp.def))
(fn static [typ initial-value] (build [typ initial-value] comp.global))
(fn eval [expr] `(,(def `[] `(return ,expr))))
(fn compile [compiler-name expr] (build expr (. comp (tostring compiler-name))))
(fn uncompile [compiler-name expr]
@ -286,4 +287,4 @@
(fn printform [form] `(do (print ,(view (macroexpand form))) ,form))
{: ttype :q tquote : def : static : compile : uncompile : printform}
{: ttype :q tquote : def : static : eval : compile : uncompile : printform}