1 /* $NetBSD: lzio.h,v 1.1.1.2 2012/03/15 00:08:14 alnsn Exp $ */
4 ** $Id: lzio.h,v 1.1.1.2 2012/03/15 00:08:14 alnsn Exp $
6 ** See Copyright Notice in lua.h
18 #define EOZ (-1) /* end of stream */
20 typedef struct Zio ZIO
;
22 #define char2int(c) cast(int, cast(unsigned char, (c)))
24 #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
26 typedef struct Mbuffer
{
32 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
34 #define luaZ_buffer(buff) ((buff)->buffer)
35 #define luaZ_sizebuffer(buff) ((buff)->buffsize)
36 #define luaZ_bufflen(buff) ((buff)->n)
38 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
41 #define luaZ_resizebuffer(L, buff, size) \
42 (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
43 (buff)->buffsize = size)
45 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
48 LUAI_FUNC
char *luaZ_openspace (lua_State
*L
, Mbuffer
*buff
, size_t n
);
49 LUAI_FUNC
void luaZ_init (lua_State
*L
, ZIO
*z
, lua_Reader reader
,
51 LUAI_FUNC
size_t luaZ_read (ZIO
* z
, void* b
, size_t n
); /* read next n bytes */
52 LUAI_FUNC
int luaZ_lookahead (ZIO
*z
);
56 /* --------- Private Part ------------------ */
59 size_t n
; /* bytes still unread */
60 const char *p
; /* current position in buffer */
62 void* data
; /* additional data */
63 lua_State
*L
; /* Lua state (for reader) */
67 LUAI_FUNC
int luaZ_fill (ZIO
*z
);