aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/lobject.c b/lobject.c
index b77600be..3b4f945c 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.26 2007/11/09 18:54:25 roberto Exp roberto $ 2** $Id: lobject.c,v 2.27 2007/12/19 17:24:38 roberto Exp roberto $
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*/
@@ -33,7 +33,7 @@ const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
33** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if 33** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
34** eeeee != 0 and (xxx) otherwise. 34** eeeee != 0 and (xxx) otherwise.
35*/ 35*/
36int luaO_int2fb (unsigned int x) { 36int luaO_int2fb (lu_int32 x) {
37 int e = 0; /* exponent */ 37 int e = 0; /* exponent */
38 if (x < 8) return x; 38 if (x < 8) return x;
39 while (x >= 0x10) { 39 while (x >= 0x10) {
@@ -52,6 +52,24 @@ int luaO_fb2int (int x) {
52} 52}
53 53
54 54
55int luaO_ceillog2 (unsigned int x) {
56 static const lu_byte log_2[256] = {
57 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
58 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,
59 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,
60 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,
61 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
62 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
63 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
64 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
65 };
66 int l = 0;
67 x--;
68 while (x >= 256) { l += 8; x >>= 8; }
69 return l + log_2[x];
70}
71
72
55int luaO_rawequalObj (const TValue *t1, const TValue *t2) { 73int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
56 if (ttype(t1) != ttype(t2)) return 0; 74 if (ttype(t1) != ttype(t2)) return 0;
57 else switch (ttype(t1)) { 75 else switch (ttype(t1)) {