summaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-23 17:24:36 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-23 17:24:36 -0200
commitd916487d7c1f620dc7844ca4febfd51f8708a7be (patch)
tree9448940263d1a02f4b7d9623ba9313f940f4cba0 /lauxlib.c
parent1bf762ba3877eb27d7c30bbbbc774f1634062800 (diff)
downloadlua-d916487d7c1f620dc7844ca4febfd51f8708a7be.tar.gz
lua-d916487d7c1f620dc7844ca4febfd51f8708a7be.tar.bz2
lua-d916487d7c1f620dc7844ca4febfd51f8708a7be.zip
auxlib split in two parts (lauxlib and lbuffer)
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c73
1 files changed, 1 insertions, 72 deletions
diff --git a/lauxlib.c b/lauxlib.c
index ce6c2c78..922bc5d2 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.5 1997/12/09 13:35:19 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.6 1997/12/17 20:48:58 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*/
@@ -7,11 +7,8 @@
7 7
8#include <stdarg.h> 8#include <stdarg.h>
9#include <stdio.h> 9#include <stdio.h>
10#include <string.h>
11 10
12#include "lauxlib.h" 11#include "lauxlib.h"
13#include "lmem.h"
14#include "lstate.h"
15#include "lua.h" 12#include "lua.h"
16#include "luadebug.h" 13#include "luadebug.h"
17 14
@@ -100,71 +97,3 @@ void luaL_verror (char *fmt, ...)
100 lua_error(buff); 97 lua_error(buff);
101} 98}
102 99
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