This commit is contained in:
Dane Johnson 2024-10-10 18:16:13 -05:00
commit 3657b8de60
11 changed files with 118 additions and 0 deletions

0
.gitignore vendored Normal file
View File

6
demo.scm Normal file
View File

@ -0,0 +1,6 @@
(use-modules (petri)
(agar gui))
(petri-app
(let ([window (make-window)])
(show-window window)))

21
guile-agar/Makefile Normal file
View File

@ -0,0 +1,21 @@
CFLAGS:=`pkg-config --cflags guile-3.0 agar` -I./include/
LDLIBS:=`pkg-config --libs guile-3.0 agar`
SRCS:=$(wildcard src/*.c)
OBJS:=$(SRCS:.c=.o)
SCMS:=$(patsubst src/%.o,scm/agar/%.scm,$(OBJS))
OBJS+=$(patsubst scm/agar/%.scm,scm/agar_%_wrap.o,$(SCMS))
.PHONY: driver
all: libguileagar.so $(SCMS)
clean:
rm -rf libguileagar.so $(SCMS) $(OBJS) $(WRAPS)
libguileagar.so: $(OBJS)
$(CC) -shared -fPIC -o $@ $^ $(LDLIBS)
scm/agar/%.scm scm/agar_%_wrap.c: scm/%.i include/%.h
swig -I./include -guile -Linkage module -scmstub -package agar -o scm/agar_$*_wrap.c scm/$*.i
driver:
GUILE_EXTENSIONS_PATH=. guile -L scm driver.scm

12
guile-agar/driver.scm Normal file
View File

@ -0,0 +1,12 @@
(use-modules (agar core))
(use-modules (agar gui))
(init-core)
(init-gui)
(define my-window (make-window))
(define my-label (make-label my-window))
(set-label-text my-label "Hi Agar")
(show-window my-window)
(event-loop)

View File

@ -0,0 +1,9 @@
#ifndef __CORE_H__
#define __CORE_H_
#include <agar/core.h>
void init_core();
void event_loop();
#endif // __CORE_H__

15
guile-agar/include/gui.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __GUI_H__
#define __GUI_H__
#include <agar/core.h>
#include <agar/gui.h>
void init_gui();
AG_Window* make_window();
void show_window(AG_Window*);
AG_Label* make_label(void* parent);
void set_label_text(AG_Label* label, const char* text);
#endif // __GUI_H__

6
guile-agar/scm/core.i Normal file
View File

@ -0,0 +1,6 @@
%module core
%scheme %{(load-extension "libguileagar" "scm_init_agar_core_module")%}
%{
#include <core.h>
%}
%include "core.h"

7
guile-agar/scm/gui.i Normal file
View File

@ -0,0 +1,7 @@
%module gui
%scheme %{(load-extension "libguileagar" "scm_init_agar_gui_module")%}
%{
#include <gui.h>
%}
%include "gui.h"

9
guile-agar/src/core.c Normal file
View File

@ -0,0 +1,9 @@
#include <core.h>
void init_core() {
AG_InitCore("agar", 0);
}
void event_loop() {
AG_EventLoop();
}

22
guile-agar/src/gui.c Normal file
View File

@ -0,0 +1,22 @@
#include <gui.h>
void init_gui() {
AG_InitGraphics(0);
}
AG_Window *make_window() {
return AG_WindowNew(AG_WINDOW_MAIN);
}
void show_window(AG_Window *win) {
AG_WindowShow(win);
}
AG_Label* make_label(void* parent) {
return AG_LabelNew(parent, 0, "");
}
void set_label_text(AG_Label* label, const char* text) {
AG_LabelText(label, text);
}

11
petri.scm Normal file
View File

@ -0,0 +1,11 @@
(define-module (petri)
:use-module (agar core)
:use-module (agar gui)
:export (petri-app))
(define-syntax-rule (petri-app exp ...)
(begin
(init-core)
(init-gui)
exp ...
(event-loop)))