From 29ede6aa13144ff7b69c57a87be1ee93f57ae896 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 22 Nov 1999 11:12:07 -0200 Subject: first implementation of multiple states (reentrant code). --- lbuffer.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'lbuffer.c') diff --git a/lbuffer.c b/lbuffer.c index 181056f8..2525ea02 100644 --- a/lbuffer.c +++ b/lbuffer.c @@ -1,5 +1,5 @@ /* -** $Id: lbuffer.c,v 1.9 1999/02/26 15:48:55 roberto Exp roberto $ +** $Id: lbuffer.c,v 1.10 1999/11/10 15:40:46 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -7,6 +7,8 @@ #include +#define LUA_REENTRANT + #include "lauxlib.h" #include "lmem.h" #include "lstate.h" @@ -20,55 +22,54 @@ #define EXTRABUFF 32 -#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size) +#define openspace(L, size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(L, size) -static void Openspace (int size) { - lua_State *l = L; /* to optimize */ - l->Mbuffsize = (l->Mbuffnext+size+EXTRABUFF)*2; - luaM_reallocvector(l->Mbuffer, l->Mbuffsize, char); +static void Openspace (lua_State *L, int size) { + L->Mbuffsize = (L->Mbuffnext+size+EXTRABUFF)*2; + luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char); } -char *luaL_openspace (int size) { - openspace(size); +char *luaL_openspace (lua_State *L, int size) { + openspace(L, size); return L->Mbuffer+L->Mbuffnext; } -void luaL_addchar (int c) { - openspace(1); +void luaL_addchar (lua_State *L, int c) { + openspace(L, 1); L->Mbuffer[L->Mbuffnext++] = (char)c; } -void luaL_resetbuffer (void) { +void luaL_resetbuffer (lua_State *L) { L->Mbuffnext = L->Mbuffbase; } -void luaL_addsize (int n) { +void luaL_addsize (lua_State *L, int n) { L->Mbuffnext += n; } -int luaL_getsize (void) { +int luaL_getsize (lua_State *L) { return L->Mbuffnext-L->Mbuffbase; } -int luaL_newbuffer (int size) { +int luaL_newbuffer (lua_State *L, int size) { int old = L->Mbuffbase; - openspace(size); + openspace(L, size); L->Mbuffbase = L->Mbuffnext; return old; } -void luaL_oldbuffer (int old) { +void luaL_oldbuffer (lua_State *L, int old) { L->Mbuffnext = L->Mbuffbase; L->Mbuffbase = old; } -char *luaL_buffer (void) { +char *luaL_buffer (lua_State *L) { return L->Mbuffer+L->Mbuffbase; } -- cgit v1.2.3-55-g6feb