Just to let you know, the (read-headers) seems to do the trick! I guess I had oversimplified...
Thanks very much for looking at it!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
; SDL_ttf.lsp
; jrlf 2007-09-13
; Library import for SDL_ttf 2.0.9
; The SDL_ttf library is distributed under the terms of the GNU LGPL license:
; http://www.gnu.org/copyleft/lesser.html
; The library source is available from the libraries page at the SDL website:
; http://www.libsdl.org/
; To be used in conjunction with SDL.lsp.
(context 'TTF)
# Determine which library to use first.
(if (= (last (sys-info)) 6)
(constant 'library (string MAIN:LIBPATH "SDL_ttf.dll"))
(constant 'library "????.so.0") ; I don't know what the Linux one is.
)
(define-macro (provide)
(dolist (_symbol (args))
(constant _symbol (import library (string "TTF_" _symbol))))
)
; Constants.
(constant 'UNICODE_BOM_NATIVE 0xfeff
'UNICODE_BOM_SWAPPED 0xfffe
'STYLE_NORMAL 0x00
'STYLE_BOLD 0x01
'STYLE_ITALIC 0x02
'STYLE_UNDERLINE 0x04
)
; Functions.
; extern DECLSPEC void SDLCALL TTF_ByteSwappedUNICODE(int swapped);
(provide ByteSwappedUNICODE)
; extern DECLSPEC int SDLCALL TTF_Init(void);
(provide Init)
; extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize);
; extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index);
; extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize);
; extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index);
(provide OpenFont)
(provide OpenFontIndex)
(provide OpenFontRW)
(provide OpenFontIndexRW)
; extern DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font);
; extern DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style);
(provide GetFontStyle)
(provide SetFontStyle)
; extern DECLSPEC int SDLCALL TTF_FontHeight(const TTF_Font *font);
(provide FontHeight)
; extern DECLSPEC int SDLCALL TTF_FontAscent(const TTF_Font *font);
(provide FontAscent)
; extern DECLSPEC int SDLCALL TTF_FontLineSkip(const TTF_Font *font);
(provide FontLineSkip)
; extern DECLSPEC long SDLCALL TTF_FontFaces(const TTF_Font *font);
(provide FontFaces)
; extern DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(const TTF_Font *font);
; extern DECLSPEC char * SDLCALL TTF_FontFaceFamilyName(const TTF_Font *font);
; extern DECLSPEC char * SDLCALL TTF_FontFaceStyleName(const TTF_Font *font);
(provide FontFaceIsFixedWidth
FontFaceFamilyName
FontFaceStyleName)
; See http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
; extern DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
; int *minx, int *maxx, int *miny, int *maxy, int *advance);
(provide GlyphMetrics)
; extern DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h);
; extern DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
; extern DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h);
(provide SizeText
SizeUTF8
SizeUNICODE)
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font,
; const char *text, SDL_Color fg);
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font,
; const char *text, SDL_Color fg);
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font,
; const Uint16 *text, SDL_Color fg);
(provide RenderText_Solid
RenderUTF8_Solid
RenderUNICODE_Solid)
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font,
; Uint16 ch, SDL_Color fg);
(provide RenderGlyph_Solid)
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font,
; const char *text, SDL_Color fg, SDL_Color bg);
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Shaded(TTF_Font *font,
; const char *text, SDL_Color fg, SDL_Color bg);
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Shaded(TTF_Font *font,
; const Uint16 *text, SDL_Color fg, SDL_Color bg);
(provide RenderText_Shaded
RenderUTF8_Shaded
RenderUNICODE_Shaded)
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font,
; Uint16 ch, SDL_Color fg, SDL_Color bg);
(provide RenderGlyph_Shaded)
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font,
; const char *text, SDL_Color fg);
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font,
; const char *text, SDL_Color fg);
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended(TTF_Font *font,
; const Uint16 *text, SDL_Color fg);
(provide RenderText_Blended
RenderUTF8_Blended
RenderUNICODE_Blended)
; extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font,
; Uint16 ch, SDL_Color fg);
(provide RenderGlyph_Blended)
; #define TTF_RenderText(font, text, fg, bg)
; TTF_RenderText_Shaded(font, text, fg, bg)
; #define TTF_RenderUTF8(font, text, fg, bg)
; TTF_RenderUTF8_Shaded(font, text, fg, bg)
; #define TTF_RenderUNICODE(font, text, fg, bg)
; TTF_RenderUNICODE_Shaded(font, text, fg, bg)
(define (RenderText font text fg bg) (RenderText_Shaded font text fg bg))
(define (RenderUTF8 font text fg bg) (RenderUTF8_Shaded font text fg bg))
(define (RenderUNICODE font text fg bg) (RenderUNICODE_Shaded font text fg bg))
; extern DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font);
(provide CloseFont)
; extern DECLSPEC void SDLCALL TTF_Quit(void);
(provide Quit)
; extern DECLSPEC int SDLCALL TTF_WasInit(void);
(provide WasInit)
; XXX It is possible that these won't work right. Need to check.
(constant 'SetError SDL:SDL_SetError)
(constant 'GetError SDL:SDL_GetError)
I tested your http-conf.lsp on Win32. To make it work you have to add a (read-headers) routine to clear out the headers coming from the client browser.Quote from: "Lutz"
I don't see how your (send text) function can return nil. It will return, what the (print text) statement evaluates too, which is the last thing printed, which is text not nil.Quote
(define (httpd-conf path query)
(if (= 0 (length path))
(begin
(setq text "This is some text.")
(print "HTTP/1.0 200 OKrn")
(print (format "Server: newLISP v.%d (%s)rn" (sys-info -1) ostype))
(print "Content-type: text/plainrnrn")
(print text)
nil)
(begin
(println "Path is " path)
path)
)
)
(define (httpd-conf path query)
(println path ":" query) ; Delete this line to see anything on IE.
(if (= 0 (length path))
(begin
(set 'page (send (template "This is a simple test.")))
(println "Page is " page)
page)
(begin
(println "Path is " path)
path)
)
)
:
HTTP/1.0 200 OK
Server: newLISP v.6 (Win32)
Content-length: 169
Content-type: text/html
<DOCTYPE>
<html>
<head>
<title>Test</title>
</head>
<body>
This is a simple test.
</body>
</html>
HTTP/1.0 200 OK
Server: newLISP v.6 (Win32)
Content-length: 0
Content-type: text/html
nilPage is nil
(define (send text)
(print "HTTP/1.0 200 OKrn")
(print (format "Server: newLISP v.%d (%s)rn" (sys-info -1) ostype))
(print (format "Content-length: %drn" (length text)))
(print "Content-type: text/htmlrnrn")
(print text))
(define (template text)
"( text -- nil) Print out filled in template."
(send (replace "%content%" (read-file "default.html") text))
nil ; As specified in CodePatterns.html#distributed
)
(define (httpd-conf path query)
(if (= 0 (length path)) (app:home)
path
)
)
; SDL_image.lsp
; jrlf 2007-08-12
; Library import for SDL_image 1.2.6.
; See http://www.libsdl.org/projects/SDL_image/.
; To be used in conjunction with SDL.lsp.
(context 'IMG)
# Determine which library to use first.
(if (= (last (sys-info)) 6)
(constant 'library "SDL_image.dll")
(constant 'library "????.so.0") ; I don't know what the Linux one is.
)
(define-macro (provide _symbol)
(let ((truename (string "IMG_" _symbol)))
(import library truename)
(constant _symbol (eval (sym truename))))
)
; Functions.
(provide LoadTyped_RW)
(provide Load)
(provide Load_RW)
(provide isBMP)
(provide isGIF)
(provide isJPG)
(provide isLBM)
(provide isPCX)
(provide isPNG)
(provide isPNM)
(provide isTIF)
(provide isXCF)
(provide isXPM)
(provide isXV)
; XXX Not including individual loading functions for simplicity.
; It is possible that these won't work right. Need to check.
(constant 'SetError SDL:SDL_SetError)
(constant 'GetError SDL:SDL_GetError)
(context 'MAIN)
(define (apply_surface x y from to)
(letn ((info (unpack "lu lu lu lu" from))
(width (info 2))
(height (info 3)))
(println "Image size is " width "x" height)
(SDL:SDL_BlitSurface
; from (pack "d d u u" 0 0 width height) ; This works, but too explicit.
from 0 ; This works like the C++ examples.
to (pack "d d u u" x y width height))
)
)
(context 'SDL)
(define (SDL_LoadBMP filename)
(SDL_LoadBMP_RW (SDL_RWFromFile filename "rb") 1))
(define (SDL_SaveBMP surface filename)
(SDL_SaveBMP_RW surface (SDL_RWFromFile filename "wb") 1))
(define (SDL_BlitSurface src srcrect dst dstrect)
(SDL_UpperBlit src srcrect dst dstrect))
(context 'MAIN)
(setq info (unpack "lu lu lu lu" testi))
(println "Image size is " (info 2) "x" (info 3))
; l002.lsp
; jrlf 2007-08-10
; Surface loading and blitting.
; http://lazyfoo.net/SDL_tutorials/lesson02/index.php
; Load SDL library.
(load "SDL.lsp")
(context 'SDL)
(define (SDL_LoadBMP filename)
(SDL:SDL_LoadBMP_RW (SDL:SDL_RWFromFile filename "rb") 1))
(define (SDL_BlitSurface src srcrect dst dstrect)
(SDL_UpperBlit src srcrect dst dstrect))
(context 'MAIN)
; Screen attributes.
(constant 'screen_width 640)
(constant 'screen_height 480)
(constant 'screen_bpp 32)
(define (load_image filename)
(let ((loaded (SDL:SDL_LoadBMP filename))
(optimized nil))
(if loaded (begin
(setq optimized (SDL:SDL_DisplayFormat loaded))
(SDL:SDL_FreeSurface loaded)
))
optimized))
(define (apply_surface x y from to)
(letn ((info (unpack "lu lu lu lu" from))
(width (info 2))
(height (info 3)))
(println "Image size is " width "x" height)
(SDL:SDL_BlitSurface from nil to (pack "u u lu lu" x y width height))
)
)
(if (< (SDL:SDL_Init SDL:SDL_INIT_EVERYTHING) 0)
(begin (println "Could not initialize SDL!") (exit)))
(if (< (setq screen (SDL:SDL_SetVideoMode screen_width screen_height
screen_bpp SDL:SDL_SWSURFACE)) 0)
(begin (println "Couldn't initialize the screen!") (exit)))
(SDL:SDL_WM_SetCaption "Hello World" "")
(setq message (load_image "hello_world.bmp")
background (load_image "background.bmp")
)
(apply_surface 0 0 background screen)
(apply_surface 180 140 message screen)
(if (< (SDL:SDL_Flip screen) 0)
(begin
(println "Couldn't flip screen!") (exit)))
(SDL:SDL_Delay 2000)
(SDL:SDL_FreeSurface message)
(SDL:SDL_FreeSurface background)
(SDL:SDL_Quit)
(exit)
(define (apply_surface x y from to)
(SDL:SDL_BlitSurface from nil to (pack "u u lu lu" x y 200 200))
)
; l002.lsp
; jrlf 2007-08-10
; Surface loading and blitting.
; http://lazyfoo.net/SDL_tutorials/lesson02/index.php
; Load SDL library.
(load "SDL.lsp")
(context 'SDL)
(define (SDL_LoadBMP filename)
(SDL:SDL_LoadBMP_RW (SDL:SDL_RWFromFile filename "rb") 1))
(define (SDL_BlitSurface src srcrect dst dstrect)
(SDL_UpperBlit src srcrect dst dstrect))
(context 'MAIN)
; Screen attributes.
(constant 'screen_width 640)
(constant 'screen_height 480)
(constant 'screen_bpp 32)
(define (load_image filename)
(let ((loaded (SDL:SDL_LoadBMP filename))
(optimized nil))
(if loaded (begin
(setq optimized (SDL:SDL_DisplayFormat loaded))
(SDL:SDL_FreeSurface loaded)
))
optimized))
(define (apply_surface x y from to)
(SDL:SDL_BlitSurface from "" to (pack "u u lu lu" x y 0 0))
)
(if (< (SDL:SDL_Init SDL:SDL_INIT_EVERYTHING) 0)
(begin (println "Could not initialize SDL!") (exit)))
(if (< (setq screen (SDL:SDL_SetVideoMode screen_width screen_height
screen_bpp SDL:SDL_SWSURFACE)) 0)
(begin (println "Couldn't initialize the screen!") (exit)))
(SDL:SDL_WM_SetCaption "Hello World" "")
(setq message (load_image "hello_world.bmp")
background (load_image "background.bmp")
)
(apply_surface 0 0 background screen)
(apply_surface 180 140 message screen)
(if (< (SDL:SDL_Flip screen) 0)
(begin
(println "Couldn't flip screen!") (exit)))
(SDL:SDL_Delay 2000)
(SDL:SDL_FreeSurface message)
(SDL:SDL_FreeSurface background)
(SDL:SDL_Quit)
(exit)
Radius of s is 1.
context expected in function new : nil
called from user defined function go