1997-12-23 22:24:36 +03:00
|
|
|
/*
|
1999-02-25 18:17:01 +03:00
|
|
|
** $Id: lbuffer.c,v 1.5 1998/12/28 13:44:54 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
|
|
|
-------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
#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 18:17:01 +03:00
|
|
|
l->Mbuffsize = l->Mbuffnext+size;
|
|
|
|
l->Mbuffer = luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char,
|
|
|
|
memEM, 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
|
|
|
}
|
|
|
|
|