From: Javier Sancho Date: Wed, 5 Jun 2013 09:22:33 +0000 (+0200) Subject: Component definitions support using Guile records X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=08ad446e3685f481d5c6225ff294e18eb305cedf;p=gacela.git Component definitions support using Guile records * src/system.scm: define-component get-component-type --- diff --git a/src/system.scm b/src/system.scm new file mode 100644 index 0000000..b4f4870 --- /dev/null +++ b/src/system.scm @@ -0,0 +1,47 @@ +;;; Gacela, a GNU Guile extension for fast games development +;;; Copyright (C) 2013 by Javier Sancho Fernandez +;;; +;;; 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, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; 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 . + + +(define-module (gacela system) + #:use-module (srfi srfi-9)) + + +;;; Component definitions + +(define (make-symbol . args) + (string->symbol + (string-concatenate + (map (lambda (a) (if (symbol? a) (symbol->string a) a)) args)))) + +(define-macro (define-component name . args) + `(begin + (use-modules (srfi srfi-9) (srfi srfi-9 gnu)) + (define-record-type ,name + (,(make-symbol "make-" name) ,@args) + ,(make-symbol name "?") + ,@(map (lambda (a) (list a (make-symbol name "-" a) (make-symbol "set-" name "-" a "!"))) args)) + (set-record-type-printer! ,name + (lambda (record port) + (format port "#<[~a]" ',name) + ,@(map (lambda (a) `(format port " ~a: ~a" ',a (,(make-symbol name "-" a) record))) args) + (format port ">"))) + ',name)) + +(define (get-component-type component) + (record-type-name (record-type-descriptor component))) + +(export define-component + get-component-type)