mirror of
https://github.com/lua/lua
synced 2024-11-26 06:39:41 +03:00
better syntax for type casts
This commit is contained in:
parent
7651a5c6b2
commit
e1d072571e
10
lapi.c
10
lapi.c
@ -544,8 +544,8 @@ LUA_API int lua_dostring (lua_State *L, const l_char *str) {
|
||||
*/
|
||||
|
||||
/* GC values are expressed in Kbytes: #bytes/2^10 */
|
||||
#define GCscale(x) ((int)((x)>>10))
|
||||
#define GCunscale(x) ((lu_mem)(x)<<10)
|
||||
#define GCscale(x) (cast(int, (x)>>10))
|
||||
#define GCunscale(x) (cast(lu_mem, (x)<<10))
|
||||
|
||||
LUA_API int lua_getgcthreshold (lua_State *L) {
|
||||
int threshold;
|
||||
@ -602,7 +602,7 @@ LUA_API int lua_name2tag (lua_State *L, const l_char *name) {
|
||||
tag = LUA_TNONE;
|
||||
else {
|
||||
lua_assert(ttype(v) == LUA_TNUMBER);
|
||||
tag = (int)nvalue(v);
|
||||
tag = cast(int, nvalue(v));
|
||||
}
|
||||
lua_unlock(L);
|
||||
return tag;
|
||||
@ -695,7 +695,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
|
||||
api_check(L, ttype(t) == LUA_TTABLE);
|
||||
value = luaH_getstr(hvalue(t), luaS_newliteral(L, l_s("n"))); /* = t.n */
|
||||
if (ttype(value) == LUA_TNUMBER)
|
||||
n = (int)nvalue(value);
|
||||
n = cast(int, nvalue(value));
|
||||
else {
|
||||
lua_Number max = 0;
|
||||
int i = hvalue(t)->size;
|
||||
@ -707,7 +707,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
|
||||
max = nvalue(key(nd));
|
||||
nd++;
|
||||
}
|
||||
n = (int)max;
|
||||
n = cast(int, max);
|
||||
}
|
||||
lua_unlock(L);
|
||||
return n;
|
||||
|
@ -141,7 +141,7 @@ static int luaB_getglobal (lua_State *L) {
|
||||
static int gettag (lua_State *L, int narg) {
|
||||
switch (lua_rawtag(L, narg)) {
|
||||
case LUA_TNUMBER:
|
||||
return (int)lua_tonumber(L, narg);
|
||||
return (int)(lua_tonumber(L, narg));
|
||||
case LUA_TSTRING: {
|
||||
const l_char *name = lua_tostring(L, narg);
|
||||
int tag = lua_name2tag(L, name);
|
||||
|
10
lcode.c
10
lcode.c
@ -41,7 +41,7 @@ static Instruction previous_instruction (FuncState *fs) {
|
||||
if (fs->pc > fs->lasttarget) /* no jumps to current position? */
|
||||
return fs->f->code[fs->pc-1]; /* returns previous instruction */
|
||||
else
|
||||
return (Instruction)(-1);/* no optimizations after an invalid instruction */
|
||||
return cast(Instruction, -1);/* invalid instruction avoids optimizations */
|
||||
}
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ void luaK_reserveregs (FuncState *fs, int n) {
|
||||
if (fs->freereg > fs->f->maxstacksize) {
|
||||
if (fs->freereg >= MAXSTACK)
|
||||
luaK_error(fs->ls, l_s("function or expression too complex"));
|
||||
fs->f->maxstacksize = (short)fs->freereg;
|
||||
fs->f->maxstacksize = cast(short, fs->freereg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,8 +225,8 @@ static void freeexp (FuncState *fs, expdesc *e) {
|
||||
static int addk (FuncState *fs, TObject *k) {
|
||||
const TObject *index = luaH_get(fs->h, k);
|
||||
if (ttype(index) == LUA_TNUMBER) {
|
||||
lua_assert(luaO_equalObj(&fs->f->k[(int)nvalue(index)], k));
|
||||
return (int)nvalue(index);
|
||||
lua_assert(luaO_equalObj(&fs->f->k[cast(int, nvalue(index))], k));
|
||||
return cast(int, nvalue(index));
|
||||
}
|
||||
else { /* constant not found; create a new entry */
|
||||
TObject o;
|
||||
@ -329,7 +329,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
|
||||
}
|
||||
case VNUMBER: {
|
||||
lua_Number f = e->u.n;
|
||||
int i = (int)f;
|
||||
int i = cast(int, f);
|
||||
if ((lua_Number)i == f && -MAXARG_sBc <= i && i <= MAXARG_sBc)
|
||||
luaK_codeAsBc(fs, OP_LOADINT, reg, i); /* f has a small int value */
|
||||
else
|
||||
|
4
ldblib.c
4
ldblib.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldblib.c,v 1.36 2001/03/26 14:31:49 roberto Exp roberto $
|
||||
** $Id: ldblib.c,v 1.37 2001/06/06 18:00:19 roberto Exp $
|
||||
** Interface from Lua to its debug API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -37,7 +37,7 @@ static int getinfo (lua_State *L) {
|
||||
const l_char *options = luaL_opt_string(L, 2, l_s("flnSu"));
|
||||
l_char buff[20];
|
||||
if (lua_isnumber(L, 1)) {
|
||||
if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) {
|
||||
if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) {
|
||||
lua_pushnil(L); /* level out of range */
|
||||
return 1;
|
||||
}
|
||||
|
6
ldo.c
6
ldo.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldo.c,v 1.137 2001/07/12 19:34:03 roberto Exp roberto $
|
||||
** $Id: ldo.c,v 1.138 2001/07/16 20:24:48 roberto Exp $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -176,7 +176,7 @@ struct CallS { /* data to `f_call' */
|
||||
};
|
||||
|
||||
static void f_call (lua_State *L, void *ud) {
|
||||
struct CallS *c = (struct CallS *)ud;
|
||||
struct CallS *c = cast(struct CallS *, ud);
|
||||
luaD_call(L, c->func);
|
||||
if (c->nresults != LUA_MULTRET)
|
||||
luaD_adjusttop(L, c->func + c->nresults);
|
||||
@ -207,7 +207,7 @@ struct SParser { /* data to `f_parser' */
|
||||
};
|
||||
|
||||
static void f_parser (lua_State *L, void *ud) {
|
||||
struct SParser *p = (struct SParser *)ud;
|
||||
struct SParser *p = cast(struct SParser *, ud);
|
||||
Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z);
|
||||
luaV_Lclosure(L, tf, 0);
|
||||
}
|
||||
|
7
lfunc.c
7
lfunc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lfunc.c,v 1.44 2001/06/05 18:17:01 roberto Exp roberto $
|
||||
** $Id: lfunc.c,v 1.45 2001/06/28 14:57:17 roberto Exp $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -15,11 +15,12 @@
|
||||
#include "lstate.h"
|
||||
|
||||
|
||||
#define sizeclosure(n) ((int)sizeof(Closure) + (int)sizeof(TObject)*((n)-1))
|
||||
#define sizeclosure(n) (cast(int, sizeof(Closure)) + \
|
||||
cast(int, sizeof(TObject)*((n)-1)))
|
||||
|
||||
|
||||
Closure *luaF_newclosure (lua_State *L, int nelems) {
|
||||
Closure *c = (Closure *)luaM_malloc(L, sizeclosure(nelems));
|
||||
Closure *c = cast(Closure *, luaM_malloc(L, sizeclosure(nelems)));
|
||||
c->next = G(L)->rootcl;
|
||||
G(L)->rootcl = c;
|
||||
c->mark = c;
|
||||
|
4
lgc.c
4
lgc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 1.108 2001/06/26 13:20:45 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 1.109 2001/06/28 14:57:17 roberto Exp $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -305,7 +305,7 @@ static void collectstrings (lua_State *L, int all) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (G(L)->strt.nuse < (ls_nstr)(G(L)->strt.size/4) &&
|
||||
if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
|
||||
G(L)->strt.size > MINPOWER2)
|
||||
luaS_resize(L, G(L)->strt.size/2); /* table is too big */
|
||||
}
|
||||
|
30
liolib.c
30
liolib.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: liolib.c,v 1.120 2001/07/16 18:48:31 roberto Exp roberto $
|
||||
** $Id: liolib.c,v 1.121 2001/07/22 00:59:36 roberto Exp $
|
||||
** Standard I/O (and system) library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -73,7 +73,7 @@ static int pushresult (lua_State *L, int i) {
|
||||
|
||||
|
||||
static FILE *getopthandle (lua_State *L, int inout) {
|
||||
FILE *p = (FILE *)lua_touserdata(L, 1);
|
||||
FILE *p = (FILE *)(lua_touserdata(L, 1));
|
||||
if (p != NULL) { /* is it a userdata ? */
|
||||
if (!checkfile(L, 1)) { /* not a valid file handle? */
|
||||
if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0)
|
||||
@ -88,7 +88,7 @@ static FILE *getopthandle (lua_State *L, int inout) {
|
||||
if (!checkfile(L,-1))
|
||||
luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"),
|
||||
filenames[inout]);
|
||||
p = (FILE *)lua_touserdata(L, -1);
|
||||
p = (FILE *)(lua_touserdata(L, -1));
|
||||
}
|
||||
return p; /* leave handle at stack top to avoid GC */
|
||||
}
|
||||
@ -127,7 +127,7 @@ static void resetfile (lua_State *L, int inout) {
|
||||
|
||||
|
||||
static int io_close (lua_State *L) {
|
||||
FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE);
|
||||
FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
|
||||
int status = 1;
|
||||
if (f != stdin && f != stdout && f != stderr) {
|
||||
lua_settop(L, 1); /* make sure file is on top */
|
||||
@ -139,7 +139,7 @@ static int io_close (lua_State *L) {
|
||||
|
||||
|
||||
static int file_collect (lua_State *L) {
|
||||
FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE);
|
||||
FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
|
||||
if (f != stdin && f != stdout && f != stderr)
|
||||
CLOSEFILE(L, f);
|
||||
return 0;
|
||||
@ -328,7 +328,7 @@ static int io_read (lua_State *L) {
|
||||
size_t pl = lua_strlen(L, n) - 2;
|
||||
luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n,
|
||||
l_s("invalid read-until length"));
|
||||
success = read_until(L, f, p+2, (int)pl);
|
||||
success = read_until(L, f, p+2, (int)(pl));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -373,7 +373,7 @@ static int io_write (lua_State *L) {
|
||||
static int io_seek (lua_State *L) {
|
||||
static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
|
||||
static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL};
|
||||
FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE);
|
||||
FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
|
||||
int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames);
|
||||
long offset = luaL_opt_long(L, 3, 0);
|
||||
luaL_arg_check(L, op != -1, 2, l_s("invalid mode"));
|
||||
@ -388,8 +388,8 @@ static int io_seek (lua_State *L) {
|
||||
|
||||
|
||||
static int io_flush (lua_State *L) {
|
||||
FILE *f = (lua_isnull(L, 1)) ? (FILE *)NULL :
|
||||
(FILE *)luaL_check_userdata(L, 1, FILEHANDLE);
|
||||
FILE *f = (lua_isnull(L, 1)) ? (FILE *)(NULL) :
|
||||
(FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
|
||||
return pushresult(L, fflush(f) == 0);
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ static int getfield (lua_State *L, const l_char *key, int d) {
|
||||
lua_pushstring(L, key);
|
||||
lua_rawget(L, -2);
|
||||
if (lua_isnumber(L, -1))
|
||||
res = (int)lua_tonumber(L, -1);
|
||||
res = (int)(lua_tonumber(L, -1));
|
||||
else {
|
||||
if (d == -2)
|
||||
luaL_verror(L, l_s("field `%.20s' missing in date table"), key);
|
||||
@ -474,9 +474,9 @@ static int getfield (lua_State *L, const l_char *key, int d) {
|
||||
|
||||
static int io_date (lua_State *L) {
|
||||
const l_char *s = luaL_opt_string(L, 1, l_s("%c"));
|
||||
time_t t = (time_t)luaL_opt_number(L, 2, -1);
|
||||
time_t t = (time_t)(luaL_opt_number(L, 2, -1));
|
||||
struct tm *stm;
|
||||
if (t == (time_t)-1) /* no time given? */
|
||||
if (t == (time_t)(-1)) /* no time given? */
|
||||
t = time(NULL); /* use current time */
|
||||
if (*s == l_c('!')) { /* UTC? */
|
||||
stm = gmtime(&t);
|
||||
@ -525,7 +525,7 @@ static int io_time (lua_State *L) {
|
||||
ts.tm_year = getfield(L, l_s("year"), -2)-1900;
|
||||
ts.tm_isdst = getfield(L, l_s("isdst"), -1);
|
||||
t = mktime(&ts);
|
||||
if (t == (time_t)-1)
|
||||
if (t == (time_t)(-1))
|
||||
lua_pushnil(L);
|
||||
else
|
||||
lua_pushnumber(L, t);
|
||||
@ -535,8 +535,8 @@ static int io_time (lua_State *L) {
|
||||
|
||||
|
||||
static int io_difftime (lua_State *L) {
|
||||
lua_pushnumber(L, difftime((time_t)luaL_check_number(L, 1),
|
||||
(time_t)luaL_opt_number(L, 2, 0)));
|
||||
lua_pushnumber(L, difftime((time_t)(luaL_check_number(L, 1)),
|
||||
(time_t)(luaL_opt_number(L, 2, 0))));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
14
llex.c
14
llex.c
@ -41,7 +41,7 @@ void luaX_init (lua_State *L) {
|
||||
for (i=0; i<NUM_RESERVED; i++) {
|
||||
TString *ts = luaS_new(L, token2string[i]);
|
||||
lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN);
|
||||
ts->tsv.marked = (unsigned short)(RESERVEDMARK+i); /* reserved word */
|
||||
ts->tsv.marked = cast(unsigned short, RESERVEDMARK+i); /* reserved word */
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ void luaX_error (LexState *ls, const l_char *s, int token) {
|
||||
l_char buff[TOKEN_LEN];
|
||||
luaX_token2str(token, buff);
|
||||
if (buff[0] == l_c('\0'))
|
||||
luaX_syntaxerror(ls, s, (l_char *)G(ls->L)->Mbuffer);
|
||||
luaX_syntaxerror(ls, s, cast(l_char *, G(ls->L)->Mbuffer));
|
||||
else
|
||||
luaX_syntaxerror(ls, s, buff);
|
||||
}
|
||||
@ -134,7 +134,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) {
|
||||
if (((len)+(n))*sizeof(l_char) > G(L)->Mbuffsize) \
|
||||
luaO_openspace(L, (len)+(n)+EXTRABUFF, l_char)
|
||||
|
||||
#define save(L, c, l) (((l_char *)G(L)->Mbuffer)[l++] = (l_char)c)
|
||||
#define save(L, c, l) (cast(l_char *, G(L)->Mbuffer)[l++] = (l_char)c)
|
||||
#define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS))
|
||||
|
||||
|
||||
@ -185,7 +185,7 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) {
|
||||
}
|
||||
}
|
||||
save(L, l_c('\0'), l);
|
||||
if (!luaO_str2d((l_char *)G(L)->Mbuffer, &seminfo->r))
|
||||
if (!luaO_str2d(cast(l_char *, G(L)->Mbuffer), &seminfo->r))
|
||||
luaX_error(LS, l_s("malformed number"), TK_NUMBER);
|
||||
}
|
||||
|
||||
@ -231,7 +231,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) {
|
||||
} endloop:
|
||||
save_and_next(L, LS, l); /* skip the second `]' */
|
||||
save(L, l_c('\0'), l);
|
||||
seminfo->ts = luaS_newlstr(L, (l_char *)G(L)->Mbuffer+2, l-5);
|
||||
seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+2, l-5);
|
||||
}
|
||||
|
||||
|
||||
@ -283,7 +283,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) {
|
||||
}
|
||||
save_and_next(L, LS, l); /* skip delimiter */
|
||||
save(L, l_c('\0'), l);
|
||||
seminfo->ts = luaS_newlstr(L, (l_char *)G(L)->Mbuffer+1, l-3);
|
||||
seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+1, l-3);
|
||||
}
|
||||
|
||||
|
||||
@ -371,7 +371,7 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
|
||||
else if (isalpha(LS->current) || LS->current == l_c('_')) {
|
||||
/* identifier or reserved word */
|
||||
size_t l = readname(LS);
|
||||
TString *ts = luaS_newlstr(LS->L, (l_char *)G(LS->L)->Mbuffer, l);
|
||||
TString *ts = luaS_newlstr(LS->L, cast(l_char *, G(LS->L)->Mbuffer), l);
|
||||
if (ts->tsv.marked >= RESERVEDMARK) /* reserved word? */
|
||||
return ts->tsv.marked-RESERVEDMARK+FIRST_RESERVED;
|
||||
seminfo->ts = ts;
|
||||
|
4
llex.h
4
llex.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: llex.h,v 1.36 2001/06/20 21:07:57 roberto Exp roberto $
|
||||
** $Id: llex.h,v 1.37 2001/07/22 00:59:36 roberto Exp $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -33,7 +33,7 @@ enum RESERVED {
|
||||
};
|
||||
|
||||
/* number of reserved words */
|
||||
#define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1))
|
||||
#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
|
||||
|
||||
|
||||
typedef union {
|
||||
|
7
lmem.c
7
lmem.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmem.c,v 1.48 2001/02/23 17:17:25 roberto Exp roberto $
|
||||
** $Id: lmem.c,v 1.49 2001/03/26 14:31:49 roberto Exp $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -34,8 +34,9 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
|
||||
newsize = limit; /* still have at least MINPOWER2 free places */
|
||||
else luaD_error(L, errormsg);
|
||||
}
|
||||
newblock = luaM_realloc(L, block, (lu_mem)(*size)*(lu_mem)size_elems,
|
||||
(lu_mem)newsize*(lu_mem)size_elems);
|
||||
newblock = luaM_realloc(L, block,
|
||||
cast(lu_mem, *size)*cast(lu_mem, size_elems),
|
||||
cast(lu_mem, newsize)*cast(lu_mem, size_elems));
|
||||
*size = newsize; /* update only when everything else is OK */
|
||||
return newblock;
|
||||
}
|
||||
|
16
lmem.h
16
lmem.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmem.h,v 1.21 2001/02/20 18:15:33 roberto Exp roberto $
|
||||
** $Id: lmem.h,v 1.22 2001/02/23 17:17:25 roberto Exp $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -21,20 +21,20 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
|
||||
#define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
|
||||
#define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0)
|
||||
#define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
|
||||
((lu_mem)(n)*(lu_mem)sizeof(t)), 0)
|
||||
cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0)
|
||||
|
||||
#define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
|
||||
#define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t)))
|
||||
#define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, \
|
||||
(lu_mem)(n)*(lu_mem)sizeof(t)))
|
||||
#define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t)))
|
||||
#define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \
|
||||
cast(lu_mem, n)*cast(lu_mem, sizeof(t))))
|
||||
|
||||
#define luaM_growvector(L,v,nelems,size,t,limit,e) \
|
||||
if (((nelems)+1) > (size)) \
|
||||
((v)=(t *)luaM_growaux(L,v,&(size),sizeof(t),limit,e))
|
||||
((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e)))
|
||||
|
||||
#define luaM_reallocvector(L, v,oldn,n,t) \
|
||||
((v)=(t *)luaM_realloc(L, v,(lu_mem)(oldn)*(lu_mem)sizeof(t), \
|
||||
(lu_mem)(n)*(lu_mem)sizeof(t)))
|
||||
((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \
|
||||
cast(lu_mem, n)*cast(lu_mem, sizeof(t)))))
|
||||
|
||||
|
||||
#endif
|
||||
|
12
lobject.h
12
lobject.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.h,v 1.109 2001/06/28 14:56:25 roberto Exp roberto $
|
||||
** $Id: lobject.h,v 1.110 2001/08/27 15:16:28 roberto Exp $
|
||||
** Type definitions for Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -22,6 +22,10 @@
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef cast
|
||||
#define cast(t, exp) ((t)(exp))
|
||||
#endif
|
||||
|
||||
|
||||
/* tags for values visible from Lua == first user-created tag */
|
||||
#define NUM_TAGS 6
|
||||
@ -96,7 +100,7 @@ typedef union TString {
|
||||
} TString;
|
||||
|
||||
|
||||
#define getstr(ts) ((l_char *)((ts) + 1))
|
||||
#define getstr(ts) cast(l_char *, (ts) + 1)
|
||||
#define svalue(o) getstr(tsvalue(o))
|
||||
|
||||
|
||||
@ -196,7 +200,7 @@ typedef struct Hash {
|
||||
/*
|
||||
** `module' operation for hashing (size is always a power of 2)
|
||||
*/
|
||||
#define lmod(s,size) ((int)((s) & ((size)-1)))
|
||||
#define lmod(s,size) (cast(int, (s) & ((size)-1)))
|
||||
|
||||
|
||||
/*
|
||||
@ -217,7 +221,7 @@ typedef struct CallInfo {
|
||||
extern const TObject luaO_nilobject;
|
||||
|
||||
|
||||
#define luaO_openspace(L,n,t) ((t *)luaO_openspaceaux(L,(n)*sizeof(t)))
|
||||
#define luaO_openspace(L,n,t) cast(t *, luaO_openspaceaux(L,(n)*sizeof(t)))
|
||||
void *luaO_openspaceaux (lua_State *L, size_t n);
|
||||
|
||||
int luaO_equalObj (const TObject *t1, const TObject *t2);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.c,v 1.2 2001/07/03 17:02:02 roberto Exp roberto $
|
||||
** $Id: lopcodes.c,v 1.3 2001/08/27 15:14:57 roberto Exp $
|
||||
** extracted automatically from lopcodes.h by mkprint.lua
|
||||
** DO NOT EDIT
|
||||
** See Copyright Notice in lua.h
|
||||
@ -9,6 +9,7 @@
|
||||
#define LUA_PRIVATE
|
||||
#include "lua.h"
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lopcodes.h"
|
||||
|
||||
|
||||
|
42
lopcodes.h
42
lopcodes.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lopcodes.h,v 1.78 2001/07/24 17:19:07 roberto Exp roberto $
|
||||
** $Id: lopcodes.h,v 1.79 2001/08/27 15:14:57 roberto Exp $
|
||||
** Opcodes for Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -76,37 +76,37 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */
|
||||
** the following macros help to manipulate instructions
|
||||
*/
|
||||
|
||||
#define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0)))
|
||||
#define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o))
|
||||
#define GET_OPCODE(i) (cast(OpCode, (i)&MASK1(SIZE_OP,0)))
|
||||
#define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | cast(Instruction, o))
|
||||
|
||||
#define GETARG_A(i) ((int)((i)>>POS_A))
|
||||
#define GETARG_A(i) (cast(int, (i)>>POS_A))
|
||||
#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
|
||||
((Instruction)(u)<<POS_A)))
|
||||
(cast(Instruction, u)<<POS_A)))
|
||||
|
||||
#define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0)))
|
||||
#define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
|
||||
#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
|
||||
((Instruction)(b)<<POS_B)))
|
||||
(cast(Instruction, b)<<POS_B)))
|
||||
|
||||
#define GETARG_C(i) ((int)(((i)>>POS_C) & MASK1(SIZE_C,0)))
|
||||
#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
|
||||
#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
|
||||
((Instruction)(b)<<POS_C)))
|
||||
(cast(Instruction, b)<<POS_C)))
|
||||
|
||||
#define GETARG_Bc(i) ((int)(((i)>>POS_Bc) & MASK1(SIZE_Bc,0)))
|
||||
#define GETARG_Bc(i) (cast(int, ((i)>>POS_Bc) & MASK1(SIZE_Bc,0)))
|
||||
#define SETARG_Bc(i,b) ((i) = (((i)&MASK0(SIZE_Bc,POS_Bc)) | \
|
||||
((Instruction)(b)<<POS_Bc)))
|
||||
(cast(Instruction, b)<<POS_Bc)))
|
||||
|
||||
#define GETARG_sBc(i) (GETARG_Bc(i)-MAXARG_sBc)
|
||||
#define SETARG_sBc(i,b) SETARG_Bc((i),(unsigned int)((b)+MAXARG_sBc))
|
||||
#define SETARG_sBc(i,b) SETARG_Bc((i),cast(unsigned int, (b)+MAXARG_sBc))
|
||||
|
||||
|
||||
#define CREATE_ABC(o,a,b,c) ((Instruction)(o) \
|
||||
| ((Instruction)(a)<<POS_A) \
|
||||
| ((Instruction)(b)<<POS_B) \
|
||||
| ((Instruction)(c)<<POS_C))
|
||||
#define CREATE_ABC(o,a,b,c) (cast(Instruction, o) \
|
||||
| (cast(Instruction, a)<<POS_A) \
|
||||
| (cast(Instruction, b)<<POS_B) \
|
||||
| (cast(Instruction, c)<<POS_C))
|
||||
|
||||
#define CREATE_ABc(o,a,bc) ((Instruction)(o) \
|
||||
| ((Instruction)(a)<<POS_A) \
|
||||
| ((Instruction)(bc)<<POS_Bc))
|
||||
#define CREATE_ABc(o,a,bc) (cast(Instruction, o) \
|
||||
| (cast(Instruction, a)<<POS_A) \
|
||||
| (cast(Instruction, bc)<<POS_Bc))
|
||||
|
||||
|
||||
|
||||
@ -184,7 +184,7 @@ OP_CLOSURE /* A Bc R(A) := closure(KPROTO[Bc], R(A), ... ,R(A+n)) */
|
||||
} OpCode;
|
||||
|
||||
|
||||
#define NUM_OPCODES ((int)OP_CLOSURE+1)
|
||||
#define NUM_OPCODES (cast(int, OP_CLOSURE+1))
|
||||
|
||||
|
||||
|
||||
@ -215,7 +215,7 @@ enum OpModeMask {
|
||||
|
||||
extern const lu_byte luaP_opmodes[NUM_OPCODES];
|
||||
|
||||
#define getOpMode(m) ((enum OpMode)(luaP_opmodes[m] & 3))
|
||||
#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
|
||||
#define testOpMode(m, b) (luaP_opmodes[m] & (1 << (b)))
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lparser.c,v 1.153 2001/08/10 20:53:03 roberto Exp roberto $
|
||||
** $Id: lparser.c,v 1.154 2001/08/27 15:16:28 roberto Exp $
|
||||
** Lua Parser
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -266,7 +266,7 @@ static void code_params (LexState *ls, int nparams, short dots) {
|
||||
FuncState *fs = ls->fs;
|
||||
adjustlocalvars(ls, nparams);
|
||||
luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters"));
|
||||
fs->f->numparams = (short)fs->nactloc; /* `self' could be there already */
|
||||
fs->f->numparams = cast(short, fs->nactloc); /* `self' could be there already */
|
||||
fs->f->is_vararg = dots;
|
||||
if (dots) {
|
||||
new_localvarstr(ls, l_s("arg"), 0);
|
||||
@ -758,13 +758,13 @@ static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
|
||||
else simpleexp(ls, v);
|
||||
/* expand while operators have priorities higher than `limit' */
|
||||
op = getbinopr(ls->t.token);
|
||||
while (op != OPR_NOBINOPR && (int)priority[op].left > limit) {
|
||||
while (op != OPR_NOBINOPR && cast(int, priority[op].left) > limit) {
|
||||
expdesc v2;
|
||||
BinOpr nextop;
|
||||
next(ls);
|
||||
luaK_infix(ls->fs, op, v);
|
||||
/* read sub-expression with higher priority */
|
||||
nextop = subexpr(ls, &v2, (int)priority[op].right);
|
||||
nextop = subexpr(ls, &v2, cast(int, priority[op].right));
|
||||
luaK_posfix(ls->fs, op, v, &v2);
|
||||
op = nextop;
|
||||
}
|
||||
|
4
lstate.c
4
lstate.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.c,v 1.65 2001/06/21 16:41:34 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 1.66 2001/07/17 17:54:46 roberto Exp $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -33,7 +33,7 @@ static void close_state (lua_State *L, lua_State *OL);
|
||||
** open parts that may cause memory-allocation errors
|
||||
*/
|
||||
static void f_luaopen (lua_State *L, void *ud) {
|
||||
struct Sopen *so = (struct Sopen *)ud;
|
||||
struct Sopen *so = cast(struct Sopen *, ud);
|
||||
if (so->stacksize == 0)
|
||||
so->stacksize = DEFAULT_STACK_SIZE;
|
||||
else
|
||||
|
10
lstring.c
10
lstring.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstring.c,v 1.65 2001/06/15 20:36:57 roberto Exp roberto $
|
||||
** $Id: lstring.c,v 1.66 2001/08/27 15:16:28 roberto Exp $
|
||||
** String table (keeps all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) {
|
||||
TString *next = p->tsv.nexthash; /* save next */
|
||||
lu_hash h = p->tsv.hash;
|
||||
int h1 = lmod(h, newsize); /* new position */
|
||||
lua_assert((int)(h%newsize) == lmod(h, newsize));
|
||||
lua_assert(cast(int, h%newsize) == lmod(h, newsize));
|
||||
p->tsv.nexthash = newhash[h1]; /* chain it in new position */
|
||||
newhash[h1] = p;
|
||||
p = next;
|
||||
@ -48,7 +48,7 @@ void luaS_resize (lua_State *L, int newsize) {
|
||||
|
||||
|
||||
static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) {
|
||||
TString *ts = (TString *)luaM_malloc(L, sizestring(l));
|
||||
TString *ts = cast(TString *, luaM_malloc(L, sizestring(l)));
|
||||
stringtable *tb;
|
||||
ts->tsv.nexthash = NULL;
|
||||
ts->tsv.len = l;
|
||||
@ -61,7 +61,7 @@ static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) {
|
||||
ts->tsv.nexthash = tb->hash[h]; /* chain new entry */
|
||||
tb->hash[h] = ts;
|
||||
tb->nuse++;
|
||||
if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2)
|
||||
if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2)
|
||||
luaS_resize(L, tb->size*2); /* too crowded */
|
||||
return ts;
|
||||
}
|
||||
@ -85,7 +85,7 @@ TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) {
|
||||
|
||||
|
||||
Udata *luaS_newudata (lua_State *L, size_t s) {
|
||||
Udata *u = (Udata *)luaM_malloc(L, sizeudata(s));
|
||||
Udata *u = cast(Udata *, luaM_malloc(L, sizeudata(s)));
|
||||
u->uv.len = s;
|
||||
u->uv.tag = 0;
|
||||
u->uv.value = u + 1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstring.h,v 1.32 2001/06/06 18:00:19 roberto Exp roberto $
|
||||
** $Id: lstring.h,v 1.33 2001/06/15 20:36:57 roberto Exp $
|
||||
** String table (keep all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -21,10 +21,10 @@
|
||||
#define RESERVEDMARK 3
|
||||
|
||||
|
||||
#define sizestring(l) ((lu_mem)sizeof(union TString)+ \
|
||||
((lu_mem)(l)+1)*sizeof(l_char))
|
||||
#define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \
|
||||
(cast(lu_mem, l)+1)*sizeof(l_char))
|
||||
|
||||
#define sizeudata(l) ((lu_mem)sizeof(union Udata)+(l))
|
||||
#define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l))
|
||||
|
||||
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \
|
||||
|
@ -91,7 +91,7 @@ static int str_byte (lua_State *L) {
|
||||
size_t l;
|
||||
const l_char *s = luaL_check_lstr(L, 1, &l);
|
||||
sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l);
|
||||
luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, l_s("out of range"));
|
||||
luaL_arg_check(L, 0 < pos && (size_t)(pos) <= l, 2, l_s("out of range"));
|
||||
lua_pushnumber(L, uchar(s[pos-1]));
|
||||
return 1;
|
||||
}
|
||||
@ -424,7 +424,7 @@ static int str_find (lua_State *L) {
|
||||
const l_char *s = luaL_check_lstr(L, 1, &l1);
|
||||
const l_char *p = luaL_check_lstr(L, 2, &l2);
|
||||
sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
|
||||
luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, l_s("out of range"));
|
||||
luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, l_s("out of range"));
|
||||
if (lua_gettop(L) > 3 || /* extra argument? */
|
||||
strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
|
||||
const l_char *s2 = lmemfind(s+init, l1-init, p, l2);
|
||||
@ -603,7 +603,7 @@ static int str_format (lua_State *L) {
|
||||
sprintf(buff, form, luaL_check_int(L, arg));
|
||||
break;
|
||||
case l_c('o'): case l_c('u'): case l_c('x'): case l_c('X'):
|
||||
sprintf(buff, form, (unsigned int)luaL_check_number(L, arg));
|
||||
sprintf(buff, form, (unsigned int)(luaL_check_number(L, arg)));
|
||||
break;
|
||||
case l_c('e'): case l_c('E'): case l_c('f'):
|
||||
case l_c('g'): case l_c('G'):
|
||||
|
14
ltable.c
14
ltable.c
@ -32,9 +32,9 @@
|
||||
#define TagDefault LUA_TTABLE
|
||||
|
||||
|
||||
#define hashnum(t,n) (node(t, lmod((lu_hash)(ls_hash)(n), t->size)))
|
||||
#define hashstr(t,str) (node(t, lmod((str)->tsv.hash, t->size)))
|
||||
#define hashpointer(t,p) (node(t, lmod(IntPoint(p), t->size)))
|
||||
#define hashnum(t,n) (node(t, lmod(cast(lu_hash, cast(ls_hash, n)), t->size)))
|
||||
#define hashstr(t,str) (node(t, lmod((str)->tsv.hash, t->size)))
|
||||
#define hashpointer(t,p) (node(t, lmod(IntPoint(p), t->size)))
|
||||
|
||||
|
||||
/*
|
||||
@ -61,8 +61,8 @@ Node *luaH_next (lua_State *L, Hash *t, const TObject *key) {
|
||||
const TObject *v = luaH_get(t, key);
|
||||
if (v == &luaO_nilobject)
|
||||
luaD_error(L, l_s("invalid key for `next'"));
|
||||
i = (int)(((const lu_byte *)v -
|
||||
(const lu_byte *)(val(node(t, 0)))) / sizeof(Node)) + 1;
|
||||
i = cast(int, (cast(const lu_byte *, v) -
|
||||
cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)) + 1;
|
||||
}
|
||||
for (; i<t->size; i++) {
|
||||
Node *n = node(t, i);
|
||||
@ -259,8 +259,8 @@ const TObject *luaH_get (Hash *t, const TObject *key) {
|
||||
switch (ttype(key)) {
|
||||
case LUA_TSTRING: return luaH_getstr(t, tsvalue(key));
|
||||
case LUA_TNUMBER: {
|
||||
int k = (int)nvalue(key);
|
||||
if ((lua_Number)k == nvalue(key)) /* is an integer index? */
|
||||
int k = cast(int, nvalue(key));
|
||||
if (cast(lua_Number, k) == nvalue(key)) /* is an integer index? */
|
||||
return luaH_getnum(t, k); /* use specialized version */
|
||||
/* else go through */
|
||||
}
|
||||
|
2
ltable.h
2
ltable.h
@ -14,7 +14,7 @@
|
||||
#define key(_n) (&(_n)->key)
|
||||
#define val(_n) (&(_n)->val)
|
||||
|
||||
#define settableval(p,v) setobj((TObject *)p, v)
|
||||
#define settableval(p,v) setobj(cast(TObject *, p), v)
|
||||
|
||||
|
||||
const TObject *luaH_getnum (Hash *t, int key);
|
||||
|
50
ltests.c
50
ltests.c
@ -64,7 +64,7 @@ static void setnameval (lua_State *L, const l_char *name, int val) {
|
||||
#define MARK 0x55 /* 01010101 (a nice pattern) */
|
||||
|
||||
|
||||
#define blocksize(b) ((size_t *)(b) - HEADER/sizeof(size_t))
|
||||
#define blocksize(b) (cast(size_t *, b) - HEADER/sizeof(size_t))
|
||||
|
||||
unsigned long memdebug_numblocks = 0;
|
||||
unsigned long memdebug_total = 0;
|
||||
@ -77,7 +77,7 @@ static void *checkblock (void *block) {
|
||||
size_t size = *b;
|
||||
int i;
|
||||
for (i=0;i<MARKSIZE;i++)
|
||||
lua_assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */
|
||||
lua_assert(*(cast(char *, b)+HEADER+size+i) == MARK+i); /* corrupted block? */
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -111,19 +111,19 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
|
||||
if (newblock == NULL) return NULL;
|
||||
if (oldsize > size) oldsize = size;
|
||||
if (block) {
|
||||
memcpy((char *)newblock+HEADER, block, oldsize);
|
||||
memcpy(cast(char *, newblock)+HEADER, block, oldsize);
|
||||
freeblock(block); /* erase (and check) old copy */
|
||||
}
|
||||
/* initialize new part of the block with something `weird' */
|
||||
memset((char *)newblock+HEADER+oldsize, -MARK, size-oldsize);
|
||||
memset(cast(char *, newblock)+HEADER+oldsize, -MARK, size-oldsize);
|
||||
memdebug_total += size;
|
||||
if (memdebug_total > memdebug_maxmem)
|
||||
memdebug_maxmem = memdebug_total;
|
||||
memdebug_numblocks++;
|
||||
*(size_t *)newblock = size;
|
||||
*cast(size_t *, newblock) = size;
|
||||
for (i=0;i<MARKSIZE;i++)
|
||||
*((char *)newblock+HEADER+size+i) = (char)(MARK+i);
|
||||
return (char *)newblock+HEADER;
|
||||
*(cast(char *, newblock)+HEADER+size+i) = cast(char, MARK+i);
|
||||
return cast(char *, newblock)+HEADER;
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,13 +343,13 @@ static int unref (lua_State *L) {
|
||||
|
||||
static int newuserdata (lua_State *L) {
|
||||
size_t size = luaL_check_int(L, 1);
|
||||
l_char *p = (l_char *)lua_newuserdata(L, size);
|
||||
l_char *p = cast(l_char *, lua_newuserdata(L, size));
|
||||
while (size--) *p++ = l_c('\0');
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int newuserdatabox (lua_State *L) {
|
||||
lua_newuserdatabox(L, (void *)luaL_check_int(L, 1));
|
||||
lua_newuserdatabox(L, cast(void *, luaL_check_int(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -362,20 +362,20 @@ static int settag (lua_State *L) {
|
||||
|
||||
static int udataval (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TUSERDATA);
|
||||
lua_pushnumber(L, (int)lua_touserdata(L, 1));
|
||||
lua_pushnumber(L, cast(int, lua_touserdata(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int newtag (lua_State *L) {
|
||||
lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1),
|
||||
(int)lua_tonumber(L, 2)));
|
||||
cast(int, lua_tonumber(L, 2))));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int doonnewstack (lua_State *L) {
|
||||
lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1));
|
||||
if (L1 == NULL) return 0;
|
||||
*((int **)L1) = &islocked; /* initialize the lock */
|
||||
*cast(int **, L1) = &islocked; /* initialize the lock */
|
||||
lua_dostring(L1, luaL_check_string(L, 2));
|
||||
lua_pushnumber(L, 1);
|
||||
lua_close(L1);
|
||||
@ -384,13 +384,13 @@ static int doonnewstack (lua_State *L) {
|
||||
|
||||
|
||||
static int s2d (lua_State *L) {
|
||||
lua_pushnumber(L, *(double *)luaL_check_string(L, 1));
|
||||
lua_pushnumber(L, *cast(double *, luaL_check_string(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int d2s (lua_State *L) {
|
||||
double d = luaL_check_number(L, 1);
|
||||
lua_pushlstring(L, (l_char *)&d, sizeof(d));
|
||||
lua_pushlstring(L, cast(l_char *, &d), sizeof(d));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -398,7 +398,7 @@ static int d2s (lua_State *L) {
|
||||
static int newstate (lua_State *L) {
|
||||
lua_State *L1 = lua_open(luaL_check_int(L, 1));
|
||||
if (L1) {
|
||||
*((int **)L1) = &islocked; /* initialize the lock */
|
||||
*cast(int **, L1) = &islocked; /* initialize the lock */
|
||||
lua_pushnumber(L, (unsigned long)L1);
|
||||
}
|
||||
else
|
||||
@ -407,7 +407,7 @@ static int newstate (lua_State *L) {
|
||||
}
|
||||
|
||||
static int loadlib (lua_State *L) {
|
||||
lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1);
|
||||
lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
|
||||
lua_register(L1, "mathlibopen", lua_mathlibopen);
|
||||
lua_register(L1, "strlibopen", lua_strlibopen);
|
||||
lua_register(L1, "iolibopen", lua_iolibopen);
|
||||
@ -417,7 +417,7 @@ static int loadlib (lua_State *L) {
|
||||
}
|
||||
|
||||
static int closestate (lua_State *L) {
|
||||
lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1);
|
||||
lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
|
||||
lua_close(L1);
|
||||
lua_unlock(L); /* close cannot unlock that */
|
||||
return 0;
|
||||
@ -427,7 +427,7 @@ static int doremote (lua_State *L) {
|
||||
lua_State *L1;
|
||||
const l_char *code = luaL_check_string(L, 2);
|
||||
int status;
|
||||
L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1);
|
||||
L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
|
||||
status = lua_dostring(L1, code);
|
||||
if (status != 0) {
|
||||
lua_pushnil(L);
|
||||
@ -472,12 +472,12 @@ static void skip (const l_char **pc) {
|
||||
while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++;
|
||||
}
|
||||
|
||||
static int getnum (lua_State *L, const l_char **pc) {
|
||||
static int getnum_aux (lua_State *L, const l_char **pc) {
|
||||
int res = 0;
|
||||
int sig = 1;
|
||||
skip(pc);
|
||||
if (**pc == l_c('.')) {
|
||||
res = (int)lua_tonumber(L, -1);
|
||||
res = cast(int, lua_tonumber(L, -1));
|
||||
lua_pop(L, 1);
|
||||
(*pc)++;
|
||||
return res;
|
||||
@ -486,11 +486,11 @@ static int getnum (lua_State *L, const l_char **pc) {
|
||||
sig = -1;
|
||||
(*pc)++;
|
||||
}
|
||||
while (isdigit((int)**pc)) res = res*10 + (*(*pc)++) - l_c('0');
|
||||
while (isdigit(cast(int, **pc))) res = res*10 + (*(*pc)++) - l_c('0');
|
||||
return sig*res;
|
||||
}
|
||||
|
||||
static const l_char *getname (l_char *buff, const l_char **pc) {
|
||||
static const l_char *getname_aux (l_char *buff, const l_char **pc) {
|
||||
int i = 0;
|
||||
skip(pc);
|
||||
while (**pc != l_c('\0') && !strchr(delimits, **pc))
|
||||
@ -502,8 +502,8 @@ static const l_char *getname (l_char *buff, const l_char **pc) {
|
||||
|
||||
#define EQ(s1) (strcmp(s1, inst) == 0)
|
||||
|
||||
#define getnum ((getnum)(L, &pc))
|
||||
#define getname ((getname)(buff, &pc))
|
||||
#define getnum (getnum_aux(L, &pc))
|
||||
#define getname (getname_aux(buff, &pc))
|
||||
|
||||
|
||||
static int testC (lua_State *L) {
|
||||
@ -661,7 +661,7 @@ static const struct luaL_reg tests_funcs[] = {
|
||||
|
||||
|
||||
void luaB_opentests (lua_State *L) {
|
||||
*((int **)L) = &islocked; /* init lock */
|
||||
*cast(int **, L) = &islocked; /* init lock */
|
||||
lua_state = L; /* keep first state to be opened */
|
||||
/* open lib in a new table */
|
||||
lua_newtable(L);
|
||||
|
6
ltests.h
6
ltests.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltests.h,v 1.6 2001/03/02 17:27:50 roberto Exp roberto $
|
||||
** $Id: ltests.h,v 1.7 2001/06/28 19:58:57 roberto Exp $
|
||||
** Internal Header for Debugging of the Lua Implementation
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -43,8 +43,8 @@ void *debug_realloc (void *block, size_t oldsize, size_t size);
|
||||
/* test for lock/unlock */
|
||||
#define LUA_USERSTATE int *lock;
|
||||
extern int islocked;
|
||||
#define lua_lock(L) lua_assert((**((int **)L))++ == 0)
|
||||
#define lua_unlock(L) lua_assert(--(**((int **)L)) == 0)
|
||||
#define lua_lock(L) lua_assert((**cast(int **, L))++ == 0)
|
||||
#define lua_unlock(L) lua_assert(--(**cast(int **, L)) == 0)
|
||||
|
||||
|
||||
extern lua_State *lua_state;
|
||||
|
4
ltm.c
4
ltm.c
@ -61,7 +61,7 @@ static const lu_byte luaT_validevents[NUM_TAGS][TM_N] = {
|
||||
};
|
||||
|
||||
int luaT_validevent (int t, int e) { /* ORDER LUA_T */
|
||||
return (t >= NUM_TAGS) ? 1 : (int)luaT_validevents[t][e];
|
||||
return (t >= NUM_TAGS) ? 1 : cast(int, luaT_validevents[t][e]);
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ int luaT_newtag (lua_State *L, const l_char *name, int basictype) {
|
||||
TObject otag;
|
||||
ts = luaS_new(L, name);
|
||||
v = luaH_getstr(G(L)->type2tag, ts);
|
||||
if (ttype(v) == LUA_TNUMBER) return (int)nvalue(v);
|
||||
if (ttype(v) == LUA_TNUMBER) return cast(int, nvalue(v));
|
||||
setnvalue(&otag, tag);
|
||||
luaH_setstr(L, G(L)->type2tag, ts, &otag);
|
||||
}
|
||||
|
6
lvm.c
6
lvm.c
@ -293,8 +293,8 @@ void luaV_strconc (lua_State *L, int total, StkId top) {
|
||||
luaG_concaterror(L, top-2, top-1);
|
||||
} else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
|
||||
/* at least two string values; get as many as possible */
|
||||
lu_mem tl = (lu_mem)tsvalue(top-1)->tsv.len +
|
||||
(lu_mem)tsvalue(top-2)->tsv.len;
|
||||
lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) +
|
||||
cast(lu_mem, tsvalue(top-2)->tsv.len);
|
||||
l_char *buffer;
|
||||
int i;
|
||||
while (n < total && !tostring(L, top-n-1)) { /* collect total length */
|
||||
@ -618,7 +618,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
|
||||
runtime_check(L, ttype(ra) == LUA_TTABLE &&
|
||||
ttype(ra+1) == LUA_TNUMBER);
|
||||
t = hvalue(ra);
|
||||
n = (int)nvalue(ra+1);
|
||||
n = cast(int, nvalue(ra+1));
|
||||
n = luaH_nexti(t, n);
|
||||
if (n != -1) { /* repeat loop? */
|
||||
Node *node = node(t, n);
|
||||
|
Loading…
Reference in New Issue
Block a user