From 35a22ed1ab15fabb9404d0184165baa1d52394f1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 3 Jun 2002 14:46:34 -0300 Subject: lua_load* replaced by a simple lua_load --- lzio.c | 56 ++++++++++++++++---------------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) (limited to 'lzio.c') diff --git a/lzio.c b/lzio.c index 6bbe6982..3e3610c9 100644 --- a/lzio.c +++ b/lzio.c @@ -1,69 +1,44 @@ /* -** $Id: lzio.c,v 1.15 2001/11/28 20:13:13 roberto Exp roberto $ +** $Id: lzio.c,v 1.16 2002/04/29 12:37:41 roberto Exp roberto $ ** a generic input stream interface ** See Copyright Notice in lua.h */ - -#include #include #include "lua.h" +#include "llimits.h" #include "lzio.h" -/* ----------------------------------------------------- memory buffers --- */ - -static int zmfilbuf (ZIO* z) { - (void)z; /* to avoid warnings */ - return EOZ; -} - - -ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name) { - if (b==NULL) return NULL; - z->n = size; - z->p = (const unsigned char *)b; - z->filbuf = zmfilbuf; - z->u = NULL; - z->name = name; - return z; -} - - -/* -------------------------------------------------------------- FILEs --- */ - -static int zffilbuf (ZIO* z) { - size_t n; - if (feof((FILE *)z->u)) return EOZ; - n = fread(z->buffer, 1, ZBSIZE, (FILE *)z->u); - if (n==0) return EOZ; - z->n = n-1; - z->p = z->buffer; +int luaZ_fill (ZIO *z) { + size_t size; + const char *buff = z->getblock(z->ud, &size); + if (buff == NULL || size == 0) return EOZ; + z->n = size - 1; + z->p = buff; return *(z->p++); } -ZIO* zFopen (ZIO* z, FILE* f, const char *name) { - if (f==NULL) return NULL; - z->n = 0; - z->p = z->buffer; - z->filbuf = zffilbuf; - z->u = f; +void luaZ_init (ZIO *z, lua_Getblock getblock, void *ud, const char *name) { + z->getblock = getblock; + z->ud = ud; z->name = name; - return z; + z->n = 0; + z->p = NULL; } /* --------------------------------------------------------------- read --- */ -size_t zread (ZIO *z, void *b, size_t n) { +size_t luaZ_zread (ZIO *z, void *b, size_t n) { while (n) { size_t m; if (z->n == 0) { - if (z->filbuf(z) == EOZ) + if (luaZ_fill(z) == EOZ) return n; /* return number of missing bytes */ else { ++z->n; /* filbuf removed first byte; put back it */ @@ -79,3 +54,4 @@ size_t zread (ZIO *z, void *b, size_t n) { } return 0; } + -- cgit v1.2.3-55-g6feb