lua/lzio.h

67 lines
1.5 KiB
C
Raw Normal View History

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