diff src/lua/lzio.h @ 11:27763b933818

raise lua sources up one level
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 11:07:39 -0600
parents src/lua/src/lzio.h@f9f4f1b99eed
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/lua/lzio.h	Sat Mar 03 11:07:39 2012 -0600
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 +** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
     1.6 +** Buffered streams
     1.7 +** See Copyright Notice in lua.h
     1.8 +*/
     1.9 +
    1.10 +
    1.11 +#ifndef lzio_h
    1.12 +#define lzio_h
    1.13 +
    1.14 +#include "lua.h"
    1.15 +
    1.16 +#include "lmem.h"
    1.17 +
    1.18 +
    1.19 +#define EOZ	(-1)			/* end of stream */
    1.20 +
    1.21 +typedef struct Zio ZIO;
    1.22 +
    1.23 +#define char2int(c)	cast(int, cast(unsigned char, (c)))
    1.24 +
    1.25 +#define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))
    1.26 +
    1.27 +typedef struct Mbuffer {
    1.28 +  char *buffer;
    1.29 +  size_t n;
    1.30 +  size_t buffsize;
    1.31 +} Mbuffer;
    1.32 +
    1.33 +#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
    1.34 +
    1.35 +#define luaZ_buffer(buff)	((buff)->buffer)
    1.36 +#define luaZ_sizebuffer(buff)	((buff)->buffsize)
    1.37 +#define luaZ_bufflen(buff)	((buff)->n)
    1.38 +
    1.39 +#define luaZ_resetbuffer(buff) ((buff)->n = 0)
    1.40 +
    1.41 +
    1.42 +#define luaZ_resizebuffer(L, buff, size) \
    1.43 +	(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
    1.44 +	(buff)->buffsize = size)
    1.45 +
    1.46 +#define luaZ_freebuffer(L, buff)	luaZ_resizebuffer(L, buff, 0)
    1.47 +
    1.48 +
    1.49 +LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
    1.50 +LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
    1.51 +                                        void *data);
    1.52 +LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);	/* read next n bytes */
    1.53 +LUAI_FUNC int luaZ_lookahead (ZIO *z);
    1.54 +
    1.55 +
    1.56 +
    1.57 +/* --------- Private Part ------------------ */
    1.58 +
    1.59 +struct Zio {
    1.60 +  size_t n;			/* bytes still unread */
    1.61 +  const char *p;		/* current position in buffer */
    1.62 +  lua_Reader reader;
    1.63 +  void* data;			/* additional data */
    1.64 +  lua_State *L;			/* Lua state (for reader) */
    1.65 +};
    1.66 +
    1.67 +
    1.68 +LUAI_FUNC int luaZ_fill (ZIO *z);
    1.69 +
    1.70 +#endif