diff options
Diffstat (limited to '')
| -rw-r--r-- | lobject.c | 30 |
1 files changed, 29 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.69 2001/03/07 12:27:06 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.70 2001/03/26 14:31:49 roberto Exp $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -23,6 +23,34 @@ | |||
| 23 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; | 23 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | int luaO_log2 (unsigned int x) { | ||
| 27 | static const lu_byte log_8[255] = { | ||
| 28 | 0, | ||
| 29 | 1,1, | ||
| 30 | 2,2,2,2, | ||
| 31 | 3,3,3,3,3,3,3,3, | ||
| 32 | 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, | ||
| 33 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
| 34 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 35 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 36 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 37 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 38 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 39 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 40 | }; | ||
| 41 | if (x & 0xffff0000) { | ||
| 42 | if (x & 0xff000000) return log_8[((x>>24) & 0xff) - 1]+24; | ||
| 43 | else return log_8[((x>>16) & 0xff) - 1]+16; | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | if (x & 0x0000ff00) return log_8[((x>>8) & 0xff) - 1]+8; | ||
| 47 | else if (x) return log_8[(x & 0xff) - 1]; | ||
| 48 | return -1; /* special `log' for 0 */ | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | |||
| 26 | int luaO_equalObj (const TObject *t1, const TObject *t2) { | 54 | int luaO_equalObj (const TObject *t1, const TObject *t2) { |
| 27 | if (ttype(t1) != ttype(t2)) return 0; | 55 | if (ttype(t1) != ttype(t2)) return 0; |
| 28 | switch (ttype(t1)) { | 56 | switch (ttype(t1)) { |
