1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

code cleaner for 16 bits.

This commit is contained in:
Roberto Ierusalimschy 2000-05-24 10:54:49 -03:00
parent 5c2dd7a9e0
commit ef62b340e0
31 changed files with 247 additions and 199 deletions

6
lapi.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 1.79 2000/05/08 19:32:53 roberto Exp roberto $ ** $Id: lapi.c,v 1.80 2000/05/08 20:49:05 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -250,7 +250,7 @@ const char *lua_getstring (lua_State *L, lua_Object obj) {
else return (svalue(obj)); else return (svalue(obj));
} }
long lua_strlen (lua_State *L, lua_Object obj) { size_t lua_strlen (lua_State *L, lua_Object obj) {
if (obj == LUA_NOOBJECT || tostring(L, obj)) if (obj == LUA_NOOBJECT || tostring(L, obj))
return 0L; return 0L;
else return (tsvalue(obj)->u.s.len); else return (tsvalue(obj)->u.s.len);
@ -281,7 +281,7 @@ void lua_pushnumber (lua_State *L, double n) {
incr_top; incr_top;
} }
void lua_pushlstring (lua_State *L, const char *s, long len) { void lua_pushlstring (lua_State *L, const char *s, size_t len) {
tsvalue(L->top) = luaS_newlstr(L, s, len); tsvalue(L->top) = luaS_newlstr(L, s, len);
ttype(L->top) = TAG_STRING; ttype(L->top) = TAG_STRING;
incr_top; incr_top;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.26 2000/02/08 16:34:31 roberto Exp roberto $ ** $Id: lauxlib.c,v 1.27 2000/03/30 17:19:48 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -51,18 +51,20 @@ static void type_error (lua_State *L, int narg, const char *type_name,
} }
static const char *checkstr (lua_State *L, lua_Object o, int narg, long *len) { static const char *checkstr (lua_State *L, lua_Object o, int narg,
size_t *len) {
const char *s = lua_getstring(L, o); const char *s = lua_getstring(L, o);
if (!s) type_error(L, narg, "string", o); if (!s) type_error(L, narg, "string", o);
if (len) *len = lua_strlen(L, o); if (len) *len = lua_strlen(L, o);
return s; return s;
} }
const char *luaL_check_lstr (lua_State *L, int narg, long *len) { const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
return checkstr(L, lua_getparam(L, narg), narg, len); return checkstr(L, lua_getparam(L, narg), narg, len);
} }
const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, long *len) { const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
size_t *len) {
lua_Object o = lua_getparam(L, narg); lua_Object o = lua_getparam(L, narg);
if (o == LUA_NOOBJECT) { if (o == LUA_NOOBJECT) {
if (len) *len = def ? strlen(def) : 0; if (len) *len = def ? strlen(def) : 0;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.h,v 1.16 1999/12/03 11:26:23 roberto Exp roberto $ ** $Id: lauxlib.h,v 1.17 1999/12/29 16:24:03 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -9,6 +9,8 @@
#define lauxlib_h #define lauxlib_h
#include <stddef.h>
#include "lua.h" #include "lua.h"
@ -20,26 +22,28 @@ struct luaL_reg {
void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n); void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n);
void luaL_argerror (lua_State *L, int numarg, const char *extramsg); void luaL_argerror (lua_State *L, int numarg, const char *extramsg);
const char *luaL_check_lstr (lua_State *L, int numArg, long *len); const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def, long *len); const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def,
size_t *len);
double luaL_check_number (lua_State *L, int numArg); double luaL_check_number (lua_State *L, int numArg);
double luaL_opt_number (lua_State *L, int numArg, double def); double luaL_opt_number (lua_State *L, int numArg, double def);
lua_Object luaL_functionarg (lua_State *L, int arg); lua_Object luaL_functionarg (lua_State *L, int arg);
lua_Object luaL_tablearg (lua_State *L, int arg); lua_Object luaL_tablearg (lua_State *L, int arg);
lua_Object luaL_nonnullarg (lua_State *L, int numArg); lua_Object luaL_nonnullarg (lua_State *L, int numArg);
void luaL_verror (lua_State *L, const char *fmt, ...); void luaL_verror (lua_State *L, const char *fmt, ...);
char *luaL_openspace (lua_State *L, int size);
void luaL_resetbuffer (lua_State *L);
void luaL_addchar (lua_State *L, int c);
int luaL_getsize (lua_State *L);
void luaL_addsize (lua_State *L, int n);
int luaL_newbuffer (lua_State *L, int size);
void luaL_oldbuffer (lua_State *L, int old);
char *luaL_buffer (lua_State *L);
int luaL_findstring (const char *name, const char *const list[]); int luaL_findstring (const char *name, const char *const list[]);
void luaL_chunkid (char *out, const char *source, int len); void luaL_chunkid (char *out, const char *source, int len);
void luaL_filesource (char *out, const char *filename, int len); void luaL_filesource (char *out, const char *filename, int len);
char *luaL_openspace (lua_State *L, size_t size);
void luaL_resetbuffer (lua_State *L);
void luaL_addchar (lua_State *L, int c);
size_t luaL_getsize (lua_State *L);
void luaL_addsize (lua_State *L, size_t n);
size_t luaL_newbuffer (lua_State *L, size_t size);
void luaL_oldbuffer (lua_State *L, size_t old);
char *luaL_buffer (lua_State *L);
#ifdef LUA_REENTRANT #ifdef LUA_REENTRANT

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbuffer.c,v 1.11 1999/11/22 13:12:07 roberto Exp roberto $ ** $Id: lbuffer.c,v 1.12 2000/03/03 14:58:26 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -25,16 +25,17 @@
#define EXTRABUFF 32 #define EXTRABUFF 32
#define openspace(L, size) if (L->Mbuffnext+(size) > L->Mbuffsize) \ #define openspace(L, size) if ((size_t)(size) > L->Mbuffsize-L->Mbuffnext) \
Openspace(L, size) Openspace(L, size)
static void Openspace (lua_State *L, int size) { static void Openspace (lua_State *L, size_t size) {
L->Mbuffsize = (L->Mbuffnext+size+EXTRABUFF)*2; lint32 newsize = ((lint32)L->Mbuffnext+size+EXTRABUFF)*2;
luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char); luaM_reallocvector(L, L->Mbuffer, newsize, char);
L->Mbuffsize = newsize;
} }
char *luaL_openspace (lua_State *L, int size) { char *luaL_openspace (lua_State *L, size_t size) {
openspace(L, size); openspace(L, size);
return L->Mbuffer+L->Mbuffnext; return L->Mbuffer+L->Mbuffnext;
} }
@ -51,23 +52,23 @@ void luaL_resetbuffer (lua_State *L) {
} }
void luaL_addsize (lua_State *L, int n) { void luaL_addsize (lua_State *L, size_t n) {
L->Mbuffnext += n; L->Mbuffnext += n;
} }
int luaL_getsize (lua_State *L) { size_t luaL_getsize (lua_State *L) {
return L->Mbuffnext-L->Mbuffbase; return L->Mbuffnext-L->Mbuffbase;
} }
int luaL_newbuffer (lua_State *L, int size) { size_t luaL_newbuffer (lua_State *L, size_t size) {
int old = L->Mbuffbase; size_t old = L->Mbuffbase;
openspace(L, size); openspace(L, size);
L->Mbuffbase = L->Mbuffnext; L->Mbuffbase = L->Mbuffnext;
return old; return old;
} }
void luaL_oldbuffer (lua_State *L, int old) { void luaL_oldbuffer (lua_State *L, size_t old) {
L->Mbuffnext = L->Mbuffbase; L->Mbuffnext = L->Mbuffbase;
L->Mbuffbase = old; L->Mbuffbase = old;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbuiltin.c,v 1.108 2000/05/08 19:32:53 roberto Exp roberto $ ** $Id: lbuiltin.c,v 1.109 2000/05/09 14:50:16 roberto Exp roberto $
** Built-in functions ** Built-in functions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -273,7 +273,7 @@ static void passresults (lua_State *L) {
} }
void luaB_dostring (lua_State *L) { void luaB_dostring (lua_State *L) {
long l; size_t l;
const char *s = luaL_check_lstr(L, 1, &l); const char *s = luaL_check_lstr(L, 1, &l);
if (*s == ID_CHUNK) if (*s == ID_CHUNK)
lua_error(L, "`dostring' cannot run pre-compiled code"); lua_error(L, "`dostring' cannot run pre-compiled code");
@ -633,7 +633,6 @@ static const struct luaL_reg builtin_funcs[] = {
void luaB_predefine (lua_State *L) { void luaB_predefine (lua_State *L) {
/* pre-register mem error messages, to avoid loop when error arises */ /* pre-register mem error messages, to avoid loop when error arises */
luaS_newfixed(L, tableEM);
luaS_newfixed(L, memEM); luaS_newfixed(L, memEM);
luaL_openl(L, builtin_funcs); luaL_openl(L, builtin_funcs);
#ifdef DEBUG #ifdef DEBUG

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 1.30 2000/05/15 19:48:04 roberto Exp roberto $ ** $Id: lcode.c,v 1.31 2000/05/22 18:44:46 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -107,7 +107,8 @@ static int real_constant (FuncState *fs, Number r) {
while (--c >= lim) while (--c >= lim)
if (f->knum[c] == r) return c; if (f->knum[c] == r) return c;
/* not found; create a new entry */ /* not found; create a new entry */
luaM_growvector(fs->L, f->knum, f->nknum, 1, Number, constantEM, MAXARG_U); luaM_growvector(fs->L, f->knum, f->nknum, 1, Number,
"constant table overflow", MAXARG_U);
c = f->nknum++; c = f->nknum++;
f->knum[c] = r; f->knum[c] = r;
return c; return c;
@ -567,7 +568,8 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
case iAB: i = CREATE_AB(o, arg1, arg2); break; case iAB: i = CREATE_AB(o, arg1, arg2); break;
} }
/* actually create the new instruction */ /* actually create the new instruction */
luaM_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction, codeEM, MAX_INT); luaM_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction,
"code size overflow", MAX_INT);
fs->f->code[fs->pc] = i; fs->f->code[fs->pc] = i;
return fs->pc++; return fs->pc++;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldblib.c,v 1.14 2000/05/08 13:21:35 roberto Exp roberto $ ** $Id: ldblib.c,v 1.15 2000/05/12 19:49:18 roberto Exp roberto $
** Interface from Lua to its debug API ** Interface from Lua to its debug API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -49,7 +49,7 @@ static void getinfo (lua_State *L) {
const char *options = luaL_opt_string(L, 2, "flnSu"); const char *options = luaL_opt_string(L, 2, "flnSu");
char buff[20]; char buff[20];
if (lua_isnumber(L, func)) { if (lua_isnumber(L, func)) {
if (!lua_getstack(L, lua_getnumber(L, func), &ar)) { if (!lua_getstack(L, (int)lua_getnumber(L, func), &ar)) {
lua_pushnil(L); /* level out of range */ lua_pushnil(L); /* level out of range */
return; return;
} }

9
ldo.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 1.74 2000/05/08 19:32:53 roberto Exp roberto $ ** $Id: ldo.c,v 1.75 2000/05/09 14:50:16 roberto Exp roberto $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -311,7 +311,9 @@ static int do_main (lua_State *L, ZIO *z, int bin) {
int status; int status;
int debug = L->debug; /* save debug status */ int debug = L->debug; /* save debug status */
do { do {
long old_blocks = (luaC_checkGC(L), L->nblocks); unsigned long old_blocks;
luaC_checkGC(L);
old_blocks = L->nblocks;
status = protectedparser(L, z, bin); status = protectedparser(L, z, bin);
if (status == 1) return 1; /* error */ if (status == 1) return 1; /* error */
else if (status == 2) return 0; /* `natural' end */ else if (status == 2) return 0; /* `natural' end */
@ -358,7 +360,8 @@ int lua_dostring (lua_State *L, const char *str) {
} }
int lua_dobuffer (lua_State *L, const char *buff, int size, const char *name) { int lua_dobuffer (lua_State *L, const char *buff, size_t size,
const char *name) {
ZIO z; ZIO z;
if (!name) name = "?"; if (!name) name = "?";
luaZ_mopen(&z, buff, size, name); luaZ_mopen(&z, buff, size, name);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.c,v 1.20 2000/03/10 18:37:44 roberto Exp roberto $ ** $Id: lfunc.c,v 1.21 2000/03/29 20:19:20 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -20,7 +20,7 @@
Closure *luaF_newclosure (lua_State *L, int nelems) { Closure *luaF_newclosure (lua_State *L, int nelems) {
Closure *c = (Closure *)luaM_malloc(L, sizeof(Closure) + Closure *c = (Closure *)luaM_malloc(L, sizeof(Closure) +
sizeof(TObject)*(nelems-1)); (lint32)sizeof(TObject)*(nelems-1));
c->next = L->rootcl; c->next = L->rootcl;
L->rootcl = c; L->rootcl = c;
c->marked = 0; c->marked = 0;

4
lgc.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 1.49 2000/05/10 16:33:20 roberto Exp roberto $ ** $Id: lgc.c,v 1.50 2000/05/11 18:57:19 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -193,7 +193,7 @@ static void collectstringtab (lua_State *L, int limit, stringtable *tb) {
} }
} }
} }
if (tb->nuse < (tb->size/4) && tb->size > 10) if (tb->nuse < (lint32)(tb->size/4) && tb->size > 10)
luaS_resize(L, tb, tb->size/2); /* table is too big */ luaS_resize(L, tb, tb->size/2); /* table is too big */
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 1.62 2000/04/24 21:05:11 roberto Exp roberto $ ** $Id: liolib.c,v 1.63 2000/05/09 14:50:16 roberto Exp roberto $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -322,19 +322,23 @@ static void read_word (lua_State *L, FILE *f) {
static int read_line (lua_State *L, FILE *f) { static int read_line (lua_State *L, FILE *f) {
int n; int n;
char *b; char *b;
do { for (;;) {
b = luaL_openspace(L, HUNK_LINE); b = luaL_openspace(L, HUNK_LINE);
if (!fgets(b, HUNK_LINE, f)) return 0; /* read fails */ if (!fgets(b, HUNK_LINE, f)) return 0; /* read fails */
n = strlen(b); n = strlen(b);
luaL_addsize(L, n); if (b[n-1] != '\n')
} while (b[n-1] != '\n'); luaL_addsize(L, n);
luaL_addsize(L, -1); /* remove '\n' */ else {
luaL_addsize(L, n-1); /* do not add the `\n' */
break;
}
}
return 1; return 1;
} }
static void read_file (lua_State *L, FILE *f) { static void read_file (lua_State *L, FILE *f) {
int n; size_t n;
do { do {
char *b = luaL_openspace(L, HUNK_FILE); char *b = luaL_openspace(L, HUNK_FILE);
n = fread(b, sizeof(char), HUNK_FILE, f); n = fread(b, sizeof(char), HUNK_FILE, f);
@ -343,9 +347,9 @@ static void read_file (lua_State *L, FILE *f) {
} }
static int read_chars (lua_State *L, FILE *f, int n) { static int read_chars (lua_State *L, FILE *f, size_t n) {
char *b = luaL_openspace(L, n); char *b = luaL_openspace(L, n);
int n1 = fread(b, sizeof(char), n, f); size_t n1 = fread(b, sizeof(char), n, f);
luaL_addsize(L, n1); luaL_addsize(L, n1);
return (n == n1); return (n == n1);
} }
@ -357,11 +361,11 @@ static void io_read (lua_State *L) {
FILE *f = getfileparam(L, ctrl, &arg, INFILE); FILE *f = getfileparam(L, ctrl, &arg, INFILE);
lua_Object op = lua_getparam(L, arg); lua_Object op = lua_getparam(L, arg);
do { /* repeat for each part */ do { /* repeat for each part */
long l; size_t l;
int success; int success;
luaL_resetbuffer(L); luaL_resetbuffer(L);
if (lua_isnumber(L, op)) if (lua_isnumber(L, op))
success = read_chars(L, f, (int)lua_getnumber(L, op)); success = read_chars(L, f, (size_t)lua_getnumber(L, op));
else { else {
const char *p = luaL_opt_string(L, arg, "*l"); const char *p = luaL_opt_string(L, arg, "*l");
if (p[0] != '*') if (p[0] != '*')
@ -409,9 +413,9 @@ static void io_write (lua_State *L) {
status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0; status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0;
} }
else { else {
long l; size_t l;
const char *s = luaL_check_lstr(L, arg, &l); const char *s = luaL_check_lstr(L, arg, &l);
status = status && ((long)fwrite(s, sizeof(char), l, f) == l); status = status && (fwrite(s, sizeof(char), l, f) == l);
} }
arg++; arg++;
} }

13
llex.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 1.57 2000/04/12 18:57:19 roberto Exp roberto $ ** $Id: llex.c,v 1.58 2000/05/08 19:32:53 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -49,6 +49,16 @@ void luaX_init (lua_State *L) {
#define MAXSRC 80 #define MAXSRC 80
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
if (val > limit) {
char buff[100];
sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
luaX_error(ls, buff, ls->token);
}
}
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
char buff[MAXSRC]; char buff[MAXSRC];
luaL_chunkid(buff, zname(ls->z), sizeof(buff)); luaL_chunkid(buff, zname(ls->z), sizeof(buff));
@ -175,6 +185,7 @@ static void inclinenumber (lua_State *L, LexState *LS) {
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL}; {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
next(LS); /* skip '\n' */ next(LS); /* skip '\n' */
++LS->linenumber; ++LS->linenumber;
luaX_checklimit(LS, LS->linenumber, MAX_INT, "lines in a chunk");
if (LS->current == '$') { /* is a pragma? */ if (LS->current == '$') { /* is a pragma? */
char buff[PRAGMASIZE+1]; char buff[PRAGMASIZE+1];
int ifnot = 0; int ifnot = 0;

3
llex.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.23 2000/04/07 13:11:49 roberto Exp roberto $ ** $Id: llex.h,v 1.24 2000/04/12 18:57:19 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -63,6 +63,7 @@ typedef struct LexState {
void luaX_init (lua_State *L); void luaX_init (lua_State *L);
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z); void luaX_setinput (lua_State *L, LexState *LS, ZIO *z);
int luaX_lex (LexState *LS); int luaX_lex (LexState *LS);
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
void luaX_syntaxerror (LexState *ls, const char *s, const char *token); void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
void luaX_error (LexState *ls, const char *s, int token); void luaX_error (LexState *ls, const char *s, int token);
void luaX_token2str (int token, char *s); void luaX_token2str (int token, char *s);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: llimits.h,v 1.5 2000/04/04 20:48:44 roberto Exp roberto $ ** $Id: llimits.h,v 1.6 2000/04/26 13:43:25 roberto Exp roberto $
** Limits, basic types, and some other "instalation-dependent" definitions ** Limits, basic types, and some other "instalation-dependent" definitions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -9,6 +9,7 @@
#include <limits.h> #include <limits.h>
#include <stddef.h>
/* /*
@ -22,6 +23,11 @@
typedef LUA_NUM_TYPE Number; typedef LUA_NUM_TYPE Number;
typedef unsigned long lint32; /* unsigned int with at least 32 bits */
#define MAX_SIZET ((size_t)(~0)-2)
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */

15
lmem.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lmem.c,v 1.28 2000/03/10 18:37:44 roberto Exp roberto $ ** $Id: lmem.c,v 1.29 2000/03/16 20:35:07 roberto Exp roberto $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -88,6 +88,7 @@ static void *debug_realloc (void *block, size_t size) {
size_t realsize = HEADER+size+MARKSIZE; size_t realsize = HEADER+size+MARKSIZE;
char *newblock = (char *)(malloc)(realsize); /* alloc a new block */ char *newblock = (char *)(malloc)(realsize); /* alloc a new block */
int i; int i;
if (realsize < size) return NULL; /* overflow! */
if (newblock == NULL) return NULL; if (newblock == NULL) return NULL;
if (block) { if (block) {
size_t oldsize = *blocksize(block); size_t oldsize = *blocksize(block);
@ -111,10 +112,10 @@ static void *debug_realloc (void *block, size_t size) {
void *luaM_growaux (lua_State *L, void *block, unsigned long nelems, void *luaM_growaux (lua_State *L, void *block, size_t nelems,
int inc, int size, const char *errormsg, unsigned long limit) { int inc, size_t size, const char *errormsg, size_t limit) {
unsigned long newn = nelems+inc; size_t newn = nelems+inc;
if (newn >= limit) lua_error(L, errormsg); if (nelems >= limit-inc) lua_error(L, errormsg);
if ((newn ^ nelems) <= nelems || /* still the same power-of-2 limit? */ if ((newn ^ nelems) <= nelems || /* still the same power-of-2 limit? */
(nelems > 0 && newn < MINPOWER2)) /* or block already is MINPOWER2? */ (nelems > 0 && newn < MINPOWER2)) /* or block already is MINPOWER2? */
return block; /* do not need to reallocate */ return block; /* do not need to reallocate */
@ -126,12 +127,12 @@ void *luaM_growaux (lua_State *L, void *block, unsigned long nelems,
/* /*
** generic allocation routine. ** generic allocation routine.
*/ */
void *luaM_realloc (lua_State *L, void *block, unsigned long size) { void *luaM_realloc (lua_State *L, void *block, lint32 size) {
if (size == 0) { if (size == 0) {
free(block); /* block may be NULL; that is OK for free */ free(block); /* block may be NULL; that is OK for free */
return NULL; return NULL;
} }
else if ((size_t)size != size) else if (size >= MAX_SIZET)
lua_error(L, "memory allocation error: block too big"); lua_error(L, "memory allocation error: block too big");
block = realloc(block, size); block = realloc(block, size);
if (block == NULL) if (block == NULL)

28
lmem.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lmem.h,v 1.12 2000/01/13 16:30:47 roberto Exp roberto $ ** $Id: lmem.h,v 1.13 2000/03/16 20:35:07 roberto Exp roberto $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -8,29 +8,29 @@
#define lmem_h #define lmem_h
#include <stdlib.h> #include <stddef.h>
#include "llimits.h"
#include "lua.h" #include "lua.h"
/* memory error messages */ /* memory error message */
#define codeEM "code size overflow"
#define constantEM "constant table overflow"
#define refEM "reference table overflow"
#define tableEM "table overflow"
#define memEM "not enough memory" #define memEM "not enough memory"
#define arrEM "internal array larger than `int' limit"
void *luaM_realloc (lua_State *L, void *oldblock, unsigned long size); void *luaM_realloc (lua_State *L, void *oldblock, lint32 size);
void *luaM_growaux (lua_State *L, void *block, unsigned long nelems, int inc, int size, void *luaM_growaux (lua_State *L, void *block, size_t nelems,
const char *errormsg, unsigned long limit); int inc, size_t size, const char *errormsg,
size_t limit);
#define luaM_free(L, b) luaM_realloc(L, (b), 0) #define luaM_free(L, b) luaM_realloc(L, (b), 0)
#define luaM_malloc(L, t) luaM_realloc(L, NULL, (t)) #define luaM_malloc(L, t) luaM_realloc(L, NULL, (t))
#define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t)))
#define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*sizeof(t))) #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*(lint32)sizeof(t)))
#define luaM_growvector(L, v,nelems,inc,t,e,l) \ #define luaM_growvector(L, v,nelems,inc,t,e,l) \
((v)=(t *)luaM_growaux(L, v,nelems,inc,sizeof(t),e,l)) ((v)=(t *)luaM_growaux(L, v,nelems,inc,sizeof(t),e,l))
#define luaM_reallocvector(L, v,n,t) ((v)=(t *)luaM_realloc(L, v,(n)*sizeof(t)))
#define luaM_reallocvector(L, v,n,t) \
((v)=(t *)luaM_realloc(L, v,(n)*(lint32)sizeof(t)))
#ifdef DEBUG #ifdef DEBUG

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.c,v 1.37 2000/04/25 16:55:09 roberto Exp roberto $ ** $Id: lobject.c,v 1.38 2000/04/26 13:43:10 roberto Exp roberto $
** Some generic functions over Lua objects ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -25,8 +25,8 @@ const TObject luaO_nilobject = {TAG_NIL, {NULL}};
/* /*
** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) ** returns smaller power of 2 larger than `n' (minimum is MINPOWER2)
*/ */
unsigned long luaO_power2 (unsigned long n) { lint32 luaO_power2 (lint32 n) {
unsigned long p = MINPOWER2; lint32 p = MINPOWER2;
while (p<=n) p<<=1; while (p<=n) p<<=1;
return p; return p;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 1.63 2000/05/08 19:37:10 roberto Exp roberto $ ** $Id: lobject.h,v 1.64 2000/05/10 16:33:20 roberto Exp roberto $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -92,7 +92,7 @@ typedef struct TString {
union { union {
struct { /* for strings */ struct { /* for strings */
unsigned long hash; unsigned long hash;
long len; size_t len;
int constindex; /* hint to reuse constants */ int constindex; /* hint to reuse constants */
} s; } s;
struct { /* for userdata */ struct { /* for userdata */
@ -170,10 +170,9 @@ extern const TObject luaO_nilobject;
#define luaO_typename(o) luaO_typenames[ttype(o)] #define luaO_typename(o) luaO_typenames[ttype(o)]
unsigned long luaO_power2 (unsigned long n); lint32 luaO_power2 (lint32 n);
int luaO_equalObj (const TObject *t1, const TObject *t2); int luaO_equalObj (const TObject *t1, const TObject *t2);
int luaO_redimension (lua_State *L, int oldsize);
int luaO_str2d (const char *s, Number *result); int luaO_str2d (const char *s, Number *result);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 1.87 2000/05/15 19:48:04 roberto Exp roberto $ ** $Id: lparser.c,v 1.88 2000/05/22 18:44:46 roberto Exp roberto $
** LL(1) Parser and code generator for Lua ** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -79,19 +79,10 @@ static void check (LexState *ls, int c) {
} }
static void checklimit (LexState *ls, int val, int limit, const char *msg) {
if (val > limit) {
char buff[100];
sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
luaK_error(ls, buff);
}
}
static void setline (LexState *ls) { static void setline (LexState *ls) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
if (ls->L->debug && ls->linenumber != fs->lastsetline) { if (ls->L->debug && ls->linenumber != fs->lastsetline) {
checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk"); luaX_checklimit(ls, ls->linenumber, MAXARG_U, "lines in a chunk");
luaK_code1(fs, OP_SETLINE, ls->linenumber); luaK_code1(fs, OP_SETLINE, ls->linenumber);
fs->lastsetline = ls->linenumber; fs->lastsetline = ls->linenumber;
} }
@ -142,7 +133,7 @@ static int string_constant (FuncState *fs, TString *s) {
int c = s->u.s.constindex; int c = s->u.s.constindex;
if (c >= f->nkstr || f->kstr[c] != s) { if (c >= f->nkstr || f->kstr[c] != s) {
luaM_growvector(fs->L, f->kstr, f->nkstr, 1, TString *, luaM_growvector(fs->L, f->kstr, f->nkstr, 1, TString *,
constantEM, MAXARG_U); "constant table overflow", MAXARG_U);
c = f->nkstr++; c = f->nkstr++;
f->kstr[c] = s; f->kstr[c] = s;
s->u.s.constindex = c; /* hint for next time */ s->u.s.constindex = c; /* hint for next time */
@ -200,7 +191,7 @@ static void luaI_unregisterlocalvar (LexState *ls, int line) {
static void store_localvar (LexState *ls, TString *name, int n) { static void store_localvar (LexState *ls, TString *name, int n) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); luaX_checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables");
fs->localvar[fs->nlocalvar+n] = name; fs->localvar[fs->nlocalvar+n] = name;
} }
@ -266,7 +257,7 @@ static int indexupvalue (LexState *ls, TString *n) {
} }
/* new one */ /* new one */
++(fs->nupvalues); ++(fs->nupvalues);
checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues"); luaX_checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues");
fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */ fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */
return i; return i;
} }
@ -306,7 +297,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, int nexps) {
static void code_args (LexState *ls, int nparams, int dots) { static void code_args (LexState *ls, int nparams, int dots) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
adjustlocalvars(ls, nparams); adjustlocalvars(ls, nparams);
checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters"); luaX_checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters");
nparams = fs->nlocalvar; /* `self' could be there already */ nparams = fs->nlocalvar; /* `self' could be there already */
fs->f->numparams = nparams; fs->f->numparams = nparams;
fs->f->is_vararg = dots; fs->f->is_vararg = dots;
@ -369,7 +360,7 @@ static void func_onstack (LexState *ls, FuncState *func) {
for (i=0; i<func->nupvalues; i++) for (i=0; i<func->nupvalues; i++)
luaK_tostack(ls, &func->upvalues[i], 1); luaK_tostack(ls, &func->upvalues[i], 1);
luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *, luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *,
constantEM, MAXARG_A); "constant table overflow", MAXARG_A);
f->kproto[f->nkproto++] = func->f; f->kproto[f->nkproto++] = func->f;
luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues); luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues);
} }
@ -623,8 +614,8 @@ static int listfields (LexState *ls) {
break; break;
exp1(ls); exp1(ls);
n++; n++;
checklimit(ls, n, MAXARG_A*LFIELDS_PER_FLUSH, luaX_checklimit(ls, n/LFIELDS_PER_FLUSH, MAXARG_A,
"items in a list initializer"); "`item groups' in a list initializer");
if (++mod_n == LFIELDS_PER_FLUSH) { if (++mod_n == LFIELDS_PER_FLUSH) {
luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH); luaK_code2(fs, OP_SETLIST, n/LFIELDS_PER_FLUSH - 1, LFIELDS_PER_FLUSH);
mod_n = 0; mod_n = 0;
@ -697,6 +688,7 @@ static void constructor (LexState *ls) {
} }
check_match(ls, '}', '{', line); check_match(ls, '}', '{', line);
/* set initial table size */ /* set initial table size */
luaX_checklimit(ls, nelems, MAXARG_U, "elements in a table constructor");
SETARG_U(fs->f->code[pc], nelems); SETARG_U(fs->f->code[pc], nelems);
} }
@ -846,7 +838,7 @@ static void block (LexState *ls) {
static int assignment (LexState *ls, expdesc *v, int nvars) { static int assignment (LexState *ls, expdesc *v, int nvars) {
int left = 0; int left = 0;
checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment"); luaX_checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment");
if (ls->token == ',') { /* assignment -> ',' NAME assignment */ if (ls->token == ',') { /* assignment -> ',' NAME assignment */
expdesc nv; expdesc nv;
next(ls); next(ls);

5
lref.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lref.c,v 1.10 2000/03/27 20:10:21 roberto Exp roberto $ ** $Id: lref.c,v 1.11 2000/03/29 20:19:20 roberto Exp roberto $
** reference mechanism ** reference mechanism
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -25,7 +25,8 @@ int lua_ref (lua_State *L, int lock) {
L->refFree = L->refArray[ref].st; L->refFree = L->refArray[ref].st;
} }
else { /* no more free places */ else { /* no more free places */
luaM_growvector(L, L->refArray, L->refSize, 1, struct Ref, refEM, MAX_INT); luaM_growvector(L, L->refArray, L->refSize, 1, struct Ref,
"reference table overflow", MAX_INT);
ref = L->refSize++; ref = L->refSize++;
} }
L->refArray[ref].o = *(L->top-1); L->refArray[ref].o = *(L->top-1);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.h,v 1.32 2000/05/08 19:32:53 roberto Exp roberto $ ** $Id: lstate.h,v 1.33 2000/05/10 16:33:20 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -42,7 +42,7 @@ struct C_Lua_Stack {
typedef struct stringtable { typedef struct stringtable {
int size; int size;
long nuse; /* number of elements */ lint32 nuse; /* number of elements */
TString **hash; TString **hash;
} stringtable; } stringtable;
@ -57,9 +57,9 @@ struct lua_State {
struct C_Lua_Stack Cstack; /* C2lua struct */ struct C_Lua_Stack Cstack; /* C2lua struct */
struct lua_longjmp *errorJmp; /* current error recover point */ struct lua_longjmp *errorJmp; /* current error recover point */
char *Mbuffer; /* global buffer */ char *Mbuffer; /* global buffer */
int Mbuffbase; /* current first position of Mbuffer */ size_t Mbuffbase; /* current first position of Mbuffer */
int Mbuffsize; /* size of Mbuffer */ size_t Mbuffsize; /* size of Mbuffer */
int Mbuffnext; /* next position to fill in Mbuffer */ size_t Mbuffnext; /* next position to fill in Mbuffer */
struct C_Lua_Stack *Cblocks; struct C_Lua_Stack *Cblocks;
int numCblocks; /* number of nested Cblocks */ int numCblocks; /* number of nested Cblocks */
/* global state */ /* global state */

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstring.c,v 1.35 2000/05/08 19:32:53 roberto Exp roberto $ ** $Id: lstring.c,v 1.36 2000/05/10 16:33:20 roberto Exp roberto $
** String table (keeps all strings handled by Lua) ** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -34,10 +34,10 @@ void luaS_freeall (lua_State *L) {
} }
static unsigned long hash_s (const char *s, long l) { static unsigned long hash_s (const char *s, size_t l) {
unsigned long h = l; /* seed */ unsigned long h = l; /* seed */
long step = (l>>6)+1; /* if string is too long, don't hash all its chars */ size_t step = (l>>6)|1; /* if string is too long, don't hash all its chars */
for (; l>0; l-=step) for (; l>=step; l-=step)
h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++));
return h; return h;
} }
@ -71,13 +71,13 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) {
ts->nexthash = tb->hash[h]; /* chain new entry */ ts->nexthash = tb->hash[h]; /* chain new entry */
tb->hash[h] = ts; tb->hash[h] = ts;
tb->nuse++; tb->nuse++;
if (tb->nuse > tb->size && tb->size < MAX_INT/2) /* too crowded? */ if (tb->nuse > (lint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */
luaS_resize(L, tb, tb->size*2); luaS_resize(L, tb, tb->size*2);
} }
TString *luaS_newlstr (lua_State *L, const char *str, long l) { TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
unsigned long h = hash_s(str, l); unsigned long h = hash_s(str, l);
int h1 = h&(L->strt.size-1); int h1 = h&(L->strt.size-1);
TString *ts; TString *ts;
@ -86,7 +86,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, long l) {
return ts; return ts;
} }
/* not found */ /* not found */
ts = (TString *)luaM_malloc(L, sizeof(TString)+l*sizeof(char)); ts = (TString *)luaM_malloc(L, sizeof(TString)+(lint32)l*sizeof(char));
ts->marked = 0; ts->marked = 0;
ts->nexthash = NULL; ts->nexthash = NULL;
ts->u.s.len = l; ts->u.s.len = l;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstring.h,v 1.19 2000/05/08 19:32:53 roberto Exp roberto $ ** $Id: lstring.h,v 1.20 2000/05/10 16:33:20 roberto Exp roberto $
** String table (keep all strings handled by Lua) ** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -28,7 +28,7 @@ void luaS_init (lua_State *L);
void luaS_resize (lua_State *L, stringtable *tb, int newsize); void luaS_resize (lua_State *L, stringtable *tb, int newsize);
TString *luaS_createudata (lua_State *L, void *udata, int tag); TString *luaS_createudata (lua_State *L, void *udata, int tag);
void luaS_freeall (lua_State *L); void luaS_freeall (lua_State *L);
TString *luaS_newlstr (lua_State *L, const char *str, long l); TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
TString *luaS_new (lua_State *L, const char *str); TString *luaS_new (lua_State *L, const char *str);
TString *luaS_newfixed (lua_State *L, const char *str); TString *luaS_newfixed (lua_State *L, const char *str);

View File

@ -1,11 +1,12 @@
/* /*
** $Id: lstrlib.c,v 1.41 2000/03/03 14:58:26 roberto Exp roberto $ ** $Id: lstrlib.c,v 1.42 2000/05/02 18:32:22 roberto Exp roberto $
** Standard library for string operations and pattern-matching ** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#include <ctype.h> #include <ctype.h>
#include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -18,7 +19,7 @@
static void addnchar (lua_State *L, const char *s, int n) { static void addnchar (lua_State *L, const char *s, size_t n) {
char *b = luaL_openspace(L, n); char *b = luaL_openspace(L, n);
memcpy(b, s, n); memcpy(b, s, n);
luaL_addsize(L, n); luaL_addsize(L, n);
@ -26,7 +27,7 @@ static void addnchar (lua_State *L, const char *s, int n) {
static void str_len (lua_State *L) { static void str_len (lua_State *L) {
long l; size_t l;
luaL_check_lstr(L, 1, &l); luaL_check_lstr(L, 1, &l);
lua_pushnumber(L, l); lua_pushnumber(L, l);
} }
@ -37,19 +38,19 @@ static void closeandpush (lua_State *L) {
} }
static long posrelat (long pos, long len) { static long posrelat (long pos, size_t len) {
/* relative string position: negative means back from end */ /* relative string position: negative means back from end */
return (pos>=0) ? pos : len+pos+1; return (pos>=0) ? pos : (long)len+pos+1;
} }
static void str_sub (lua_State *L) { static void str_sub (lua_State *L) {
long l; size_t l;
const char *s = luaL_check_lstr(L, 1, &l); const char *s = luaL_check_lstr(L, 1, &l);
long start = posrelat(luaL_check_long(L, 2), l); long start = posrelat(luaL_check_long(L, 2), l);
long end = posrelat(luaL_opt_long(L, 3, -1), l); long end = posrelat(luaL_opt_long(L, 3, -1), l);
if (start < 1) start = 1; if (start < 1) start = 1;
if (end > l) end = l; if (end > (long)l) end = l;
if (start <= end) if (start <= end)
lua_pushlstring(L, s+start-1, end-start+1); lua_pushlstring(L, s+start-1, end-start+1);
else lua_pushstring(L, ""); else lua_pushstring(L, "");
@ -57,8 +58,8 @@ static void str_sub (lua_State *L) {
static void str_lower (lua_State *L) { static void str_lower (lua_State *L) {
long l; size_t l;
int i; size_t i;
const char *s = luaL_check_lstr(L, 1, &l); const char *s = luaL_check_lstr(L, 1, &l);
luaL_resetbuffer(L); luaL_resetbuffer(L);
for (i=0; i<l; i++) for (i=0; i<l; i++)
@ -68,8 +69,8 @@ static void str_lower (lua_State *L) {
static void str_upper (lua_State *L) { static void str_upper (lua_State *L) {
long l; size_t l;
int i; size_t i;
const char *s = luaL_check_lstr(L, 1, &l); const char *s = luaL_check_lstr(L, 1, &l);
luaL_resetbuffer(L); luaL_resetbuffer(L);
for (i=0; i<l; i++) for (i=0; i<l; i++)
@ -78,7 +79,7 @@ static void str_upper (lua_State *L) {
} }
static void str_rep (lua_State *L) { static void str_rep (lua_State *L) {
long l; size_t l;
const char *s = luaL_check_lstr(L, 1, &l); const char *s = luaL_check_lstr(L, 1, &l);
int n = luaL_check_int(L, 2); int n = luaL_check_int(L, 2);
luaL_resetbuffer(L); luaL_resetbuffer(L);
@ -89,10 +90,10 @@ static void str_rep (lua_State *L) {
static void str_byte (lua_State *L) { static void str_byte (lua_State *L) {
long l; size_t l;
const char *s = luaL_check_lstr(L, 1, &l); const char *s = luaL_check_lstr(L, 1, &l);
long pos = posrelat(luaL_opt_long(L, 2, 1), l); long pos = posrelat(luaL_opt_long(L, 2, 1), l);
luaL_arg_check(L, 0<pos && pos<=l, 2, "out of range"); luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range");
lua_pushnumber(L, (unsigned char)s[pos-1]); lua_pushnumber(L, (unsigned char)s[pos-1]);
} }
@ -126,7 +127,7 @@ struct Capture {
int level; /* total number of captures (finished or unfinished) */ int level; /* total number of captures (finished or unfinished) */
struct { struct {
const char *init; const char *init;
int len; /* -1 signals unfinished capture */ long len; /* -1 signals unfinished capture */
} capture[MAX_CAPTURES]; } capture[MAX_CAPTURES];
}; };
@ -238,7 +239,8 @@ int luaI_singlematch (int c, const char *p, const char *ep) {
} }
static const char *match (lua_State *L, const char *s, const char *p, struct Capture *cap); static const char *match (lua_State *L, const char *s, const char *p,
struct Capture *cap);
static const char *matchbalance (lua_State *L, const char *s, const char *p, static const char *matchbalance (lua_State *L, const char *s, const char *p,
@ -261,9 +263,9 @@ static const char *matchbalance (lua_State *L, const char *s, const char *p,
} }
static const char *max_expand (lua_State *L, const char *s, const char *p, const char *ep, static const char *max_expand (lua_State *L, const char *s, const char *p,
struct Capture *cap) { const char *ep, struct Capture *cap) {
int i = 0; /* counts maximum expand for item */ long i = 0; /* counts maximum expand for item */
while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep)) while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep))
i++; i++;
/* keeps trying to match mith the maximum repetitions */ /* keeps trying to match mith the maximum repetitions */
@ -276,8 +278,8 @@ static const char *max_expand (lua_State *L, const char *s, const char *p, const
} }
static const char *min_expand (lua_State *L, const char *s, const char *p, const char *ep, static const char *min_expand (lua_State *L, const char *s, const char *p,
struct Capture *cap) { const char *ep, struct Capture *cap) {
for (;;) { for (;;) {
const char *res = match(L, s, ep+1, cap); const char *res = match(L, s, ep+1, cap);
if (res != NULL) if (res != NULL)
@ -317,15 +319,16 @@ static const char *end_capture (lua_State *L, const char *s, const char *p,
static const char *match_capture (lua_State *L, const char *s, int level, static const char *match_capture (lua_State *L, const char *s, int level,
struct Capture *cap) { struct Capture *cap) {
int l = check_capture(L, level, cap); int l = check_capture(L, level, cap);
int len = cap->capture[l].len; size_t len = cap->capture[l].len;
if (cap->src_end-s >= len && if ((size_t)(cap->src_end-s) >= len &&
memcmp(cap->capture[l].init, s, len) == 0) memcmp(cap->capture[l].init, s, len) == 0)
return s+len; return s+len;
else return NULL; else return NULL;
} }
static const char *match (lua_State *L, const char *s, const char *p, struct Capture *cap) { static const char *match (lua_State *L, const char *s, const char *p,
struct Capture *cap) {
init: /* using goto's to optimize tail recursion */ init: /* using goto's to optimize tail recursion */
switch (*p) { switch (*p) {
case '(': /* start capture */ case '(': /* start capture */
@ -397,12 +400,12 @@ static const char *memfind (const char *s1, long l1, const char *s2, long l2) {
static void str_find (lua_State *L) { static void str_find (lua_State *L) {
long l1, l2; size_t l1, l2;
const char *s = luaL_check_lstr(L, 1, &l1); const char *s = luaL_check_lstr(L, 1, &l1);
const char *p = luaL_check_lstr(L, 2, &l2); const char *p = luaL_check_lstr(L, 2, &l2);
long init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; long init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
struct Capture cap; struct Capture cap;
luaL_arg_check(L, 0 <= init && init <= l1, 3, "out of range"); luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range");
if (lua_getparam(L, 4) != LUA_NOOBJECT || if (lua_getparam(L, 4) != LUA_NOOBJECT ||
strpbrk(p, SPECIALS) == NULL) { /* no special characters? */ strpbrk(p, SPECIALS) == NULL) { /* no special characters? */
const char *s2 = memfind(s+init, l1-init, p, l2); const char *s2 = memfind(s+init, l1-init, p, l2);
@ -434,8 +437,8 @@ static void str_find (lua_State *L) {
static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) { static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) {
if (lua_isstring(L, newp)) { if (lua_isstring(L, newp)) {
const char *news = lua_getstring(L, newp); const char *news = lua_getstring(L, newp);
int l = lua_strlen(L, newp); size_t l = lua_strlen(L, newp);
int i; size_t i;
for (i=0; i<l; i++) { for (i=0; i<l; i++) {
if (news[i] != ESC) if (news[i] != ESC)
luaL_addchar(L, news[i]); luaL_addchar(L, news[i]);
@ -453,7 +456,7 @@ static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) {
else { /* is a function */ else { /* is a function */
lua_Object res; lua_Object res;
int status; int status;
int oldbuff; size_t oldbuff;
lua_beginblock(L); lua_beginblock(L);
push_captures(L, cap); push_captures(L, cap);
/* function may use buffer, so save it and create a new one */ /* function may use buffer, so save it and create a new one */
@ -474,7 +477,7 @@ static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) {
static void str_gsub (lua_State *L) { static void str_gsub (lua_State *L) {
long srcl; size_t srcl;
const char *src = luaL_check_lstr(L, 1, &srcl); const char *src = luaL_check_lstr(L, 1, &srcl);
const char *p = luaL_check_string(L, 2); const char *p = luaL_check_string(L, 2);
lua_Object newp = lua_getparam(L, 3); lua_Object newp = lua_getparam(L, 3);
@ -510,7 +513,7 @@ static void str_gsub (lua_State *L) {
static void luaI_addquoted (lua_State *L, int arg) { static void luaI_addquoted (lua_State *L, int arg) {
long l; size_t l;
const char *s = luaL_check_lstr(L, arg, &l); const char *s = luaL_check_lstr(L, arg, &l);
luaL_addchar(L, '"'); luaL_addchar(L, '"');
while (l--) { while (l--) {
@ -573,7 +576,7 @@ static void str_format (lua_State *L) {
luaI_addquoted(L, arg); luaI_addquoted(L, arg);
continue; /* skip the "addsize" at the end */ continue; /* skip the "addsize" at the end */
case 's': { case 's': {
long l; size_t l;
const char *s = luaL_check_lstr(L, arg, &l); const char *s = luaL_check_lstr(L, arg, &l);
if (cap.capture[1].len == 0 && l >= 100) { if (cap.capture[1].len == 0 && l >= 100) {
/* no precision and string is too long to be formatted; /* no precision and string is too long to be formatted;

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltable.c,v 1.41 2000/05/08 19:32:53 roberto Exp roberto $ ** $Id: ltable.c,v 1.42 2000/05/11 18:57:19 roberto Exp roberto $
** Lua tables (hash) ** Lua tables (hash)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -122,10 +122,12 @@ int luaH_pos (lua_State *L, const Hash *t, const TObject *key) {
} }
static void setnodevector (lua_State *L, Hash *t, int size) { static void setnodevector (lua_State *L, Hash *t, lint32 size) {
int i; int i;
if (size > MAX_INT)
lua_error(L, "table overflow");
t->node = luaM_newvector(L, size, Node); t->node = luaM_newvector(L, size, Node);
for (i=0; i<size; i++) { for (i=0; i<(int)size; i++) {
ttype(&t->node[i].key) = ttype(&t->node[i].val) = TAG_NIL; ttype(&t->node[i].key) = ttype(&t->node[i].val) = TAG_NIL;
t->node[i].next = NULL; t->node[i].next = NULL;
} }
@ -153,7 +155,7 @@ void luaH_free (lua_State *L, Hash *t) {
} }
static int newsize (const Hash *t) { static int numuse (const Hash *t) {
Node *v = t->node; Node *v = t->node;
int size = t->size; int size = t->size;
int realuse = 0; int realuse = 0;
@ -162,16 +164,24 @@ static int newsize (const Hash *t) {
if (ttype(&v[i].val) != TAG_NIL) if (ttype(&v[i].val) != TAG_NIL)
realuse++; realuse++;
} }
return luaO_power2(realuse+realuse/4+1); return realuse;
} }
static void rehash (lua_State *L, Hash *t) { static void rehash (lua_State *L, Hash *t) {
int oldsize = t->size; int oldsize = t->size;
Node *nold = t->node; Node *nold = t->node;
int newsize = numuse(t);
int i; int i;
LUA_ASSERT(L, newsize<=oldsize, "wrong count");
if (newsize >= oldsize-oldsize/4) /* using more than 3/4? */
setnodevector(L, t, (lint32)oldsize*2);
else if (newsize <= oldsize/4 && /* less than 1/4? */
oldsize > MINPOWER2)
setnodevector(L, t, oldsize/2);
else
setnodevector(L, t, oldsize);
L->nblocks -= gcsize(L, oldsize); L->nblocks -= gcsize(L, oldsize);
setnodevector(L, t, newsize(t)); /* create new array of nodes */
for (i=0; i<oldsize; i++) { for (i=0; i<oldsize; i++) {
Node *old = nold+i; Node *old = nold+i;
if (ttype(&old->val) != TAG_NIL) if (ttype(&old->val) != TAG_NIL)
@ -249,3 +259,4 @@ void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) {
const TObject *luaH_getglobal (lua_State *L, const char *name) { const TObject *luaH_getglobal (lua_State *L, const char *name) {
return luaH_getstr(L->gt, luaS_new(L, name)); return luaH_getstr(L->gt, luaS_new(L, name));
} }

7
ltm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltm.c,v 1.38 2000/03/29 20:19:20 roberto Exp roberto $ ** $Id: ltm.c,v 1.39 2000/03/30 16:41:51 roberto Exp roberto $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -67,7 +67,7 @@ static void init_entry (lua_State *L, int tag) {
void luaT_init (lua_State *L) { void luaT_init (lua_State *L) {
int t; int t;
L->last_tag = NUM_TAGS-1; L->last_tag = NUM_TAGS-1;
luaM_growvector(L, L->IMtable, 0, NUM_TAGS, struct IM, arrEM, MAX_INT); luaM_growvector(L, L->IMtable, 0, NUM_TAGS, struct IM, "", MAX_INT);
for (t=0; t<=L->last_tag; t++) for (t=0; t<=L->last_tag; t++)
init_entry(L, t); init_entry(L, t);
} }
@ -75,7 +75,8 @@ void luaT_init (lua_State *L) {
int lua_newtag (lua_State *L) { int lua_newtag (lua_State *L) {
++L->last_tag; ++L->last_tag;
luaM_growvector(L, L->IMtable, L->last_tag, 1, struct IM, arrEM, MAX_INT); luaM_growvector(L, L->IMtable, L->last_tag, 1, struct IM,
"tag table overflow", MAX_INT);
init_entry(L, L->last_tag); init_entry(L, L->last_tag);
return L->last_tag; return L->last_tag;
} }

15
lua.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lua.h,v 1.51 2000/05/09 14:50:16 roberto Exp roberto $ ** $Id: lua.h,v 1.52 2000/05/10 16:35:18 roberto Exp roberto $
** Lua - An Extensible Extension Language ** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br ** e-mail: lua@tecgraf.puc-rio.br
@ -11,6 +11,11 @@
#ifndef lua_h #ifndef lua_h
#define lua_h #define lua_h
/* definition of `size_t' */
#include <stddef.h>
#define LUA_VERSION "Lua 4.0 (alpha)" #define LUA_VERSION "Lua 4.0 (alpha)"
#define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio" #define LUA_COPYRIGHT "Copyright (C) 1994-2000 TeCGraf, PUC-Rio"
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
@ -50,8 +55,8 @@ int lua_dofile (lua_State *L, const char *filename);
/* Out: returns */ /* Out: returns */
int lua_dostring (lua_State *L, const char *str); int lua_dostring (lua_State *L, const char *str);
/* Out: returns */ /* Out: returns */
int lua_dobuffer (lua_State *L, const char *buff, int size, int lua_dobuffer (lua_State *L, const char *buff, size_t size,
const char *name); /* Out: returns */ const char *name); /* Out: returns */
int lua_callfunction (lua_State *L, lua_Object f); int lua_callfunction (lua_State *L, lua_Object f);
/* In: parameters; Out: returns */ /* In: parameters; Out: returns */
@ -79,14 +84,14 @@ int lua_equal (lua_State *L, lua_Object o1, lua_Object o2);
double lua_getnumber (lua_State *L, lua_Object obj); double lua_getnumber (lua_State *L, lua_Object obj);
const char *lua_getstring (lua_State *L, lua_Object obj); const char *lua_getstring (lua_State *L, lua_Object obj);
long lua_strlen (lua_State *L, lua_Object obj); size_t lua_strlen (lua_State *L, lua_Object obj);
lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj); lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj);
void *lua_getuserdata (lua_State *L, lua_Object obj); void *lua_getuserdata (lua_State *L, lua_Object obj);
void lua_pushnil (lua_State *L); void lua_pushnil (lua_State *L);
void lua_pushnumber (lua_State *L, double n); void lua_pushnumber (lua_State *L, double n);
void lua_pushlstring (lua_State *L, const char *s, long len); void lua_pushlstring (lua_State *L, const char *s, size_t len);
void lua_pushstring (lua_State *L, const char *s); void lua_pushstring (lua_State *L, const char *s);
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
void lua_pushusertag (lua_State *L, void *u, int tag); void lua_pushusertag (lua_State *L, void *u, int tag);

34
lvm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 1.106 2000/05/15 19:48:04 roberto Exp roberto $ ** $Id: lvm.c,v 1.107 2000/05/22 18:44:46 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -187,7 +187,7 @@ void luaV_setglobal (lua_State *L, TString *s, StkId top) {
const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL);
if (ttype(im) == TAG_NIL) { /* is there a tag method? */ if (ttype(im) == TAG_NIL) { /* is there a tag method? */
if (oldvalue != &luaO_nilobject) if (oldvalue != &luaO_nilobject)
*oldvalue = *(top-1); *(TObject *)oldvalue = *(top-1);
else { else {
TObject key; TObject key;
ttype(&key) = TAG_STRING; ttype(&key) = TAG_STRING;
@ -239,21 +239,22 @@ static void addK (lua_State *L, StkId top, int k) {
static int luaV_strcomp (const TString *ls, const TString *rs) { static int luaV_strcomp (const TString *ls, const TString *rs) {
const char *l = ls->str; const char *l = ls->str;
long ll = ls->u.s.len; size_t ll = ls->u.s.len;
const char *r = rs->str; const char *r = rs->str;
long lr = rs->u.s.len; size_t lr = rs->u.s.len;
for (;;) { for (;;) {
long temp = strcoll(l, r); int temp = strcoll(l, r);
if (temp != 0) return temp; if (temp != 0) return temp;
/* strings are equal up to a '\0' */ else { /* strings are equal up to a '\0' */
temp = strlen(l); /* index of first '\0' in both strings */ size_t len = strlen(l); /* index of first '\0' in both strings */
if (temp == ll) /* l is finished? */ if (len == ll) /* l is finished? */
return (temp == lr) ? 0 : -1; /* l is equal or smaller than r */ return (len == lr) ? 0 : -1; /* l is equal or smaller than r */
else if (temp == lr) /* r is finished? */ else if (len == lr) /* r is finished? */
return 1; /* l is greater than r (because l is not finished) */ return 1; /* l is greater than r (because l is not finished) */
/* both strings longer than temp; go on comparing (after the '\0') */ /* both strings longer than `len'; go on comparing (after the '\0') */
temp++; len++;
l += temp; ll -= temp; r += temp; lr -= temp; l += len; ll -= len; r += len; lr -= len;
}
} }
} }
@ -281,17 +282,18 @@ static void strconc (lua_State *L, int total, StkId top) {
call_binTM(L, top, IM_CONCAT, "unexpected type for concatenation"); call_binTM(L, top, IM_CONCAT, "unexpected type for concatenation");
else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */ else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */
/* at least two string values; get as many as possible */ /* at least two string values; get as many as possible */
long tl = tsvalue(top-1)->u.s.len + tsvalue(top-2)->u.s.len; lint32 tl = tsvalue(top-1)->u.s.len + tsvalue(top-2)->u.s.len;
char *buffer; char *buffer;
int i; int i;
while (n < total && !tostring(L, top-n-1)) { /* collect total length */ while (n < total && !tostring(L, top-n-1)) { /* collect total length */
tl += tsvalue(top-n-1)->u.s.len; tl += tsvalue(top-n-1)->u.s.len;
n++; n++;
} }
if (tl > MAX_SIZET) lua_error(L, "string size overflow");
buffer = luaL_openspace(L, tl); buffer = luaL_openspace(L, tl);
tl = 0; tl = 0;
for (i=n; i>0; i--) { /* concat all strings */ for (i=n; i>0; i--) { /* concat all strings */
long l = tsvalue(top-i)->u.s.len; lint32 l = tsvalue(top-i)->u.s.len;
memcpy(buffer+tl, tsvalue(top-i)->str, l); memcpy(buffer+tl, tsvalue(top-i)->str, l);
tl += l; tl += l;
} }

10
lzio.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lzio.c,v 1.10 2000/02/08 16:39:42 roberto Exp roberto $ ** $Id: lzio.c,v 1.11 2000/03/03 14:58:26 roberto Exp roberto $
** a generic input stream interface ** a generic input stream interface
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -21,7 +21,7 @@ static int zmfilbuf (ZIO* z) {
} }
ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) { ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name) {
if (b==NULL) return NULL; if (b==NULL) return NULL;
z->n = size; z->n = size;
z->p = (const unsigned char *)b; z->p = (const unsigned char *)b;
@ -41,7 +41,7 @@ ZIO* zsopen (ZIO* z, const char* s, const char *name) {
/* -------------------------------------------------------------- FILEs --- */ /* -------------------------------------------------------------- FILEs --- */
static int zffilbuf (ZIO* z) { static int zffilbuf (ZIO* z) {
int n; size_t n;
if (feof((FILE *)z->u)) return EOZ; if (feof((FILE *)z->u)) return EOZ;
n = fread(z->buffer, 1, ZBSIZE, (FILE *)z->u); n = fread(z->buffer, 1, ZBSIZE, (FILE *)z->u);
if (n==0) return EOZ; if (n==0) return EOZ;
@ -63,9 +63,9 @@ ZIO* zFopen (ZIO* z, FILE* f, const char *name) {
/* --------------------------------------------------------------- read --- */ /* --------------------------------------------------------------- read --- */
int zread (ZIO *z, void *b, int n) { size_t zread (ZIO *z, void *b, size_t n) {
while (n) { while (n) {
int m; size_t m;
if (z->n == 0) { if (z->n == 0) {
if (z->filbuf(z) == EOZ) if (z->filbuf(z) == EOZ)
return n; /* return number of missing bytes */ return n; /* return number of missing bytes */

10
lzio.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lzio.h,v 1.4 1998/01/09 14:57:43 roberto Exp roberto $ ** $Id: lzio.h,v 1.5 1999/08/16 20:52:00 roberto Exp roberto $
** Buffered streams ** Buffered streams
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -24,11 +24,11 @@ typedef struct zio ZIO;
ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */ ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */
ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */ ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */
ZIO* zmopen (ZIO* z, const char* b, int size, const char *name); /* memory */ ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name); /* memory */
int zread (ZIO* z, void* b, int n); /* read next n bytes */ size_t zread (ZIO* z, void* b, size_t n); /* read next n bytes */
#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) #define zgetc(z) (((z)->n--)>0 ? ((int)*(z)->p++): (z)->filbuf(z))
#define zungetc(z) (++(z)->n,--(z)->p) #define zungetc(z) (++(z)->n,--(z)->p)
#define zname(z) ((z)->name) #define zname(z) ((z)->name)
@ -38,7 +38,7 @@ int zread (ZIO* z, void* b, int n); /* read next n bytes */
#define ZBSIZE 256 /* buffer size */ #define ZBSIZE 256 /* buffer size */
struct zio { struct zio {
int n; /* bytes still unread */ size_t n; /* bytes still unread */
const unsigned char* p; /* current position in buffer */ const unsigned char* p; /* current position in buffer */
int (*filbuf)(ZIO* z); int (*filbuf)(ZIO* z);
void* u; /* additional data */ void* u; /* additional data */

View File

@ -1,4 +1,4 @@
% $Id: manual.tex,v 1.37 2000/05/12 19:19:18 roberto Exp roberto $ % $Id: manual.tex,v 1.38 2000/05/12 19:49:18 roberto Exp roberto $
\documentclass[11pt]{article} \documentclass[11pt]{article}
\usepackage{fullpage,bnf} \usepackage{fullpage,bnf}
@ -122,7 +122,7 @@ Waldemar Celes
\tecgraf\ --- Computer Science Department --- PUC-Rio \tecgraf\ --- Computer Science Department --- PUC-Rio
} }
\date{{\small \tt\$Date: 2000/05/12 19:19:18 $ $}} \date{{\small \tt\$Date: 2000/05/12 19:49:18 $ $}}
\maketitle \maketitle
@ -1695,7 +1695,7 @@ you can use the following conversion functions:
\begin{verbatim} \begin{verbatim}
double lua_getnumber (lua_Object object); double lua_getnumber (lua_Object object);
const char *lua_getstring (lua_Object object); const char *lua_getstring (lua_Object object);
long lua_strlen (lua_Object object); size_t lua_strlen (lua_Object object);
lua_CFunction lua_getcfunction (lua_Object object); lua_CFunction lua_getcfunction (lua_Object object);
void *lua_getuserdata (lua_Object object); void *lua_getuserdata (lua_Object object);
\end{verbatim} \end{verbatim}
@ -1765,7 +1765,7 @@ is done with the following functions:
\Deffunc{lua_pushuserdata}\label{pushing} \Deffunc{lua_pushuserdata}\label{pushing}
\begin{verbatim} \begin{verbatim}
void lua_pushnumber (double n); void lua_pushnumber (double n);
void lua_pushlstring (const char *s, long len); void lua_pushlstring (const char *s, size_t len);
void lua_pushstring (const char *s); void lua_pushstring (const char *s);
void lua_pushusertag (void *u, int tag); void lua_pushusertag (void *u, int tag);
void lua_pushnil (void); void lua_pushnil (void);
@ -1864,7 +1864,7 @@ using the following functions:%
\begin{verbatim} \begin{verbatim}
int lua_dofile (const char *filename); int lua_dofile (const char *filename);
int lua_dostring (const char *string); int lua_dostring (const char *string);
int lua_dobuffer (const char *buff, int size, const char *name); int lua_dobuffer (const char *buff, size_t size, const char *name);
\end{verbatim} \end{verbatim}
All these functions return an error code: All these functions return an error code:
0, in case of success; non zero, in case of errors. 0, in case of success; non zero, in case of errors.