1997-12-23 22:24:36 +03:00
|
|
|
/*
|
1999-02-26 18:48:55 +03:00
|
|
|
** $Id: lbuffer.c,v 1.8 1999/02/25 19:20:40 roberto Exp roberto $
|
1998-06-19 20:14:09 +04:00
|
|
|
** Auxiliary functions for building Lua libraries
|
1997-12-23 22:24:36 +03:00
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "lmem.h"
|
|
|
|
#include "lstate.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------
|
1998-06-19 20:14:09 +04:00
|
|
|
** Auxiliary buffer
|
1997-12-23 22:24:36 +03:00
|
|
|
-------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
1999-02-25 22:13:56 +03:00
|
|
|
#define EXTRABUFF 32
|
|
|
|
|
|
|
|
|
1997-12-23 22:24:36 +03:00
|
|
|
#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
static void Openspace (int size) {
|
1998-06-03 00:37:04 +04:00
|
|
|
lua_State *l = L; /* to optimize */
|
1999-02-25 22:20:40 +03:00
|
|
|
size += EXTRABUFF;
|
|
|
|
l->Mbuffsize = l->Mbuffnext+size;
|
1999-02-26 18:48:55 +03:00
|
|
|
luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, arrEM, MAX_INT);
|
1997-12-23 22:24:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
char *luaL_openspace (int size) {
|
1997-12-23 22:24:36 +03:00
|
|
|
openspace(size);
|
|
|
|
return L->Mbuffer+L->Mbuffnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
void luaL_addchar (int c) {
|
|
|
|
openspace(1);
|
1998-12-28 16:44:54 +03:00
|
|
|
L->Mbuffer[L->Mbuffnext++] = (char)c;
|
1997-12-23 22:24:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
void luaL_resetbuffer (void) {
|
|
|
|
L->Mbuffnext = L->Mbuffbase;
|
1997-12-23 22:24:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
void luaL_addsize (int n) {
|
1997-12-23 22:24:36 +03:00
|
|
|
L->Mbuffnext += n;
|
|
|
|
}
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
int luaL_getsize (void) {
|
|
|
|
return L->Mbuffnext-L->Mbuffbase;
|
1998-03-06 19:54:42 +03:00
|
|
|
}
|
1997-12-23 22:24:36 +03:00
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
int luaL_newbuffer (int size) {
|
|
|
|
int old = L->Mbuffbase;
|
1997-12-23 22:24:36 +03:00
|
|
|
openspace(size);
|
1999-02-25 18:17:01 +03:00
|
|
|
L->Mbuffbase = L->Mbuffnext;
|
1997-12-23 22:24:36 +03:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
void luaL_oldbuffer (int old) {
|
|
|
|
L->Mbuffnext = L->Mbuffbase;
|
|
|
|
L->Mbuffbase = old;
|
1997-12-23 22:24:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-25 18:17:01 +03:00
|
|
|
char *luaL_buffer (void) {
|
|
|
|
return L->Mbuffer+L->Mbuffbase;
|
1997-12-23 22:24:36 +03:00
|
|
|
}
|
|
|
|
|