Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef lzio_h
00009 #define lzio_h
00010
00011 #include <lua/lua.h>
00012
00013 #include <lua/lmem.h>
00014
00015
00016 #define EOZ (-1)
00017
00018 typedef struct Zio ZIO;
00019
00020 #define char2int(c) cast(int, cast(unsigned char, (c)))
00021
00022 #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
00023
00024 typedef struct Mbuffer {
00025 char *buffer;
00026 size_t n;
00027 size_t buffsize;
00028 } Mbuffer;
00029
00030 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
00031
00032 #define luaZ_buffer(buff) ((buff)->buffer)
00033 #define luaZ_sizebuffer(buff) ((buff)->buffsize)
00034 #define luaZ_bufflen(buff) ((buff)->n)
00035
00036 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
00037
00038
00039 #define luaZ_resizebuffer(L, buff, size) \
00040 (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
00041 (buff)->buffsize = size)
00042
00043 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
00044
00045
00046 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
00047 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
00048 void *data);
00049 LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);
00050 LUAI_FUNC int luaZ_lookahead (ZIO *z);
00051
00052
00053
00054
00055
00056 struct Zio {
00057 size_t n;
00058 const char *p;
00059 lua_Reader reader;
00060 void* data;
00061 lua_State *L;
00062 };
00063
00064
00065 LUAI_FUNC int luaZ_fill (ZIO *z);
00066
00067 #endif