Commit 16533e06 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Code a layer of scheme above the bindings

parent d4de7b6e
......@@ -2,6 +2,7 @@
.dir-locals.el
/**/*.def
/**/*.gir
/**/*.go
/**/*.la
/**/*.lo
/**/*.log
......
......@@ -66,7 +66,7 @@ AM_CFLAGS += $(GOBJECT_CFLAGS)
AM_LDADD += $(GOBJECT_LIBS)
endif # WITH_GOBJECT
PRIO_1 = lib/libgnu.la
PRIO_1 = lib/libgnu.la src/libtarot/guile/tarot/config.scm
PRIO_2 = eu.planete_kraus.Tarot.appdata.xml.in releases.xml
PRIO_3 = src/libtarot/cards/tarot/cards_defs.h \
src/libtarot/cards/tarot/cards_private_impl.h \
......
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tarot 0.4.2.83-ebdc-dirty\n"
"Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n"
"POT-Creation-Date: 2019-10-26 19:22+0200\n"
"POT-Creation-Date: 2019-11-01 18:01+0100\n"
"PO-Revision-Date: 2019-10-12 11:34+0200\n"
"Last-Translator: Vivien Kraus <vivien@planete-kraus.eu>\n"
"Language-Team: French\n"
......
......@@ -30,10 +30,12 @@ EXTRA_DIST += %reldir%/test_guile.c %reldir%/tarot/config.scm.in
> %reldir%/tarot/config.scm-t
@mv %reldir%/tarot/config.scm-t %reldir%/tarot/config.scm
CLEANFILES += %reldir%/tarot/config.scm %reldir%/tarot/config.go
CLEANFILES += %reldir%/tarot/config.scm
moddir=$(datadir)/guile/site/$(GUILE_EFFECTIVE_VERSION)
godir=$(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache
tarotmoddir=$(moddir)/tarot
tarotgodir=$(godir)/tarot
dist_mod_DATA =
go_DATA =
......@@ -51,10 +53,11 @@ $(guile_install_go_files): install-dist_modDATA
guile_install_tarotgo_files = install-tarotgoDATA
$(guile_install_tarotgo_files): install-dist_tarotmodDATA install-tarotmodDATA
CLEANFILES = $(GOBJECTS)
CLEANFILES += $(go_DATA) $(tarotgo_DATA)
GUILE_WARNINGS = -Wunbound-variable -Warity-mismatch -Wformat
SUFFIXES += .scm .go
.scm.go:
$(MAKE) $(AM_MAKEFLAGS) %reldir%/tarot/config.scm
$(AM_V_GEN)$(top_builddir)/pre-inst-env $(GUILD) compile $(GUILE_WARNINGS) -o "$@" "$<"
if HAVE_GUILE
......
;; tarot implements the rules of the tarot game
;; Copyright (C) 2019 Vivien Kraus
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, version 3 of the License.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (tarot)
#:export (libtarot-version
ace jack knight queen king petit twentyone excuse
of decompose
string->card string->card/c card-parse card-parse/c
card->string card->string/c))
(use-modules (tarot config) (rnrs bytevectors) (ice-9 optargs))
(define tarot-lib (dynamic-link "libtarot-guile.so"))
(dynamic-call "tarot_guile_init" tarot-lib)
(define (init)
(let ((datadir (string->utf8 absolute-datadir))
(localedir (string->utf8 absolute-localedir)))
(tarot-set-datadir datadir)
(if (not (eq? (tarot-init localedir) 0))
(error "Could not initialize libtarot."))))
(init)
(define (libtarot-version)
(utf8->string (tarot-libtarot-version)))
(define ace 1)
(define jack 11)
(define knight 12)
(define queen 13)
(define king 14)
(define petit 56)
(define twentyone 76)
(define excuse 77)
(define (input-card what)
(cond ((eq? what 'petit) petit)
((eq? what 'twentyone) twentyone)
((eq? what 'excuse) excuse)
(else what)))
(define (input-number what)
(cond ((eq? what 'ace) ace)
((eq? what 'jack) jack)
((eq? what 'knight) knight)
((eq? what 'queen) queen)
((eq? what 'king) king)
(else what)))
(define (of number suit)
(let ((ret (tarot-of (input-number number) suit)))
(if (eq? (car ret) 0)
(cadr ret)
#f)))
(define (decompose card)
(let ((ret (tarot-decompose (input-card card))))
(if (eq? (car ret) 0)
(cdr ret)
#f)))
(define (string->card str)
(let ((ret (tarot-string-to-card (string->utf8 str))))
(if (eq? ret -1)
#f
ret)))
(define (string->card/c str)
(let ((ret (tarot-string-to-card-c (string->utf8 str))))
(if (eq? ret -1)
#f
ret)))
(define (card-parse str)
(let ((ret (tarot-card-parse (string->utf8 str))))
(let ((parsed (if (>= (car ret) 78) #f (car ret)))
(remaining (utf8->string (cadr ret))))
(list parsed remaining))))
(define (card-parse/c str)
(let ((ret (tarot-card-parse-c (string->utf8 str))))
(let ((parsed (if (>= (car ret) 78) #f (car ret)))
(remaining (utf8->string (cadr ret))))
(list parsed remaining))))
(define (card->string card)
(utf8->string (tarot-card-to-string-alloc (input-card card))))
(define (card->string/c card)
(utf8->string (tarot-card-to-string-c-alloc (input-card card))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment