|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
-** $Id: lbuffer.c,v 1.4 1998/06/19 16:14:09 roberto Exp roberto $
|
|
|
|
|
|
+** $Id: lbuffer.c,v 1.5 1998/12/28 13:44:54 roberto Exp roberto $
|
|
** Auxiliary functions for building Lua libraries
|
|
** Auxiliary functions for building Lua libraries
|
|
** See Copyright Notice in lua.h
|
|
** See Copyright Notice in lua.h
|
|
*/
|
|
*/
|
|
@@ -16,70 +16,57 @@
|
|
** Auxiliary buffer
|
|
** Auxiliary buffer
|
|
-------------------------------------------------------*/
|
|
-------------------------------------------------------*/
|
|
|
|
|
|
-#define BUFF_STEP 32
|
|
|
|
|
|
|
|
#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
|
|
#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
|
|
|
|
|
|
-static void Openspace (int size)
|
|
|
|
-{
|
|
|
|
|
|
+static void Openspace (int size) {
|
|
lua_State *l = L; /* to optimize */
|
|
lua_State *l = L; /* to optimize */
|
|
- int base = l->Mbuffbase-l->Mbuffer;
|
|
|
|
- l->Mbuffsize *= 2;
|
|
|
|
- if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */
|
|
|
|
- l->Mbuffsize = l->Mbuffnext+size;
|
|
|
|
- l->Mbuffer = luaM_realloc(l->Mbuffer, l->Mbuffsize);
|
|
|
|
- l->Mbuffbase = l->Mbuffer+base;
|
|
|
|
|
|
+ l->Mbuffsize = l->Mbuffnext+size;
|
|
|
|
+ l->Mbuffer = luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char,
|
|
|
|
+ memEM, MAX_INT);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-char *luaL_openspace (int size)
|
|
|
|
-{
|
|
|
|
|
|
+char *luaL_openspace (int size) {
|
|
openspace(size);
|
|
openspace(size);
|
|
return L->Mbuffer+L->Mbuffnext;
|
|
return L->Mbuffer+L->Mbuffnext;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void luaL_addchar (int c)
|
|
|
|
-{
|
|
|
|
- openspace(BUFF_STEP);
|
|
|
|
|
|
+void luaL_addchar (int c) {
|
|
|
|
+ openspace(1);
|
|
L->Mbuffer[L->Mbuffnext++] = (char)c;
|
|
L->Mbuffer[L->Mbuffnext++] = (char)c;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void luaL_resetbuffer (void)
|
|
|
|
-{
|
|
|
|
- L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
|
|
|
|
|
|
+void luaL_resetbuffer (void) {
|
|
|
|
+ L->Mbuffnext = L->Mbuffbase;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void luaL_addsize (int n)
|
|
|
|
-{
|
|
|
|
|
|
+void luaL_addsize (int n) {
|
|
L->Mbuffnext += n;
|
|
L->Mbuffnext += n;
|
|
}
|
|
}
|
|
|
|
|
|
-int luaL_getsize (void)
|
|
|
|
-{
|
|
|
|
- return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer);
|
|
|
|
|
|
+int luaL_getsize (void) {
|
|
|
|
+ return L->Mbuffnext-L->Mbuffbase;
|
|
}
|
|
}
|
|
|
|
|
|
-int luaL_newbuffer (int size)
|
|
|
|
-{
|
|
|
|
- int old = L->Mbuffbase-L->Mbuffer;
|
|
|
|
|
|
+int luaL_newbuffer (int size) {
|
|
|
|
+ int old = L->Mbuffbase;
|
|
openspace(size);
|
|
openspace(size);
|
|
- L->Mbuffbase = L->Mbuffer+L->Mbuffnext;
|
|
|
|
|
|
+ L->Mbuffbase = L->Mbuffnext;
|
|
return old;
|
|
return old;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void luaL_oldbuffer (int old)
|
|
|
|
-{
|
|
|
|
- L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
|
|
|
|
- L->Mbuffbase = L->Mbuffer+old;
|
|
|
|
|
|
+void luaL_oldbuffer (int old) {
|
|
|
|
+ L->Mbuffnext = L->Mbuffbase;
|
|
|
|
+ L->Mbuffbase = old;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-char *luaL_buffer (void)
|
|
|
|
-{
|
|
|
|
- return L->Mbuffbase;
|
|
|
|
|
|
+char *luaL_buffer (void) {
|
|
|
|
+ return L->Mbuffer+L->Mbuffbase;
|
|
}
|
|
}
|
|
|
|
|