aboutsummaryrefslogtreecommitdiff
path: root/lbuffer.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-22 11:12:07 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-22 11:12:07 -0200
commit29ede6aa13144ff7b69c57a87be1ee93f57ae896 (patch)
treeadcfb5dcff7db55481cd675349e23dec0e63c939 /lbuffer.c
parent951897c09319ae5474a4b86bb7d615136577caa0 (diff)
downloadlua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.gz
lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.bz2
lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.zip
first implementation of multiple states (reentrant code).
Diffstat (limited to 'lbuffer.c')
-rw-r--r--lbuffer.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/lbuffer.c b/lbuffer.c
index 181056f8..2525ea02 100644
--- a/lbuffer.c
+++ b/lbuffer.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuffer.c,v 1.9 1999/02/26 15:48:55 roberto Exp roberto $ 2** $Id: lbuffer.c,v 1.10 1999/11/10 15:40:46 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -7,6 +7,8 @@
7 7
8#include <stdio.h> 8#include <stdio.h>
9 9
10#define LUA_REENTRANT
11
10#include "lauxlib.h" 12#include "lauxlib.h"
11#include "lmem.h" 13#include "lmem.h"
12#include "lstate.h" 14#include "lstate.h"
@@ -20,55 +22,54 @@
20#define EXTRABUFF 32 22#define EXTRABUFF 32
21 23
22 24
23#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size) 25#define openspace(L, size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(L, size)
24 26
25static void Openspace (int size) { 27static void Openspace (lua_State *L, int size) {
26 lua_State *l = L; /* to optimize */ 28 L->Mbuffsize = (L->Mbuffnext+size+EXTRABUFF)*2;
27 l->Mbuffsize = (l->Mbuffnext+size+EXTRABUFF)*2; 29 luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char);
28 luaM_reallocvector(l->Mbuffer, l->Mbuffsize, char);
29} 30}
30 31
31 32
32char *luaL_openspace (int size) { 33char *luaL_openspace (lua_State *L, int size) {
33 openspace(size); 34 openspace(L, size);
34 return L->Mbuffer+L->Mbuffnext; 35 return L->Mbuffer+L->Mbuffnext;
35} 36}
36 37
37 38
38void luaL_addchar (int c) { 39void luaL_addchar (lua_State *L, int c) {
39 openspace(1); 40 openspace(L, 1);
40 L->Mbuffer[L->Mbuffnext++] = (char)c; 41 L->Mbuffer[L->Mbuffnext++] = (char)c;
41} 42}
42 43
43 44
44void luaL_resetbuffer (void) { 45void luaL_resetbuffer (lua_State *L) {
45 L->Mbuffnext = L->Mbuffbase; 46 L->Mbuffnext = L->Mbuffbase;
46} 47}
47 48
48 49
49void luaL_addsize (int n) { 50void luaL_addsize (lua_State *L, int n) {
50 L->Mbuffnext += n; 51 L->Mbuffnext += n;
51} 52}
52 53
53int luaL_getsize (void) { 54int luaL_getsize (lua_State *L) {
54 return L->Mbuffnext-L->Mbuffbase; 55 return L->Mbuffnext-L->Mbuffbase;
55} 56}
56 57
57int luaL_newbuffer (int size) { 58int luaL_newbuffer (lua_State *L, int size) {
58 int old = L->Mbuffbase; 59 int old = L->Mbuffbase;
59 openspace(size); 60 openspace(L, size);
60 L->Mbuffbase = L->Mbuffnext; 61 L->Mbuffbase = L->Mbuffnext;
61 return old; 62 return old;
62} 63}
63 64
64 65
65void luaL_oldbuffer (int old) { 66void luaL_oldbuffer (lua_State *L, int old) {
66 L->Mbuffnext = L->Mbuffbase; 67 L->Mbuffnext = L->Mbuffbase;
67 L->Mbuffbase = old; 68 L->Mbuffbase = old;
68} 69}
69 70
70 71
71char *luaL_buffer (void) { 72char *luaL_buffer (lua_State *L) {
72 return L->Mbuffer+L->Mbuffbase; 73 return L->Mbuffer+L->Mbuffbase;
73} 74}
74 75