Show Posts
Pages: [1]
1  The Doryen Projects / General discussion / Re: [Ann] CL-TCOD: Common Lisp bindings for libtcod on: February 14, 2009, 03:35:55 AM
Thanks! Including the wrapping code would make it less daunting for people to use. I also noticed some of the wrapper functions already have very similar python equivalents.

It's compatible with 1.4.1rc2 -- I just updated it this morning, prior to release.

I need to include an explanation in the readme regarding how colours are handled, but basically they are converted to and from 3-byte integers using functions int_to_color(int) and color_to_int(TCOD_color_t). Bytes are reg, green and blue in order (blue is 1's). ie:

struct TCOD_color_t {r, g, b}  <==>  0xRRGGBB

All C functions that take or return TCOD_color_t structs, are wrapped by lisp functions that take or return integers as described above.

Paul Sexton

2  The Doryen Projects / General discussion / [Ann] CL-TCOD: Common Lisp bindings for libtcod on: February 14, 2009, 12:57:37 AM
Hi,
I have written a library allowing libtcod to be used with Common Lisp. The source code repository is at:

http://bitbucket.org/moriarty4/cl-tcod/

The readme file is pasted below.

Thanks for your excellent library.

Paul

---readme file follows---

This is CL-TCOD, an interface between Common Lisp and the Doryen Library
("libtcod"), a portable truecolour console library intended for use with
roguelike games.

It consists of 2 parts:

1. TCOD.LISP, a lisp file which creates lisp bindings for C functions in the
   compiled libtcod library.  This is accompanied by TCOD.ASD, which (to be
   brief!) allows TCOD to be easily loaded and used as a library by other
   common lisp programs.
   
2. wrappers.c and wrappers.h. These are C files, and need to be added to the
   sources for libtcod so that CL-TCOD can use the library. The reason this is
   necessary is that some libtcod functions pass structures around as arguments
   and return values, which common lisp (and a lot of other programming
   languages that might want to interface with a C library) has great
   difficulty dealing with. The wrapper C code converts these structures into
   pointers to structures, which lisp can deal with more readily.

CL-TCOD has been tested with SBCL 1.0.22, CLISP 2.44, and Clozure 1.3 on
Linux. It should work on any common lisp implementation where CFFI works.


=========
Resources
=========

The latest version of CL-TCOD is available at:

    http://bitbucket.org/moriarty4/cl-tcod/

The latest version of libtcod is available at:

    http://jice.nospam.googlepages.com/thedoryenlibrary

This Common Lisp package depends on CFFI, the Common Foreign Function Interface:

    http://common-lisp.net/project/cffi/

A system definition file for use with ASDF is provided (tcod.asd), although it
is easy enough to simply load tcod.lisp if you are not using ASDF.


=======
Licence
=======

The CL-TCOD package is placed in the Public Domain by its authors.


======
Usage
======

You need to know your way around your chosen common lisp and how to install and
load lisp libraries before proceeding. You also need to have a working C
compiler, because you will need to recompile libtcod.

1. Ensure you have a working common lisp installation.
2. Ensure the ASDF lisp library is installed.
3. Put the CL-TCOD files in a directory where ASDF can find them.
4. Install CFFI (see above), also putting it somewhere ASDF can find it.
5. Put wrappers.c in the src/ directory of the libtcod sources.
6. Put wrappers.h in the include/ directory of the libtcod sources.
7. Open the makefile you will be using to compile libtcod (eg "makefile-linux").
   Under the heading "LIBOBJS_C=\", add this line:

   $(TEMP)/libtcod/wrappers.o \

(Make sure the whitespace at the beginning of the line is tabs, NOT spaces.)
8. Compile libtcod, and put the resulting dynamically linked library (.DLL or
.SO file) somewhere your lisp system can find it. Example commands under linux:

  make -f makefile linux
  sudo cp libtcod*.so /usr/local/lib/

9. Start lisp. Load ASDF, CFFI, and then CL-TCOD:

  (asdf:oos 'asdf:load-op :tcod)

10. Type something like the following at the lisp prompt to start using TCOD
from within Lisp:

  (tcod:console-set-custom-font "myfont.bmp" :font-layout-ascii-in-row 16 16)
  (tcod:console-init-root 80 25 "Test" nil)
  (tcod:console-clear tcod:*root*)
  (tcod:console-print-left tcod:*root* 1 1 :set "Hello, world!~%")
  (tcod:console-flush)








Pages: [1]