File: lobject.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (84 lines) | stat: -rw-r--r-- 2,087 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/

#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp

#include "engines/grim/lua/lobject.h"
#include "engines/grim/lua/lua.h"
#include "engines/grim/lua/lstring.h"
#include "engines/grim/lua/lstate.h"

namespace Grim {

const char *luaO_typenames[] = { // ORDER LUA_T
	"userdata", "number", "string", "table", "function", "function", "task",
	"nil", "function", "mark", "mark", "mark", "line", nullptr
};

TObject luaO_nilobject = { LUA_T_NIL, { nullptr } };


// hash dimensions values
static int32 dimensions[] = {
	5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421,
	12853, 25717, 51437, 102811, 205619, 411233, 822433,
	1644817, 3289613, 6579211, 13158023, MAX_INT
};

int32 luaO_redimension(int32 oldsize) {
	for (int32 i = 0; dimensions[i] < MAX_INT; i++) {
		if (dimensions[i] > oldsize)
			return dimensions[i];
	}
	lua_error("table overflow");
	return 0;  // to avoid warnings
}

int32 luaO_equalObj(TObject *t1, TObject *t2) {
	if (ttype(t1) != ttype(t2))
		return 0;
	switch (ttype(t1)) {
	case LUA_T_NIL:
		return 1;
	case LUA_T_NUMBER:
		return nvalue(t1) == nvalue(t2);
	case LUA_T_USERDATA:
		return (t1->value.ud.id == t2->value.ud.id && t1->value.ud.tag == t2->value.ud.tag);
	case LUA_T_STRING:
		return tsvalue(t1) == tsvalue(t2);
	case LUA_T_ARRAY:
		return avalue(t1) == avalue(t2);
	case LUA_T_PROTO:
		return tfvalue(t1) == tfvalue(t2);
	case LUA_T_CPROTO:
		return fvalue(t1) == fvalue(t2);
	case LUA_T_CLOSURE:
		return t1->value.cl == t2->value.cl;
	case LUA_T_TASK:
		return nvalue(t1) == nvalue(t2);
	default:
#ifdef LUA_DEBUG
		LUA_INTERNALERROR("internal error in `lua_equalObj'");
#endif
		return 0; // UNREACHABLE
	}
}

int luaO_findstring(const char *name, const char *list[]) {
	for (int i = 0; list[i]; i++)
		if (strcmp(list[i], name) == 0)
			return i;
	return -1;  // name not found
}

void luaO_insertlist(GCnode *root, GCnode *node) {
	node->next = root->next;
	root->next = node;
	node->marked = 0;
}

} // end of namespace Grim