1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00
lua/lzio.h

65 lines
1.3 KiB
C
Raw Normal View History

1997-06-16 13:50:22 -03:00
/*
** $Id: lzio.h,v 1.14 2002/10/08 18:46:08 roberto Exp roberto $
1997-09-16 16:25:59 -03:00
** Buffered streams
** See Copyright Notice in lua.h
1997-06-16 13:50:22 -03:00
*/
1997-09-16 16:25:59 -03:00
#ifndef lzio_h
#define lzio_h
1997-06-16 13:50:22 -03:00
#include "lua.h"
1997-06-16 13:50:22 -03:00
#define EOZ (-1) /* end of stream */
typedef struct Zio ZIO;
1997-06-16 13:50:22 -03:00
#define char2int(c) cast(int, cast(unsigned char, (c)))
#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
1997-06-18 18:39:56 -03:00
1997-12-22 18:57:18 -02:00
#define zname(z) ((z)->name)
1997-06-16 13:50:22 -03:00
2002-06-06 09:40:22 -03:00
void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data, const char *name);
2002-08-05 15:45:02 -03:00
size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
2002-06-03 17:11:07 -03:00
int luaZ_lookahead (ZIO *z);
1997-06-16 13:50:22 -03:00
2000-10-20 14:36:32 -02:00
typedef struct Mbuffer {
char *buffer;
size_t buffsize;
} Mbuffer;
char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
#define luaZ_buffer(buff) ((buff)->buffer)
#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)
1997-06-16 13:50:22 -03:00
/* --------- Private Part ------------------ */
struct Zio {
size_t n; /* bytes still unread */
const char *p; /* current position in buffer */
2002-06-06 09:40:22 -03:00
lua_Chunkreader reader;
void* data; /* additional data */
1999-08-16 17:52:00 -03:00
const char *name;
1997-06-16 13:50:22 -03:00
};
int luaZ_fill (ZIO *z);
1997-06-16 13:50:22 -03:00
#endif