The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/openzfs/module/lua/ltm.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 2891206c39f531ecb4885f95d19a87f6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.