1997-06-17 00:50:22 +08:00
|
|
|
/*
|
2009-05-19 01:26:25 +08:00
|
|
|
** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp roberto $
|
1997-09-17 03:25:59 +08:00
|
|
|
** Buffered streams
|
|
|
|
** See Copyright Notice in lua.h
|
1997-06-17 00:50:22 +08:00
|
|
|
*/
|
|
|
|
|
1997-09-17 03:25:59 +08:00
|
|
|
|
|
|
|
#ifndef lzio_h
|
|
|
|
#define lzio_h
|
1997-06-17 00:50:22 +08:00
|
|
|
|
2002-06-04 01:46:34 +08:00
|
|
|
#include "lua.h"
|
1997-06-19 04:30:52 +08:00
|
|
|
|
2003-08-28 22:38:46 +08:00
|
|
|
#include "lmem.h"
|
|
|
|
|
1997-06-19 04:30:52 +08:00
|
|
|
|
1997-06-17 00:50:22 +08:00
|
|
|
#define EOZ (-1) /* end of stream */
|
|
|
|
|
2002-10-09 02:46:08 +08:00
|
|
|
typedef struct Zio ZIO;
|
1997-06-17 00:50:22 +08:00
|
|
|
|
2003-03-21 00:00:56 +08:00
|
|
|
#define char2int(c) cast(int, cast(unsigned char, (c)))
|
|
|
|
|
|
|
|
#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
|
1997-06-19 05:39:56 +08:00
|
|
|
|
2009-05-19 01:26:25 +08:00
|
|
|
#define zungetc(z) ((z)->n++, (z)->p--)
|
|
|
|
|
|
|
|
|
2002-10-09 02:46:08 +08:00
|
|
|
typedef struct Mbuffer {
|
|
|
|
char *buffer;
|
2003-10-04 00:05:34 +08:00
|
|
|
size_t n;
|
|
|
|
size_t buffsize;
|
2002-10-09 02:46:08 +08:00
|
|
|
} Mbuffer;
|
|
|
|
|
|
|
|
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
|
|
|
|
|
|
|
|
#define luaZ_buffer(buff) ((buff)->buffer)
|
2003-08-28 22:38:46 +08:00
|
|
|
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
|
|
|
|
#define luaZ_bufflen(buff) ((buff)->n)
|
|
|
|
|
|
|
|
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
|
|
|
|
|
2002-10-09 02:46:08 +08:00
|
|
|
|
|
|
|
#define luaZ_resizebuffer(L, buff, size) \
|
|
|
|
(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
|
|
|
|
(buff)->buffsize = size)
|
|
|
|
|
|
|
|
#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
|
|
|
|
|
2003-08-28 22:38:46 +08:00
|
|
|
|
2005-04-26 03:24:10 +08:00
|
|
|
LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
|
2005-05-18 03:49:15 +08:00
|
|
|
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
|
2005-04-26 03:24:10 +08:00
|
|
|
void *data);
|
|
|
|
LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
|
|
|
|
LUAI_FUNC int luaZ_lookahead (ZIO *z);
|
|
|
|
|
|
|
|
|
2002-10-09 02:46:08 +08:00
|
|
|
|
1997-06-17 00:50:22 +08:00
|
|
|
/* --------- Private Part ------------------ */
|
|
|
|
|
2002-10-09 02:46:08 +08:00
|
|
|
struct Zio {
|
2002-06-04 01:46:34 +08:00
|
|
|
size_t n; /* bytes still unread */
|
|
|
|
const char *p; /* current position in buffer */
|
2005-05-18 03:49:15 +08:00
|
|
|
lua_Reader reader;
|
2002-06-06 20:40:22 +08:00
|
|
|
void* data; /* additional data */
|
2003-08-26 04:00:50 +08:00
|
|
|
lua_State *L; /* Lua state (for reader) */
|
1997-06-17 00:50:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-04-26 03:24:10 +08:00
|
|
|
LUAI_FUNC int luaZ_fill (ZIO *z);
|
2002-06-04 01:46:34 +08:00
|
|
|
|
1997-06-17 00:50:22 +08:00
|
|
|
#endif
|