A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/*
2** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
3** Tag methods
4** See Copyright Notice in lua.h
5*/
6
7
8#include <string.h>
9
10#define ltm_c
11#define LUA_CORE
12
13#include "lua.h"
14
15#include "lobject.h"
16#include "lstate.h"
17#include "lstring.h"
18#include "ltable.h"
19#include "ltm.h"
20
21
22
23const char *const luaT_typenames[] = {
24 "nil", "boolean", "userdata", "number",
25 "string", "table", "function", "userdata", "thread",
26 "proto", "upval"
27};
28
29
30void luaT_init (lua_State *L) {
31 static const char *const luaT_eventname[] = { /* ORDER TM */
32 "__index", "__newindex",
33 "__gc", "__mode", "__eq",
34 "__add", "__sub", "__mul", "__div", "__mod",
35 "__pow", "__unm", "__len", "__lt", "__le",
36 "__concat", "__call"
37 };
38 int i;
39 for (i=0; i<TM_N; i++) /* never collect these names */
40 G(L)->tmname[i] = luaS_newlloc(L, luaT_eventname[i], TSTR_INBIN | TSTR_FIXED);
41}
42
43
44/*
45** function to be used with macro "fasttm": optimized for absence of
46** tag methods
47*/
48const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
49 const TValue *tm = luaH_getstr(events, ename);
50 lua_assert(event <= TM_EQ);
51 if (ttisnil(tm)) { /* no tag method? */
52 events->flags |= cast_byte(1u<<event); /* cache this fact */
53 return NULL;
54 }
55 else return tm;
56}
57
58
59const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
60 Table *mt;
61 switch (ttype(o)) {
62 case LUA_TTABLE:
63 mt = hvalue(o)->metatable;
64 break;
65 case LUA_TUSERDATA:
66 mt = uvalue(o)->metatable;
67 break;
68 default:
69 mt = G(L)->mt[ttype(o)];
70 }
71 return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
72}
73