misc/liblua/lzio.h
author Vittorio Giovara <vittorio.giovara@gmail.com>
Fri, 03 Jan 2014 07:19:04 -0800
changeset 9927 22bb4dfbfea8
parent 2812 0a24853de796
child 10017 de822cd3df3a
permissions -rw-r--r--
Merge pull request #8 from LocutusOfBorg/fix-avwrapper-exit-calls Fixed avwrapper exit calls, fixing issue #752
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     1
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     2
** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     3
** Buffered streams
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     4
** See Copyright Notice in lua.h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     5
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     7
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     8
#ifndef lzio_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     9
#define lzio_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    10
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    11
#include "lua.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    12
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    13
#include "lmem.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    14
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    15
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    16
#define EOZ	(-1)			/* end of stream */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    17
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    18
typedef struct Zio ZIO;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    19
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    20
#define char2int(c)	cast(int, cast(unsigned char, (c)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    21
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    22
#define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    23
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    24
typedef struct Mbuffer {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    25
  char *buffer;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    26
  size_t n;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    27
  size_t buffsize;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    28
} Mbuffer;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    29
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    30
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    31
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    32
#define luaZ_buffer(buff)	((buff)->buffer)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    33
#define luaZ_sizebuffer(buff)	((buff)->buffsize)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    34
#define luaZ_bufflen(buff)	((buff)->n)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    35
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    36
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    37
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    38
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    39
#define luaZ_resizebuffer(L, buff, size) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    40
	(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    41
	(buff)->buffsize = size)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    42
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    43
#define luaZ_freebuffer(L, buff)	luaZ_resizebuffer(L, buff, 0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    44
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    45
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    46
LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    47
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    48
                                        void *data);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    49
LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n);	/* read next n bytes */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    50
LUAI_FUNC int luaZ_lookahead (ZIO *z);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    51
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    52
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    53
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    54
/* --------- Private Part ------------------ */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    55
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    56
struct Zio {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    57
  size_t n;			/* bytes still unread */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    58
  const char *p;		/* current position in buffer */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    59
  lua_Reader reader;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    60
  void* data;			/* additional data */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    61
  lua_State *L;			/* Lua state (for reader) */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    62
};
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    63
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    64
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    65
LUAI_FUNC int luaZ_fill (ZIO *z);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    66
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    67
#endif