The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lzio.h
Go to the documentation of this file.
1 /*
2 ** Buffered streams
3 ** See Copyright Notice in lua.h
4 */
5 
6 
7 #ifndef lzio_h
8 #define lzio_h
9 
10 #include "lua.h"
11 
12 #include "lmem.h"
13 
14 
15 #define EOZ (-1) /* end of stream */
16 
17 typedef struct Zio ZIO;
18 
19 #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
20 
21 
22 typedef struct Mbuffer {
23  char *buffer;
24  size_t n;
25  size_t buffsize;
26 } Mbuffer;
27 
28 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
29 
30 #define luaZ_buffer(buff) ((buff)->buffer)
31 #define luaZ_sizebuffer(buff) ((buff)->buffsize)
32 #define luaZ_bufflen(buff) ((buff)->n)
33 
34 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
35 
36 
37 #define luaZ_resizebuffer(L, buff, size) \
38  (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
39  (buff)->buffsize = size)
40 
41 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
42 
43 
44 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
46  void *data);
47 LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
48 
49 
50 
51 /* --------- Private Part ------------------ */
52 
53 struct Zio {
54  size_t n; /* bytes still unread */
55  const char *p; /* current position in buffer */
56  lua_Reader reader; /* reader function */
57  void* data; /* additional data */
58  lua_State *L; /* Lua state (for reader) */
59 };
60 
61 
62 LUAI_FUNC int luaZ_fill (ZIO *z);
63 
64 #endif
GLdouble GLdouble z
Definition: glew.h:1527
const char * p
Definition: lzio.h:55
void * data
Definition: lzio.h:57
#define LUAI_FUNC
Definition: luaconf.h:187
struct Mbuffer Mbuffer
lua_Reader reader
Definition: lzio.h:56
LUAI_FUNC size_t luaZ_read(ZIO *z, void *b, size_t n)
Definition: lzio.cpp:45
lua_State * L
Definition: lzio.h:58
const char *(* lua_Reader)(lua_State *L, void *ud, size_t *sz)
Definition: lua.h:61
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
size_t n
Definition: lzio.h:24
Definition: lzio.h:53
LUAI_FUNC int luaZ_fill(ZIO *z)
Definition: lzio.cpp:20
LUAI_FUNC char * luaZ_openspace(lua_State *L, Mbuffer *buff, size_t n)
Definition: lzio.cpp:67
char * buffer
Definition: lzio.h:23
static const char * reader(lua_State *L, void *ud, size_t *size)
Definition: luac.cpp:118
GLclampd n
Definition: glew.h:5903
Definition: lzio.h:22
size_t n
Definition: lzio.h:54
LUAI_FUNC void luaZ_init(lua_State *L, ZIO *z, lua_Reader reader, void *data)
Definition: lzio.cpp:35
size_t buffsize
Definition: lzio.h:25