summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-17 18:48:58 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-17 18:48:58 -0200
commit502343b40230dfb00efc37bdbaa5c5576f3a5aa5 (patch)
treeb75f9e296ad3229a607fb2b7152dd9efc3706ef6
parent82d09fbf0dbd5aee890f033b25b09dc48ce58a48 (diff)
downloadlua-github-502343b40230dfb00efc37bdbaa5c5576f3a5aa5.tar.gz
new scheme for buffers, centralized in auxlib.
-rw-r--r--lauxlib.c71
-rw-r--r--lauxlib.h9
-rw-r--r--lbuiltin.c4
-rw-r--r--lgc.c3
-rw-r--r--liolib.c9
-rw-r--r--llex.c64
-rw-r--r--llex.h9
-rw-r--r--lmem.c19
-rw-r--r--lmem.h4
-rw-r--r--lstate.c4
-rw-r--r--lstate.h8
-rw-r--r--lstrlib.c125
-rw-r--r--lualib.h5
-rw-r--r--lvm.c6
-rw-r--r--makefile13
15 files changed, 181 insertions, 172 deletions
diff --git a/lauxlib.c b/lauxlib.c
index ed893f70..ce6c2c78 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.4 1997/11/21 19:00:46 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.5 1997/12/09 13:35:19 roberto Exp roberto $
** Auxiliar functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -10,6 +10,8 @@
#include <string.h>
#include "lauxlib.h"
+#include "lmem.h"
+#include "lstate.h"
#include "lua.h"
#include "luadebug.h"
@@ -99,3 +101,70 @@ void luaL_verror (char *fmt, ...)
}
+/*-------------------------------------------------------
+** Auxiliar buffer
+-------------------------------------------------------*/
+
+#define BUFF_STEP 32
+
+#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
+
+static void Openspace (int size)
+{
+ LState *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;
+}
+
+
+char *luaL_openspace (int size)
+{
+ openspace(size);
+ return L->Mbuffer+L->Mbuffnext;
+}
+
+
+void luaL_addchar (int c)
+{
+ openspace(BUFF_STEP);
+ L->Mbuffer[L->Mbuffnext++] = c;
+}
+
+
+void luaL_resetbuffer (void)
+{
+ L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
+}
+
+
+void luaL_addsize (int n)
+{
+ L->Mbuffnext += n;
+}
+
+
+int luaL_newbuffer (int size)
+{
+ int old = L->Mbuffbase-L->Mbuffer;
+ openspace(size);
+ L->Mbuffbase = L->Mbuffer+L->Mbuffnext;
+ return old;
+}
+
+
+void luaL_oldbuffer (int old)
+{
+ L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
+ L->Mbuffbase = L->Mbuffer+old;
+}
+
+
+char *luaL_buffer (void)
+{
+ return L->Mbuffbase;
+}
+
diff --git a/lauxlib.h b/lauxlib.h
index 712c484c..ae043322 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.h,v 1.3 1997/11/21 19:00:46 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.4 1997/12/09 13:35:19 roberto Exp roberto $
** Auxiliar functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -27,6 +27,13 @@ lua_Object luaL_functionarg (int arg);
lua_Object luaL_tablearg (int arg);
lua_Object luaL_nonnullarg (int numArg);
void luaL_verror (char *fmt, ...);
+char *luaL_openspace (int size);
+void luaL_resetbuffer (void);
+void luaL_addchar (int c);
+void luaL_addsize (int n);
+int luaL_newbuffer (int size);
+void luaL_oldbuffer (int old);
+char *luaL_buffer (void);
#endif
diff --git a/lbuiltin.c b/lbuiltin.c
index c43a230b..fa83e58a 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbuiltin.c,v 1.16 1997/12/11 17:21:11 roberto Exp roberto $
+** $Id: lbuiltin.c,v 1.17 1997/12/15 16:17:20 roberto Exp roberto $
** Built-in functions
** See Copyright Notice in lua.h
*/
@@ -131,7 +131,7 @@ static void internaldofile (void)
static char *to_string (lua_Object obj)
{
- char *buff = luaM_buffer(30);
+ char *buff = luaL_openspace(30);
TObject *o = luaA_Address(obj);
switch (ttype(o)) {
case LUA_T_NUMBER: case LUA_T_STRING:
diff --git a/lgc.c b/lgc.c
index 1af3cb85..c5a99e62 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 1.12 1997/12/11 14:48:46 roberto Exp roberto $
+** $Id: lgc.c,v 1.13 1997/12/15 16:17:20 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -272,7 +272,6 @@ long lua_collectgarbage (long limit)
luaS_free(freestr);
luaF_freeproto(freefunc);
luaF_freeclosure(freeclos);
- luaM_clearbuffer();
recovered = recovered-L->nblocks;
L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit;
return recovered;
diff --git a/liolib.c b/liolib.c
index 4befcfa6..46c4e87c 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 1.8 1997/11/28 12:40:37 roberto Exp roberto $
+** $Id: liolib.c,v 1.9 1997/12/09 13:50:08 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -190,7 +190,7 @@ static void io_read (void)
char *p = luaL_opt_string(arg, "[^\n]*{\n}");
int inskip = 0; /* to control {skips} */
int c = NEED_OTHER;
- luaI_emptybuff();
+ luaL_resetbuffer();
while (*p) {
if (*p == '{') {
inskip++;
@@ -208,7 +208,7 @@ static void io_read (void)
if (c == NEED_OTHER) c = getc(f);
m = luaI_singlematch((c == EOF) ? 0 : (char)c, p, &ep);
if (m) {
- if (inskip == 0) luaI_addchar(c);
+ if (inskip == 0) luaL_addchar(c);
c = NEED_OTHER;
}
switch (*ep) {
@@ -227,7 +227,8 @@ static void io_read (void)
} break_while:
if (c >= 0) /* not EOF nor NEED_OTHER? */
ungetc(c, f);
- buff = luaI_addchar(0);
+ luaL_addchar(0);
+ buff = luaL_buffer();
if (*buff != 0 || *p == 0) /* read something or did not fail? */
lua_pushstring(buff);
}
diff --git a/llex.c b/llex.c
index 9c8bcb3d..2fd65496 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
/*
-** $Id: llex.c,v 1.9 1997/12/02 12:43:54 roberto Exp roberto $
+** $Id: llex.c,v 1.10 1997/12/09 13:35:19 roberto Exp roberto $
** Lexical Analizer
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <ctype.h>
#include <string.h>
+#include "lauxlib.h"
#include "llex.h"
#include "lmem.h"
#include "lobject.h"
@@ -66,8 +67,7 @@ void luaX_setinput (ZIO *z)
LS->ifstate[0].elsepart = 1; /* to avoid a free $else */
LS->lex_z = z;
firstline(LS);
- LS->textbuff.buffsize = 20;
- LS->textbuff.text = luaM_buffer(LS->textbuff.buffsize);
+ luaL_resetbuffer();
}
@@ -201,31 +201,24 @@ static void inclinenumber (LexState *LS)
-static void save (LexState *LS, int c)
-{
- if (LS->textbuff.tokensize >= LS->textbuff.buffsize)
- LS->textbuff.text = luaM_buffer(LS->textbuff.buffsize *= 2);
- LS->textbuff.text[LS->textbuff.tokensize++] = c;
-}
+#define save(c) luaL_addchar(c)
+#define save_and_next(LS) (save(LS->current), next(LS))
char *luaX_lasttoken (void)
{
- save(L->lexstate, 0);
- return L->lexstate->textbuff.text;
+ save(0);
+ return luaL_buffer();
}
-#define save_and_next(LS) (save(LS, LS->current), next(LS))
-
-
static int read_long_string (LexState *LS, YYSTYPE *l)
{
int cont = 0;
while (1) {
switch (LS->current) {
case EOZ:
- save(LS, 0);
+ save(0);
return WRONGTOKEN;
case '[':
save_and_next(LS);
@@ -243,7 +236,7 @@ static int read_long_string (LexState *LS, YYSTYPE *l)
}
continue;
case '\n':
- save(LS, '\n');
+ save('\n');
inclinenumber(LS);
continue;
default:
@@ -251,9 +244,9 @@ static int read_long_string (LexState *LS, YYSTYPE *l)
}
} endloop:
save_and_next(LS); /* pass the second ']' */
- LS->textbuff.text[LS->textbuff.tokensize-2] = 0; /* erases ']]' */
- l->pTStr = luaS_new(LS->textbuff.text+2);
- LS->textbuff.text[LS->textbuff.tokensize-2] = ']'; /* restores ']]' */
+ L->Mbuffer[L->Mbuffnext-2] = 0; /* erases ']]' */
+ l->pTStr = luaS_new(L->Mbuffbase+2);
+ L->Mbuffer[L->Mbuffnext-2] = ']'; /* restores ']]' */
return STRING;
}
@@ -267,7 +260,7 @@ int luaY_lex (YYSTYPE *l)
{
LexState *LS = L->lexstate;
double a;
- LS->textbuff.tokensize = 0;
+ luaL_resetbuffer();
if (lua_debug)
luaY_codedebugline(LS->linelasttoken);
LS->linelasttoken = LS->linenumber;
@@ -286,7 +279,7 @@ int luaY_lex (YYSTYPE *l)
save_and_next(LS);
if (LS->current != '-') return '-';
do { next(LS); } while (LS->current != '\n' && LS->current != EOZ);
- LS->textbuff.tokensize = 0;
+ luaL_resetbuffer();
continue;
case '[':
@@ -325,15 +318,15 @@ int luaY_lex (YYSTYPE *l)
switch (LS->current) {
case EOZ:
case '\n':
- save(LS, 0);
+ save(0);
return WRONGTOKEN;
case '\\':
next(LS); /* do not save the '\' */
switch (LS->current) {
- case 'n': save(LS, '\n'); next(LS); break;
- case 't': save(LS, '\t'); next(LS); break;
- case 'r': save(LS, '\r'); next(LS); break;
- case '\n': save(LS, '\n'); inclinenumber(LS); break;
+ case 'n': save('\n'); next(LS); break;
+ case 't': save('\t'); next(LS); break;
+ case 'r': save('\r'); next(LS); break;
+ case '\n': save('\n'); inclinenumber(LS); break;
default : save_and_next(LS); break;
}
break;
@@ -342,9 +335,9 @@ int luaY_lex (YYSTYPE *l)
}
}
next(LS); /* skip delimiter */
- save(LS, 0);
- l->pTStr = luaS_new(LS->textbuff.text+1);
- LS->textbuff.text[LS->textbuff.tokensize-1] = del; /* restore delimiter */
+ save(0);
+ l->pTStr = luaS_new(L->Mbuffbase+1);
+ L->Mbuffer[L->Mbuffnext-1] = del; /* restore delimiter */
return STRING;
}
@@ -375,7 +368,7 @@ int luaY_lex (YYSTYPE *l)
if (LS->current == '.') {
save_and_next(LS);
if (LS->current == '.') {
- save(LS, 0);
+ save(0);
luaY_error(
"ambiguous syntax (decimal point x string concatenation)");
}
@@ -396,7 +389,7 @@ int luaY_lex (YYSTYPE *l)
neg=(LS->current=='-');
if (LS->current == '+' || LS->current == '-') save_and_next(LS);
if (!isdigit(LS->current)) {
- save(LS, 0); return WRONGTOKEN; }
+ save(0); return WRONGTOKEN; }
do {
e=10.0*e+(LS->current-'0');
save_and_next(LS);
@@ -412,23 +405,24 @@ int luaY_lex (YYSTYPE *l)
}
case EOZ:
- save(LS, 0);
+ save(0);
if (LS->iflevel > 0)
luaY_syntaxerror("input ends inside a $if", "");
return 0;
default:
if (LS->current != '_' && !isalpha(LS->current)) {
+ int c = LS->current;
save_and_next(LS);
- return LS->textbuff.text[0];
+ return c;
}
else { /* identifier or reserved word */
TaggedString *ts;
do {
save_and_next(LS);
} while (isalnum(LS->current) || LS->current == '_');
- save(LS, 0);
- ts = luaS_new(LS->textbuff.text);
+ save(0);
+ ts = luaS_new(L->Mbuffbase);
if (ts->head.marked > 255)
return ts->head.marked; /* reserved word */
l->pTStr = ts;
diff --git a/llex.h b/llex.h
index eba9c351..7ebfa378 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
/*
-** $Id: llex.h,v 1.4 1997/11/26 18:53:45 roberto Exp roberto $
+** $Id: llex.h,v 1.5 1997/12/02 12:43:44 roberto Exp roberto $
** Lexical Analizer
** See Copyright Notice in lua.h
*/
@@ -21,18 +21,11 @@ struct ifState {
int skip; /* true if part must be skiped */
};
-struct textBuff {
- char *text; /* always points to luaM_buffer */
- int tokensize;
- int buffsize;
-};
-
typedef struct LexState {
int current; /* look ahead character */
struct zio *lex_z; /* input stream */
int linenumber; /* input line counter */
- struct textBuff textbuff; /* buffer for tokens */
int linelasttoken; /* line where last token was read */
int lastline; /* last line wherein a SETLINE was generated */
struct ifState ifstate[MAX_IFS];
diff --git a/lmem.c b/lmem.c
index 069c4d0d..15ea9fc3 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.c,v 1.2 1997/11/19 17:29:23 roberto Exp roberto $
+** $Id: lmem.c,v 1.3 1997/12/01 20:30:44 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -27,23 +27,6 @@ int luaM_growaux (void **block, unsigned long nelems, int size,
-void *luaM_buffer (unsigned long size)
-{
- if (size > L->Mbuffsize) {
- L->Mbuffsize = size;
- L->Mbuffer = luaM_realloc(L->Mbuffer, L->Mbuffsize);
- }
- return L->Mbuffer;
-}
-
-
-void luaM_clearbuffer (void)
-{
- L->Mbuffsize /= 2;
- L->Mbuffer = luaM_realloc(L->Mbuffer, L->Mbuffsize);
-}
-
-
#ifndef DEBUG
/*
diff --git a/lmem.h b/lmem.h
index ac7ba9ae..94e81515 100644
--- a/lmem.h
+++ b/lmem.h
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.h,v 1.3 1997/11/26 20:44:52 roberto Exp roberto $
+** $Id: lmem.h,v 1.4 1997/12/01 20:30:44 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -20,8 +20,6 @@
#define tableEM "table overflow"
#define memEM "not enough memory"
-void *luaM_buffer (unsigned long size);
-void luaM_clearbuffer (void);
void *luaM_realloc (void *oldblock, unsigned long size);
int luaM_growaux (void **block, unsigned long nelems, int size,
char *errormsg, unsigned long limit);
diff --git a/lstate.c b/lstate.c
index e1011a1a..c1a1b43d 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.c,v 1.3 1997/12/01 20:31:25 roberto Exp roberto $
+** $Id: lstate.c,v 1.4 1997/12/11 14:48:46 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -40,6 +40,8 @@ void lua_open (void)
L->refArray = NULL;
L->refSize = 0;
L->Mbuffsize = 0;
+ L->Mbuffnext = 0;
+ L->Mbuffbase = NULL;
L->Mbuffer = NULL;
L->GCthreshold = GARBAGE_BLOCK;
L->nblocks = 0;
diff --git a/lstate.h b/lstate.h
index 9388b444..3da2e2ef 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.4 1997/11/27 15:59:25 roberto Exp roberto $
+** $Id: lstate.h,v 1.5 1997/11/28 16:56:05 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -65,8 +65,10 @@ typedef struct LState {
int refSize; /* size of refArray */
unsigned long GCthreshold;
unsigned long nblocks; /* number of 'blocks' currently allocated */
- char *Mbuffer; /* global buffer, used by luaM_buffer */
- unsigned long Mbuffsize; /* size of Mbuffer */
+ char *Mbuffer; /* global buffer */
+ char *Mbuffbase; /* current first position of Mbuffer */
+ int Mbuffsize; /* size of Mbuffer */
+ int Mbuffnext; /* next position to fill in Mbuffer */
} LState;
diff --git a/lstrlib.c b/lstrlib.c
index 9f1ae82d..cca70bc5 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.3 1997/12/09 13:35:19 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.4 1997/12/15 17:58:49 roberto Exp roberto $
** Standard library for strings and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -15,56 +15,12 @@
#include "lualib.h"
-struct lbuff {
- char *b;
- size_t max;
- size_t size;
-};
-
-static struct lbuff lbuffer = {NULL, 0, 0};
-
-
-static char *strbuffer (unsigned long size)
-{
- if (size > lbuffer.max) {
- /* ANSI "realloc" doesn't need this test, but some machines (Sun!)
- don't follow ANSI */
- lbuffer.b = (lbuffer.b) ? realloc(lbuffer.b, lbuffer.max=size) :
- malloc(lbuffer.max=size);
- if (lbuffer.b == NULL)
- lua_error("memory overflow");
- }
- return lbuffer.b;
-}
-
-
-static char *openspace (unsigned long size)
-{
- char *buff = strbuffer(lbuffer.size+size);
- return buff+lbuffer.size;
-}
-
-
-char *luaI_addchar (int c)
-{
- if (lbuffer.size >= lbuffer.max)
- strbuffer(lbuffer.max == 0 ? 100 : lbuffer.max*2);
- lbuffer.b[lbuffer.size++] = c;
- return lbuffer.b;
-}
-
-
-void luaI_emptybuff (void)
-{
- lbuffer.size = 0; /* prepare for next string */
-}
-
static void addnchar (char *s, int n)
{
- char *b = openspace(n);
+ char *b = luaL_openspace(n);
strncpy(b, s, n);
- lbuffer.size += n;
+ luaL_addsize(n);
}
@@ -80,6 +36,13 @@ static void str_len (void)
}
+static void closeandpush (void)
+{
+ luaL_addchar(0);
+ lua_pushstring(luaL_buffer());
+}
+
+
static void str_sub (void)
{
char *s = luaL_check_string(1);
@@ -89,9 +52,9 @@ static void str_sub (void)
if (start < 0) start = l+start+1;
if (end < 0) end = l+end+1;
if (1 <= start && start <= end && end <= l) {
- luaI_emptybuff();
+ luaL_resetbuffer();
addnchar(s+start-1, end-start+1);
- lua_pushstring(luaI_addchar(0));
+ closeandpush();
}
else lua_pushstring("");
}
@@ -100,30 +63,30 @@ static void str_sub (void)
static void str_lower (void)
{
char *s;
- luaI_emptybuff();
+ luaL_resetbuffer();
for (s = luaL_check_string(1); *s; s++)
- luaI_addchar(tolower((unsigned char)*s));
- lua_pushstring(luaI_addchar(0));
+ luaL_addchar(tolower((unsigned char)*s));
+ closeandpush();
}
static void str_upper (void)
{
char *s;
- luaI_emptybuff();
+ luaL_resetbuffer();
for (s = luaL_check_string(1); *s; s++)
- luaI_addchar(toupper((unsigned char)*s));
- lua_pushstring(luaI_addchar(0));
+ luaL_addchar(toupper((unsigned char)*s));
+ closeandpush();
}
static void str_rep (void)
{
char *s = luaL_check_string(1);
int n = (int)luaL_check_number(2);
- luaI_emptybuff();
+ luaL_resetbuffer();
while (n-- > 0)
addstr(s);
- lua_pushstring(luaI_addchar(0));
+ closeandpush();
}
@@ -163,7 +126,7 @@ static void push_captures (struct Capture *cap)
int i;
for (i=0; i<cap->level; i++) {
int l = cap->capture[i].len;
- char *buff = openspace(l+1);
+ char *buff = luaL_openspace(l+1);
if (l == -1) lua_error("unfinished capture");
strncpy(buff, cap->capture[i].init, l);
buff[l] = 0;
@@ -395,7 +358,7 @@ static void add_s (lua_Object newp, struct Capture *cap)
char *news = lua_getstring(newp);
while (*news) {
if (*news != ESC || !isdigit((unsigned char)*++news))
- luaI_addchar(*news++);
+ luaL_addchar(*news++);
else {
int l = check_cap(*news++, cap);
addnchar(cap->capture[l].init, cap->capture[l].len);
@@ -404,24 +367,24 @@ static void add_s (lua_Object newp, struct Capture *cap)
}
else if (lua_isfunction(newp)) {
lua_Object res;
- struct lbuff oldbuff;
int status;
+ int oldbuff;
lua_beginblock();
push_captures(cap);
- /* function may use lbuffer, so save it and create a luaM_new one */
- oldbuff = lbuffer;
- lbuffer.b = NULL; lbuffer.max = lbuffer.size = 0;
+ /* function may use buffer, so save it and create a new one */
+ oldbuff = luaL_newbuffer(0);
status = lua_callfunction(newp);
/* restore old buffer */
- free(lbuffer.b);
- lbuffer = oldbuff;
- if (status != 0)
+ luaL_oldbuffer(oldbuff);
+ if (status != 0) {
+ lua_endblock();
lua_error(NULL);
+ }
res = lua_getresult(1);
addstr(lua_isstring(res) ? lua_getstring(res) : "");
lua_endblock();
}
- else luaL_arg_check(0, 3, NULL);
+ else luaL_arg_check(0, 3, "string or function expected");
}
@@ -433,7 +396,7 @@ static void str_gsub (void)
int max_s = (int)luaL_opt_number(4, strlen(src)+1);
int anchor = (*p == '^') ? (p++, 1) : 0;
int n = 0;
- luaI_emptybuff();
+ luaL_resetbuffer();
while (n < max_s) {
struct Capture cap;
char *e;
@@ -446,25 +409,25 @@ static void str_gsub (void)
if (e && e>src) /* non empty match? */
src = e; /* skip it */
else if (*src)
- luaI_addchar(*src++);
+ luaL_addchar(*src++);
else break;
if (anchor) break;
}
addstr(src);
- lua_pushstring(luaI_addchar(0));
+ closeandpush();
lua_pushnumber(n); /* number of substitutions */
}
static void luaI_addquoted (char *s)
{
- luaI_addchar('"');
+ luaL_addchar('"');
for (; *s; s++) {
if (strchr("\"\\\n", *s))
- luaI_addchar('\\');
- luaI_addchar(*s);
+ luaL_addchar('\\');
+ luaL_addchar(*s);
}
- luaI_addchar('"');
+ luaL_addchar('"');
}
#define MAX_FORMAT 200
@@ -473,12 +436,12 @@ static void str_format (void)
{
int arg = 1;
char *strfrmt = luaL_check_string(arg);
- luaI_emptybuff(); /* initialize */
+ luaL_resetbuffer();
while (*strfrmt) {
if (*strfrmt != '%')
- luaI_addchar(*strfrmt++);
+ luaL_addchar(*strfrmt++);
else if (*++strfrmt == '%')
- luaI_addchar(*strfrmt++); /* %% */
+ luaL_addchar(*strfrmt++); /* %% */
else { /* format item */
char form[MAX_FORMAT]; /* store the format ('%...') */
struct Capture cap;
@@ -496,14 +459,14 @@ static void str_format (void)
arg++;
strncpy(form+1, initf, strfrmt-initf+1); /* +1 to include convertion */
form[strfrmt-initf+2] = 0;
- buff = openspace(1000); /* to store the formatted value */
+ buff = luaL_openspace(1000); /* to store the formatted value */
switch (*strfrmt++) {
case 'q':
luaI_addquoted(luaL_check_string(arg));
continue;
case 's': {
char *s = luaL_check_string(arg);
- buff = openspace(strlen(s));
+ buff = luaL_openspace(strlen(s));
sprintf(buff, form, s);
break;
}
@@ -517,10 +480,10 @@ static void str_format (void)
default: /* also treat cases 'pnLlh' */
lua_error("invalid option in `format'");
}
- lbuffer.size += strlen(buff);
+ luaL_addsize(strlen(buff));
}
}
- lua_pushstring(luaI_addchar(0)); /* push the result */
+ closeandpush(); /* push the result */
}
diff --git a/lualib.h b/lualib.h
index 9e9b0193..dabe8f7a 100644
--- a/lualib.h
+++ b/lualib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lualib.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
+** $Id: lualib.h,v 1.2 1997/11/26 18:53:45 roberto Exp roberto $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
@@ -28,9 +28,6 @@ void lua_mathlibopen (void);
/* auxiliar functions (private) */
-char *luaI_addchar (int c);
-void luaI_emptybuff (void);
-
int luaI_singlematch (int c, char *p, char **ep);
#endif
diff --git a/lvm.c b/lvm.c
index 7cf995f1..5e160f71 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.16 1997/12/09 13:35:19 roberto Exp roberto $
+** $Id: lvm.c,v 1.17 1997/12/15 16:17:20 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -27,7 +27,7 @@
#define next_word(pc) (pc+=2, get_word(pc-2))
-/* Extra stack to run a function: LUA_T_LINE(1), TM calls(2), ... */
+/* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */
#define EXTRA_STACK 5
@@ -35,7 +35,7 @@
static TaggedString *strconc (char *l, char *r)
{
size_t nl = strlen(l);
- char *buffer = luaM_buffer(nl+strlen(r)+1);
+ char *buffer = luaL_openspace(nl+strlen(r)+1);
strcpy(buffer, l);
strcpy(buffer+nl, r);
return luaS_new(buffer);
diff --git a/makefile b/makefile
index 234cf701..9e450230 100644
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
#
-## $Id: makefile,v 1.5 1997/11/07 15:09:49 roberto Exp roberto $
+## $Id: makefile,v 1.6 1997/11/19 17:29:23 roberto Exp roberto $
## Makefile
## See Copyright Notice in lua.h
#
@@ -94,7 +94,8 @@ clear :
lapi.o: lapi.c lapi.h lua.h lobject.h lauxlib.h ldo.h lstate.h lfunc.h \
lgc.h lmem.h lstring.h ltable.h ltm.h luadebug.h lvm.h
-lauxlib.o: lauxlib.c lauxlib.h lua.h luadebug.h
+lauxlib.o: lauxlib.c lauxlib.h lua.h lmem.h lstate.h lobject.h \
+ luadebug.h
lbuiltin.o: lbuiltin.c lapi.h lua.h lobject.h lauxlib.h lbuiltin.h \
ldo.h lstate.h lfunc.h lmem.h lstring.h ltable.h ltm.h
ldo.o: ldo.c ldo.h lobject.h lua.h lstate.h lfunc.h lgc.h lmem.h \
@@ -103,13 +104,13 @@ lfunc.o: lfunc.c lfunc.h lobject.h lua.h lmem.h lstate.h
lgc.o: lgc.c ldo.h lobject.h lua.h lstate.h lfunc.h lgc.h lmem.h \
lstring.h ltable.h ltm.h
liolib.o: liolib.c lauxlib.h lua.h luadebug.h lualib.h
-llex.o: llex.c llex.h lobject.h lua.h lzio.h lmem.h lparser.h lstate.h \
- lstring.h lstx.h luadebug.h
+llex.o: llex.c lauxlib.h lua.h llex.h lobject.h lzio.h lmem.h \
+ lparser.h lstate.h lstring.h lstx.h luadebug.h
lmathlib.o: lmathlib.c lauxlib.h lua.h lualib.h
lmem.o: lmem.c lmem.h lstate.h lobject.h lua.h
lobject.o: lobject.c lobject.h lua.h
-lstate.o: lstate.c lbuiltin.h ldo.h lobject.h lua.h lstate.h llex.h \
- lzio.h lmem.h lstring.h ltable.h ltm.h
+lstate.o: lstate.c lbuiltin.h ldo.h lobject.h lua.h lstate.h lfunc.h \
+ lgc.h llex.h lzio.h lmem.h lstring.h ltable.h ltm.h
lstring.o: lstring.c lmem.h lobject.h lua.h lstate.h lstring.h
lstrlib.o: lstrlib.c lauxlib.h lua.h lualib.h
lstx.o: lstx.c lauxlib.h lua.h ldo.h lobject.h lstate.h lfunc.h llex.h \