diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-23 16:19:57 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-23 16:19:57 -0200 |
commit | b1b0c219f5255a0cd0921ebc0a77a81f99b72532 (patch) | |
tree | 7cb4d9cbbdb1309b94794eb75694b02f2b08f75a /lapi.c | |
parent | be3212de781786c0a68365dee1d3510407b5c325 (diff) | |
download | lua-b1b0c219f5255a0cd0921ebc0a77a81f99b72532.tar.gz lua-b1b0c219f5255a0cd0921ebc0a77a81f99b72532.tar.bz2 lua-b1b0c219f5255a0cd0921ebc0a77a81f99b72532.zip |
new ttypes to distinguish between C closures and Lua closures.
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 81 |
1 files changed, 36 insertions, 45 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.63 1999/12/06 12:03:45 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.64 1999/12/14 18:31:20 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -30,19 +30,13 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | |||
30 | 30 | ||
31 | 31 | ||
32 | 32 | ||
33 | lua_Type luaA_normalizedtype (const TObject *o) { | 33 | const lua_Type luaA_normtype[] = { /* ORDER LUA_T */ |
34 | int t = ttype(o); | 34 | LUA_T_USERDATA, LUA_T_NUMBER, LUA_T_STRING, LUA_T_ARRAY, |
35 | switch (t) { | 35 | LUA_T_LPROTO, LUA_T_CPROTO, LUA_T_NIL, |
36 | case LUA_T_PMARK: | 36 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, |
37 | return LUA_T_PROTO; | 37 | LUA_T_LCLOSURE, LUA_T_CCLOSURE, /* LUA_T_LCLMARK, LUA_T_CCLMARK */ |
38 | case LUA_T_CMARK: | 38 | LUA_T_LPROTO, LUA_T_CPROTO /* LUA_T_LMARK, LUA_T_CMARK */ |
39 | return LUA_T_CPROTO; | 39 | }; |
40 | case LUA_T_CLMARK: | ||
41 | return LUA_T_CLOSURE; | ||
42 | default: | ||
43 | return t; | ||
44 | } | ||
45 | } | ||
46 | 40 | ||
47 | 41 | ||
48 | void luaA_setnormalized (TObject *d, const TObject *s) { | 42 | void luaA_setnormalized (TObject *d, const TObject *s) { |
@@ -52,7 +46,15 @@ void luaA_setnormalized (TObject *d, const TObject *s) { | |||
52 | 46 | ||
53 | 47 | ||
54 | const TObject *luaA_protovalue (const TObject *o) { | 48 | const TObject *luaA_protovalue (const TObject *o) { |
55 | return (luaA_normalizedtype(o) == LUA_T_CLOSURE) ? protovalue(o) : o; | 49 | switch (luaA_normalizedtype(o)) { |
50 | case LUA_T_CCLOSURE: case LUA_T_LCLOSURE: | ||
51 | return protovalue(o); | ||
52 | default: | ||
53 | LUA_ASSERT(L, luaA_normalizedtype(o) == LUA_T_LPROTO || | ||
54 | luaA_normalizedtype(o) == LUA_T_CPROTO, | ||
55 | "invalid `function'"); | ||
56 | return o; | ||
57 | } | ||
56 | } | 58 | } |
57 | 59 | ||
58 | 60 | ||
@@ -228,26 +230,32 @@ int lua_isnumber (lua_State *L, lua_Object o) { | |||
228 | } | 230 | } |
229 | 231 | ||
230 | int lua_isstring (lua_State *L, lua_Object o) { | 232 | int lua_isstring (lua_State *L, lua_Object o) { |
231 | int t = lua_tag(L, o); | 233 | UNUSED(L); |
232 | return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); | 234 | return (o != LUA_NOOBJECT && (ttype(o) == LUA_T_STRING || |
235 | ttype(o) == LUA_T_NUMBER)); | ||
233 | } | 236 | } |
234 | 237 | ||
235 | int lua_isfunction (lua_State *L, lua_Object o) { | 238 | int lua_isfunction (lua_State *L, lua_Object o) { |
236 | int t = lua_tag(L, o); | 239 | return *lua_type(L, o) == 'f'; |
237 | return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO); | ||
238 | } | 240 | } |
239 | 241 | ||
240 | int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { | 242 | int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { |
241 | UNUSED(L); | 243 | UNUSED(L); |
242 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) return (o1 == o2); | 244 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) |
243 | else return luaO_equalObj(o1, o2); | 245 | return (o1 == o2); |
246 | else { | ||
247 | TObject obj1, obj2; | ||
248 | luaA_setnormalized(&obj1, o1); | ||
249 | luaA_setnormalized(&obj2, o2); | ||
250 | return luaO_equalObj(&obj1, &obj2); | ||
251 | } | ||
244 | } | 252 | } |
245 | 253 | ||
246 | 254 | ||
247 | double lua_getnumber (lua_State *L, lua_Object obj) { | 255 | double lua_getnumber (lua_State *L, lua_Object obj) { |
248 | UNUSED(L); | 256 | UNUSED(L); |
249 | if (obj == LUA_NOOBJECT) return 0.0; | 257 | if (obj == LUA_NOOBJECT || tonumber(obj)) |
250 | if (tonumber(obj)) return 0.0; | 258 | return 0.0; |
251 | else return (nvalue(obj)); | 259 | else return (nvalue(obj)); |
252 | } | 260 | } |
253 | 261 | ||
@@ -339,28 +347,11 @@ void lua_pushobject (lua_State *L, lua_Object o) { | |||
339 | int lua_tag (lua_State *L, lua_Object o) { | 347 | int lua_tag (lua_State *L, lua_Object o) { |
340 | UNUSED(L); | 348 | UNUSED(L); |
341 | if (o == LUA_NOOBJECT) | 349 | if (o == LUA_NOOBJECT) |
342 | return LUA_T_NIL; | 350 | return LUA_T_NIL; |
343 | else { | 351 | else if (ttype(o) == LUA_T_USERDATA) /* to allow `old' tags (deprecated) */ |
344 | int t; | 352 | return o->value.ts->u.d.tag; |
345 | switch (t = ttype(o)) { | 353 | else |
346 | case LUA_T_USERDATA: | 354 | return luaT_effectivetag(o); |
347 | return o->value.ts->u.d.tag; | ||
348 | case LUA_T_ARRAY: | ||
349 | return o->value.a->htag; | ||
350 | case LUA_T_PMARK: | ||
351 | return LUA_T_PROTO; | ||
352 | case LUA_T_CMARK: | ||
353 | return LUA_T_CPROTO; | ||
354 | case LUA_T_CLOSURE: case LUA_T_CLMARK: | ||
355 | return o->value.cl->consts[0].ttype; | ||
356 | #ifdef DEBUG | ||
357 | case LUA_T_LINE: | ||
358 | LUA_INTERNALERROR(L, "invalid type"); | ||
359 | #endif | ||
360 | default: | ||
361 | return t; | ||
362 | } | ||
363 | } | ||
364 | } | 355 | } |
365 | 356 | ||
366 | 357 | ||