This commit is contained in:
Roberto Ierusalimschy 1999-08-10 09:55:47 -03:00
parent 4bbe0679a8
commit a82c8185bc
1 changed files with 19 additions and 18 deletions

37
lvm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 1.57 1999/05/21 19:41:49 roberto Exp roberto $ ** $Id: lvm.c,v 1.58 1999/06/22 20:37:23 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -53,7 +53,7 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
if (ttype(obj) != LUA_T_STRING) if (ttype(obj) != LUA_T_STRING)
return 1; return 1;
else { else {
double t; real t;
char *e = svalue(obj); char *e = svalue(obj);
int sig = 1; int sig = 1;
while (isspace((unsigned char)*e)) e++; while (isspace((unsigned char)*e)) e++;
@ -65,9 +65,9 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
/* no digit before or after decimal point? */ /* no digit before or after decimal point? */
if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1))) if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1)))
return 2; return 2;
t = luaO_str2d(e); t = (real)luaO_str2d(e);
if (t<0) return 2; if (t<0) return 2;
nvalue(obj) = (real)t*sig; nvalue(obj) = t*sig;
ttype(obj) = LUA_T_NUMBER; ttype(obj) = LUA_T_NUMBER;
return 0; return 0;
} }
@ -186,23 +186,24 @@ void luaV_rawsettable (TObject *t) {
void luaV_getglobal (TaggedString *ts) { void luaV_getglobal (TaggedString *ts) {
/* WARNING: caller must assure stack space */ /* WARNING: caller must assure stack space */
/* only userdata, tables and nil can have getglobal tag methods */
static char valid_getglobals[] = {1, 0, 0, 1, 0, 0, 1, 0}; /* ORDER LUA_T */
TObject *value = &ts->u.s.globalval; TObject *value = &ts->u.s.globalval;
if (valid_getglobals[-ttype(value)]) { switch (ttype(value)) {
TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL); /* only userdata, tables and nil can have getglobal tag methods */
if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */ case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: {
struct Stack *S = &L->stack; TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL);
ttype(S->top) = LUA_T_STRING; if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */
tsvalue(S->top) = ts; struct Stack *S = &L->stack;
S->top++; ttype(S->top) = LUA_T_STRING;
*S->top++ = *value; tsvalue(S->top) = ts;
luaD_callTM(im, 2, 1); S->top++;
return; *S->top++ = *value;
luaD_callTM(im, 2, 1);
return;
}
/* else no tag method: go through to default behavior */
} }
/* else no tag method: go through to default behavior */ default: *L->stack.top++ = *value; /* default behavior */
} }
*L->stack.top++ = *value; /* default behavior */
} }