123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
- ** $Id: lbuffer.c,v 1.8 1999/02/25 19:20:40 roberto Exp roberto $
- ** Auxiliary functions for building Lua libraries
- ** See Copyright Notice in lua.h
- */
- #include <stdio.h>
- #include "lauxlib.h"
- #include "lmem.h"
- #include "lstate.h"
- /*-------------------------------------------------------
- ** Auxiliary buffer
- -------------------------------------------------------*/
- #define EXTRABUFF 32
- #define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
- static void Openspace (int size) {
- lua_State *l = L; /* to optimize */
- size += EXTRABUFF;
- l->Mbuffsize = l->Mbuffnext+size;
- luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, arrEM, MAX_INT);
- }
- char *luaL_openspace (int size) {
- openspace(size);
- return L->Mbuffer+L->Mbuffnext;
- }
- void luaL_addchar (int c) {
- openspace(1);
- L->Mbuffer[L->Mbuffnext++] = (char)c;
- }
- void luaL_resetbuffer (void) {
- L->Mbuffnext = L->Mbuffbase;
- }
- void luaL_addsize (int n) {
- L->Mbuffnext += n;
- }
- int luaL_getsize (void) {
- return L->Mbuffnext-L->Mbuffbase;
- }
- int luaL_newbuffer (int size) {
- int old = L->Mbuffbase;
- openspace(size);
- L->Mbuffbase = L->Mbuffnext;
- return old;
- }
- void luaL_oldbuffer (int old) {
- L->Mbuffnext = L->Mbuffbase;
- L->Mbuffbase = old;
- }
- char *luaL_buffer (void) {
- return L->Mbuffer+L->Mbuffbase;
- }
|