annotate lib/lua/lua-5.2.2/ltm.c @ 2412:e7a551f458e1

LoadSound - cause of the crash exe file
author Ritor1
date Wed, 16 Jul 2014 17:22:12 +0600
parents 41cc4dd3c122
children
rev   line source
1866
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
1 /*
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
2 ** $Id: ltm.c,v 2.14 2011/06/02 19:31:40 roberto Exp $
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
3 ** Tag methods
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
4 ** See Copyright Notice in lua.h
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
5 */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
6
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
7
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
8 #include <string.h>
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
9
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
10 #define ltm_c
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
11 #define LUA_CORE
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
12
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
13 #include "lua.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
14
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
15 #include "lobject.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
16 #include "lstate.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
17 #include "lstring.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
18 #include "ltable.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
19 #include "ltm.h"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
20
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
21
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
22 static const char udatatypename[] = "userdata";
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
23
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
24 LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
25 "no value",
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
26 "nil", "boolean", udatatypename, "number",
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
27 "string", "table", "function", udatatypename, "thread",
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
28 "proto", "upval" /* these last two cases are used for tests only */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
29 };
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
30
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
31
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
32 void luaT_init (lua_State *L) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
33 static const char *const luaT_eventname[] = { /* ORDER TM */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
34 "__index", "__newindex",
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
35 "__gc", "__mode", "__len", "__eq",
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
36 "__add", "__sub", "__mul", "__div", "__mod",
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
37 "__pow", "__unm", "__lt", "__le",
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
38 "__concat", "__call"
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
39 };
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
40 int i;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
41 for (i=0; i<TM_N; i++) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
42 G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
43 luaS_fix(G(L)->tmname[i]); /* never collect these names */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
44 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
45 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
46
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
47
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
48 /*
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
49 ** function to be used with macro "fasttm": optimized for absence of
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
50 ** tag methods
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
51 */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
52 const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
53 const TValue *tm = luaH_getstr(events, ename);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
54 lua_assert(event <= TM_EQ);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
55 if (ttisnil(tm)) { /* no tag method? */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
56 events->flags |= cast_byte(1u<<event); /* cache this fact */
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
57 return NULL;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
58 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
59 else return tm;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
60 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
61
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
62
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
63 const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
64 Table *mt;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
65 switch (ttypenv(o)) {
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
66 case LUA_TTABLE:
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
67 mt = hvalue(o)->metatable;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
68 break;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
69 case LUA_TUSERDATA:
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
70 mt = uvalue(o)->metatable;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
71 break;
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
72 default:
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
73 mt = G(L)->mt[ttypenv(o)];
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
74 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
75 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
76 }
41cc4dd3c122 Lua 5.2.2 added.
Nomad
parents:
diff changeset
77