Imported from ../lua-3.2.2.tar.gz.
[lua.git] / src / lbuffer.c
blob81ff16cab760b9dcf8998ff05b17f00a1bd5db1a
1 /*
2 ** $Id: lbuffer.c,v 1.9 1999/02/26 15:48:55 roberto Exp $
3 ** Auxiliary functions for building Lua libraries
4 ** See Copyright Notice in lua.h
5 */
8 #include <stdio.h>
10 #include "lauxlib.h"
11 #include "lmem.h"
12 #include "lstate.h"
15 /*-------------------------------------------------------
16 ** Auxiliary buffer
17 -------------------------------------------------------*/
20 #define EXTRABUFF 32
23 #define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
25 static void Openspace (int size) {
26 lua_State *l = L; /* to optimize */
27 size += EXTRABUFF;
28 l->Mbuffsize = l->Mbuffnext+size;
29 luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, arrEM, MAX_INT);
33 char *luaL_openspace (int size) {
34 openspace(size);
35 return L->Mbuffer+L->Mbuffnext;
39 void luaL_addchar (int c) {
40 openspace(1);
41 L->Mbuffer[L->Mbuffnext++] = (char)c;
45 void luaL_resetbuffer (void) {
46 L->Mbuffnext = L->Mbuffbase;
50 void luaL_addsize (int n) {
51 L->Mbuffnext += n;
54 int luaL_getsize (void) {
55 return L->Mbuffnext-L->Mbuffbase;
58 int luaL_newbuffer (int size) {
59 int old = L->Mbuffbase;
60 openspace(size);
61 L->Mbuffbase = L->Mbuffnext;
62 return old;
66 void luaL_oldbuffer (int old) {
67 L->Mbuffnext = L->Mbuffbase;
68 L->Mbuffbase = old;
72 char *luaL_buffer (void) {
73 return L->Mbuffer+L->Mbuffbase;