1997-06-16 09:50:22 -07:00
|
|
|
/*
|
2018-08-23 10:26:12 -07:00
|
|
|
** $Id: lzio.h $
|
1997-09-16 12:25:59 -07:00
|
|
|
** Buffered streams
|
|
|
|
** See Copyright Notice in lua.h
|
1997-06-16 09:50:22 -07:00
|
|
|
*/
|
|
|
|
|
1997-09-16 12:25:59 -07:00
|
|
|
|
|
|
|
#ifndef lzio_h
|
|
|
|
#define lzio_h
|
1997-06-16 09:50:22 -07:00
|
|
|
|
2002-06-03 10:46:34 -07:00
|
|
|
#include "lua.h"
|
1997-06-18 13:30:52 -07:00
|
|
|
|
2003-08-28 07:38:46 -07:00
|
|
|
#include "lmem.h"
|
|
|
|
|
1997-06-18 13:30:52 -07:00
|
|
|
|
1997-06-16 09:50:22 -07:00
|
|
|
#define EOZ (-1) /* end of stream */
|
|
|
|
|
2002-10-08 11:46:08 -07:00
|
|
|
typedef struct Zio ZIO;
|
1997-06-16 09:50:22 -07:00
|
|
|
|
2011-07-15 05:35:32 -07:00
|
|
|
#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
|
1997-06-18 14:39:56 -07:00
|
|
|
|
2009-05-18 10:26:25 -07:00
|
|
|
|
2002-10-08 11:46:08 -07:00
|
|
|
typedef struct Mbuffer {
|
|
|
|
char *buffer;
|
2003-10-03 09:05:34 -07:00
|
|
|
size_t n;
|
|
|
|
size_t buffsize;
|
2002-10-08 11:46:08 -07:00
|
|
|
} Mbuffer;
|
|
|
|
|
|
|
|
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
|
|
|
|
|
|
|
|
#define luaZ_buffer(buff) ((buff)->buffer)
|
2003-08-28 07:38:46 -07:00
|
|
|
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
|
|
|
|
#define luaZ_bufflen(buff) ((buff)->n)
|
|
|
|
|
2014-01-31 07:14:22 -08:00
|
|
|
#define luaZ_buffremove(buff,i) ((buff)->n -= (i))
|
2003-08-28 07:38:46 -07:00
|
|
|
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
|
|
|
|
|
2002-10-08 11:46:08 -07:00
|
|
|
|
|
|
|
#define luaZ_resizebuffer(L, buff, size) \
|
2014-12-19 09:26:14 -08:00
|
|
|
((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
|
|
|
|
(buff)->buffsize, size), \
|
2002-10-08 11:46:08 -07:00
|
|
|
(buff)->buffsize = size)
|
|
|
|
|
|
|
|
#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
|
|
|
|
|
2003-08-28 07:38:46 -07:00
|
|
|
|
2005-05-17 12:49:15 -07:00
|
|
|
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
|
2005-04-25 12:24:10 -07:00
|
|
|
void *data);
|
2013-06-07 07:51:10 -07:00
|
|
|
LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */
|
2005-04-25 12:24:10 -07:00
|
|
|
|
|
|
|
|
2002-10-08 11:46:08 -07:00
|
|
|
|
1997-06-16 09:50:22 -07:00
|
|
|
/* --------- Private Part ------------------ */
|
|
|
|
|
2002-10-08 11:46:08 -07:00
|
|
|
struct Zio {
|
2002-06-03 10:46:34 -07:00
|
|
|
size_t n; /* bytes still unread */
|
|
|
|
const char *p; /* current position in buffer */
|
2011-02-17 09:34:16 -08:00
|
|
|
lua_Reader reader; /* reader function */
|
2013-06-07 07:51:10 -07:00
|
|
|
void *data; /* additional data */
|
2003-08-25 13:00:50 -07:00
|
|
|
lua_State *L; /* Lua state (for reader) */
|
1997-06-16 09:50:22 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-04-25 12:24:10 -07:00
|
|
|
LUAI_FUNC int luaZ_fill (ZIO *z);
|
2002-06-03 10:46:34 -07:00
|
|
|
|
1997-06-16 09:50:22 -07:00
|
|
|
#endif
|