aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-17 18:48:58 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-17 18:48:58 -0200
commit502343b40230dfb00efc37bdbaa5c5576f3a5aa5 (patch)
treeb75f9e296ad3229a607fb2b7152dd9efc3706ef6 /lauxlib.c
parent82d09fbf0dbd5aee890f033b25b09dc48ce58a48 (diff)
downloadlua-502343b40230dfb00efc37bdbaa5c5576f3a5aa5.tar.gz
lua-502343b40230dfb00efc37bdbaa5c5576f3a5aa5.tar.bz2
lua-502343b40230dfb00efc37bdbaa5c5576f3a5aa5.zip
new scheme for buffers, centralized in auxlib.
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c71
1 files changed, 70 insertions, 1 deletions
diff --git a/lauxlib.c b/lauxlib.c
index ed893f70..ce6c2c78 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.4 1997/11/21 19:00:46 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.5 1997/12/09 13:35:19 roberto Exp roberto $
3** Auxiliar functions for building Lua libraries 3** Auxiliar functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,6 +10,8 @@
10#include <string.h> 10#include <string.h>
11 11
12#include "lauxlib.h" 12#include "lauxlib.h"
13#include "lmem.h"
14#include "lstate.h"
13#include "lua.h" 15#include "lua.h"
14#include "luadebug.h" 16#include "luadebug.h"
15 17
@@ -99,3 +101,70 @@ void luaL_verror (char *fmt, ...)
99} 101}
100 102
101 103
104/*-------------------------------------------------------
105** Auxiliar buffer
106-------------------------------------------------------*/
107
108#define BUFF_STEP 32
109
110#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
111
112static void Openspace (int size)
113{
114 LState *l = L; /* to optimize */
115 int base = l->Mbuffbase-l->Mbuffer;
116 l->Mbuffsize *= 2;
117 if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */
118 l->Mbuffsize = l->Mbuffnext+size;
119 l->Mbuffer = luaM_realloc(l->Mbuffer, l->Mbuffsize);
120 l->Mbuffbase = l->Mbuffer+base;
121}
122
123
124char *luaL_openspace (int size)
125{
126 openspace(size);
127 return L->Mbuffer+L->Mbuffnext;
128}
129
130
131void luaL_addchar (int c)
132{
133 openspace(BUFF_STEP);
134 L->Mbuffer[L->Mbuffnext++] = c;
135}
136
137
138void luaL_resetbuffer (void)
139{
140 L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
141}
142
143
144void luaL_addsize (int n)
145{
146 L->Mbuffnext += n;
147}
148
149
150int luaL_newbuffer (int size)
151{
152 int old = L->Mbuffbase-L->Mbuffer;
153 openspace(size);
154 L->Mbuffbase = L->Mbuffer+L->Mbuffnext;
155 return old;
156}
157
158
159void luaL_oldbuffer (int old)
160{
161 L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
162 L->Mbuffbase = L->Mbuffer+old;
163}
164
165
166char *luaL_buffer (void)
167{
168 return L->Mbuffbase;
169}
170