diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-10 09:55:47 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-10 09:55:47 -0300 |
commit | a82c8185bc351666c801ba437064becc41cd57a5 (patch) | |
tree | aae043977942f75f74ac3cccb4a1cde8103dc419 /lvm.c | |
parent | 4bbe0679a857727f9d2d172da88f2bb9b0f34cd3 (diff) | |
download | lua-a82c8185bc351666c801ba437064becc41cd57a5.tar.gz lua-a82c8185bc351666c801ba437064becc41cd57a5.tar.bz2 lua-a82c8185bc351666c801ba437064becc41cd57a5.zip |
details
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.57 1999/05/21 19:41:49 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.58 1999/06/22 20:37:23 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -53,7 +53,7 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */ | |||
53 | if (ttype(obj) != LUA_T_STRING) | 53 | if (ttype(obj) != LUA_T_STRING) |
54 | return 1; | 54 | return 1; |
55 | else { | 55 | else { |
56 | double t; | 56 | real t; |
57 | char *e = svalue(obj); | 57 | char *e = svalue(obj); |
58 | int sig = 1; | 58 | int sig = 1; |
59 | while (isspace((unsigned char)*e)) e++; | 59 | while (isspace((unsigned char)*e)) e++; |
@@ -65,9 +65,9 @@ int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */ | |||
65 | /* no digit before or after decimal point? */ | 65 | /* no digit before or after decimal point? */ |
66 | if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1))) | 66 | if (!isdigit((unsigned char)*e) && !isdigit((unsigned char)*(e+1))) |
67 | return 2; | 67 | return 2; |
68 | t = luaO_str2d(e); | 68 | t = (real)luaO_str2d(e); |
69 | if (t<0) return 2; | 69 | if (t<0) return 2; |
70 | nvalue(obj) = (real)t*sig; | 70 | nvalue(obj) = t*sig; |
71 | ttype(obj) = LUA_T_NUMBER; | 71 | ttype(obj) = LUA_T_NUMBER; |
72 | return 0; | 72 | return 0; |
73 | } | 73 | } |
@@ -186,23 +186,24 @@ void luaV_rawsettable (TObject *t) { | |||
186 | 186 | ||
187 | void luaV_getglobal (TaggedString *ts) { | 187 | void luaV_getglobal (TaggedString *ts) { |
188 | /* WARNING: caller must assure stack space */ | 188 | /* WARNING: caller must assure stack space */ |
189 | /* only userdata, tables and nil can have getglobal tag methods */ | ||
190 | static char valid_getglobals[] = {1, 0, 0, 1, 0, 0, 1, 0}; /* ORDER LUA_T */ | ||
191 | TObject *value = &ts->u.s.globalval; | 189 | TObject *value = &ts->u.s.globalval; |
192 | if (valid_getglobals[-ttype(value)]) { | 190 | switch (ttype(value)) { |
193 | TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL); | 191 | /* only userdata, tables and nil can have getglobal tag methods */ |
194 | if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */ | 192 | case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: { |
195 | struct Stack *S = &L->stack; | 193 | TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL); |
196 | ttype(S->top) = LUA_T_STRING; | 194 | if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */ |
197 | tsvalue(S->top) = ts; | 195 | struct Stack *S = &L->stack; |
198 | S->top++; | 196 | ttype(S->top) = LUA_T_STRING; |
199 | *S->top++ = *value; | 197 | tsvalue(S->top) = ts; |
200 | luaD_callTM(im, 2, 1); | 198 | S->top++; |
201 | return; | 199 | *S->top++ = *value; |
200 | luaD_callTM(im, 2, 1); | ||
201 | return; | ||
202 | } | ||
203 | /* else no tag method: go through to default behavior */ | ||
202 | } | 204 | } |
203 | /* else no tag method: go through to default behavior */ | 205 | default: *L->stack.top++ = *value; /* default behavior */ |
204 | } | 206 | } |
205 | *L->stack.top++ = *value; /* default behavior */ | ||
206 | } | 207 | } |
207 | 208 | ||
208 | 209 | ||