diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-16 16:25:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-09-16 16:25:59 -0300 |
commit | c1801e623f75dab3ccc4444ebe76417e1ef88afb (patch) | |
tree | f09c2221e1607601ae630a51be088e38b5a62339 | |
parent | a404f6e0e621927dc3765db556a7f4e645756a47 (diff) | |
download | lua-c1801e623f75dab3ccc4444ebe76417e1ef88afb.tar.gz lua-c1801e623f75dab3ccc4444ebe76417e1ef88afb.tar.bz2 lua-c1801e623f75dab3ccc4444ebe76417e1ef88afb.zip |
Some generic functions over Lua objects
-rw-r--r-- | lobject.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lobject.c b/lobject.c new file mode 100644 index 00000000..b9cabb0b --- /dev/null +++ b/lobject.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | ** $Id: $ | ||
3 | ** Some generic functions over Lua objects | ||
4 | ** See Copyright Notice in lua.h | ||
5 | */ | ||
6 | |||
7 | #include <stdlib.h> | ||
8 | #include <string.h> | ||
9 | |||
10 | #include "lobject.h" | ||
11 | #include "lua.h" | ||
12 | |||
13 | |||
14 | char *luaO_typenames[] = { /* ORDER LUA_T */ | ||
15 | "userdata", "line", "cmark", "mark", "function", "function", | ||
16 | "prototype", "table", "string", "number", "nil", | ||
17 | NULL | ||
18 | }; | ||
19 | |||
20 | |||
21 | long luaO_nentities = 0; | ||
22 | |||
23 | |||
24 | /* hash dimensions values */ | ||
25 | static long dimensions[] = | ||
26 | {5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L, | ||
27 | 12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L, | ||
28 | 1644817L, 3289613L, 6579211L, 13158023L, MAX_INT}; | ||
29 | |||
30 | |||
31 | int luaO_redimension (int oldsize) | ||
32 | { | ||
33 | int i; | ||
34 | for (i=0; dimensions[i]<MAX_INT; i++) { | ||
35 | if (dimensions[i] > oldsize) | ||
36 | return dimensions[i]; | ||
37 | } | ||
38 | lua_error("table overflow"); | ||
39 | return 0; /* to avoid warnings */ | ||
40 | } | ||
41 | |||
42 | |||
43 | int luaO_equalObj (TObject *t1, TObject *t2) | ||
44 | { | ||
45 | if (ttype(t1) != ttype(t2)) return 0; | ||
46 | switch (ttype(t1)) { | ||
47 | case LUA_T_NIL: return 1; | ||
48 | case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); | ||
49 | case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2); | ||
50 | case LUA_T_ARRAY: return avalue(t1) == avalue(t2); | ||
51 | case LUA_T_FUNCTION: return t1->value.cl == t2->value.cl; | ||
52 | case LUA_T_CFUNCTION: return fvalue(t1) == fvalue(t2); | ||
53 | default: | ||
54 | lua_error("internal error in `lua_equalObj'"); | ||
55 | return 0; /* UNREACHEABLE */ | ||
56 | } | ||
57 | } | ||
58 | |||
59 | |||
60 | int luaO_findstring (char *name, char *list[]) | ||
61 | { | ||
62 | int i; | ||
63 | for (i=0; list[i]; i++) | ||
64 | if (strcmp(list[i], name) == 0) | ||
65 | return i; | ||
66 | return -1; /* name not found */ | ||
67 | } | ||
68 | |||