slightly better-working SDL integration test, ditch nix
This commit is contained in:
parent
7c931f4cf5
commit
1d6d033e5d
2
SDL.fnl
2
SDL.fnl
|
@ -1,5 +1,5 @@
|
||||||
; todo: can we implement portable logic for finding dynamic libraries?
|
; 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]
|
(fn load-sdl-headers [headers]
|
||||||
(let [includes (table.concat (icollect [_ h (ipairs headers)]
|
(let [includes (table.concat (icollect [_ h (ipairs headers)]
|
||||||
|
|
4
boot.t
4
boot.t
|
@ -10,7 +10,3 @@ _G._3 = nil
|
||||||
|
|
||||||
debug.traceback = fennel.traceback
|
debug.traceback = fennel.traceback
|
||||||
table.insert(package.loaders, fennel.searcher)
|
table.insert(package.loaders, fennel.searcher)
|
||||||
|
|
||||||
if rawget(_G, "arg") and arg[0] == "boot.t" then
|
|
||||||
fennel.repl()
|
|
||||||
end
|
|
||||||
|
|
75
flake.lock
75
flake.lock
|
@ -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
|
|
||||||
}
|
|
20
flake.nix
20
flake.nix
|
@ -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
26
go.fnl
|
@ -1,19 +1,25 @@
|
||||||
; export LIBGL_ALWAYS_INDIRECT=1
|
; LIBGL_ALWAYS_INDIRECT=1
|
||||||
(local fennel (require :fennel))
|
(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 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 window [SDL.Window] nil)
|
||||||
(var renderer [SDL.Renderer] nil)
|
(var renderer [SDL.Renderer] nil)
|
||||||
(var result (SDL.CreateWindowAndRenderer w h flags (& window) (& renderer)))
|
(var result (SDL.CreateWindowAndRenderer w h flags (& window) (& renderer)))
|
||||||
(return result window renderer))))
|
(return result window renderer)))
|
||||||
|
|
||||||
(fn rect [x y w h]
|
(local last-event (printform (static SDL.Event (q (SDL.Event {type 0})))))
|
||||||
(SDL.Rect {: x : y : w : h}))
|
(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)
|
(SDL.Init SDL.INIT_EVERYTHING)
|
||||||
(let [windowflags SDL.WINDOW_RESIZABLE ;(bit.bor SDL.WINDOW_RESIZABLE SDL.WINDOW_OPENGL)
|
(let [windowflags SDL.WINDOW_RESIZABLE
|
||||||
(window renderer) (CreateWindowAndRenderer 640 480 windowflags)]
|
(ok window renderer) (unpacktuple (CreateWindowAndRenderer 640 480 windowflags))]
|
||||||
(SDL.RenderFillRect renderer (rect 0 0 640 480))
|
(SDL.SetRenderDrawColor renderer 0 0 0 255)
|
||||||
{: window : renderer})
|
(SDL.RenderClear renderer)
|
||||||
|
(SDL.RenderPresent renderer)
|
||||||
|
{: window : renderer : rect : event-loop})
|
||||||
|
|
4
repl.t
Normal file
4
repl.t
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
require "boot"
|
||||||
|
local fennel = require "fennel"
|
||||||
|
|
||||||
|
fennel.repl()
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
(where l (list? l)) (extract.quotes-in-table (list) l inputs locals)
|
(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 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))
|
_ form))
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@
|
||||||
(indent :end scope)))))
|
(indent :end scope)))))
|
||||||
|
|
||||||
(fn comp.global [[typ initial-val] 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]
|
(fn build [expr compiler]
|
||||||
(let [scope (new-scope)
|
(let [scope (new-scope)
|
||||||
|
@ -277,6 +277,7 @@
|
||||||
(fn tquote [...] (build [...] comp.quote))
|
(fn tquote [...] (build [...] comp.quote))
|
||||||
(fn def [...] (build [...] comp.def))
|
(fn def [...] (build [...] comp.def))
|
||||||
(fn static [typ initial-value] (build [typ initial-value] comp.global))
|
(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 compile [compiler-name expr] (build expr (. comp (tostring compiler-name))))
|
||||||
(fn uncompile [compiler-name expr]
|
(fn uncompile [compiler-name expr]
|
||||||
|
@ -286,4 +287,4 @@
|
||||||
|
|
||||||
(fn printform [form] `(do (print ,(view (macroexpand form))) ,form))
|
(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}
|
||||||
|
|
Loading…
Reference in a new issue