xref: /freebsd/contrib/lua/src/ltm.h (revision a9490b81b032b43cdb3c8c76b4d01bbad9ff82c1)
18e3e3a7aSWarner Losh /*
20495ed39SKyle Evans ** $Id: ltm.h $
38e3e3a7aSWarner Losh ** Tag methods
48e3e3a7aSWarner Losh ** See Copyright Notice in lua.h
58e3e3a7aSWarner Losh */
68e3e3a7aSWarner Losh 
78e3e3a7aSWarner Losh #ifndef ltm_h
88e3e3a7aSWarner Losh #define ltm_h
98e3e3a7aSWarner Losh 
108e3e3a7aSWarner Losh 
118e3e3a7aSWarner Losh #include "lobject.h"
12*a9490b81SWarner Losh #include "lstate.h"
138e3e3a7aSWarner Losh 
148e3e3a7aSWarner Losh 
158e3e3a7aSWarner Losh /*
168e3e3a7aSWarner Losh * WARNING: if you change the order of this enumeration,
178e3e3a7aSWarner Losh * grep "ORDER TM" and "ORDER OP"
188e3e3a7aSWarner Losh */
198e3e3a7aSWarner Losh typedef enum {
208e3e3a7aSWarner Losh   TM_INDEX,
218e3e3a7aSWarner Losh   TM_NEWINDEX,
228e3e3a7aSWarner Losh   TM_GC,
238e3e3a7aSWarner Losh   TM_MODE,
248e3e3a7aSWarner Losh   TM_LEN,
258e3e3a7aSWarner Losh   TM_EQ,  /* last tag method with fast access */
268e3e3a7aSWarner Losh   TM_ADD,
278e3e3a7aSWarner Losh   TM_SUB,
288e3e3a7aSWarner Losh   TM_MUL,
298e3e3a7aSWarner Losh   TM_MOD,
308e3e3a7aSWarner Losh   TM_POW,
318e3e3a7aSWarner Losh   TM_DIV,
328e3e3a7aSWarner Losh   TM_IDIV,
338e3e3a7aSWarner Losh   TM_BAND,
348e3e3a7aSWarner Losh   TM_BOR,
358e3e3a7aSWarner Losh   TM_BXOR,
368e3e3a7aSWarner Losh   TM_SHL,
378e3e3a7aSWarner Losh   TM_SHR,
388e3e3a7aSWarner Losh   TM_UNM,
398e3e3a7aSWarner Losh   TM_BNOT,
408e3e3a7aSWarner Losh   TM_LT,
418e3e3a7aSWarner Losh   TM_LE,
428e3e3a7aSWarner Losh   TM_CONCAT,
438e3e3a7aSWarner Losh   TM_CALL,
440495ed39SKyle Evans   TM_CLOSE,
458e3e3a7aSWarner Losh   TM_N		/* number of elements in the enum */
468e3e3a7aSWarner Losh } TMS;
478e3e3a7aSWarner Losh 
488e3e3a7aSWarner Losh 
490495ed39SKyle Evans /*
500495ed39SKyle Evans ** Mask with 1 in all fast-access methods. A 1 in any of these bits
510495ed39SKyle Evans ** in the flag of a (meta)table means the metatable does not have the
520495ed39SKyle Evans ** corresponding metamethod field. (Bit 7 of the flag is used for
530495ed39SKyle Evans ** 'isrealasize'.)
540495ed39SKyle Evans */
550495ed39SKyle Evans #define maskflags	(~(~0u << (TM_EQ + 1)))
560495ed39SKyle Evans 
570495ed39SKyle Evans 
580495ed39SKyle Evans /*
590495ed39SKyle Evans ** Test whether there is no tagmethod.
600495ed39SKyle Evans ** (Because tagmethods use raw accesses, the result may be an "empty" nil.)
610495ed39SKyle Evans */
620495ed39SKyle Evans #define notm(tm)	ttisnil(tm)
630495ed39SKyle Evans 
648e3e3a7aSWarner Losh 
658e3e3a7aSWarner Losh #define gfasttm(g,et,e) ((et) == NULL ? NULL : \
668e3e3a7aSWarner Losh   ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
678e3e3a7aSWarner Losh 
688e3e3a7aSWarner Losh #define fasttm(l,et,e)	gfasttm(G(l), et, e)
698e3e3a7aSWarner Losh 
708e3e3a7aSWarner Losh #define ttypename(x)	luaT_typenames_[(x) + 1]
718e3e3a7aSWarner Losh 
720495ed39SKyle Evans LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];)
738e3e3a7aSWarner Losh 
748e3e3a7aSWarner Losh 
758e3e3a7aSWarner Losh LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);
768e3e3a7aSWarner Losh 
778e3e3a7aSWarner Losh LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
788e3e3a7aSWarner Losh LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
798e3e3a7aSWarner Losh                                                        TMS event);
808e3e3a7aSWarner Losh LUAI_FUNC void luaT_init (lua_State *L);
818e3e3a7aSWarner Losh 
828e3e3a7aSWarner Losh LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
830495ed39SKyle Evans                             const TValue *p2, const TValue *p3);
840495ed39SKyle Evans LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f,
850495ed39SKyle Evans                             const TValue *p1, const TValue *p2, StkId p3);
868e3e3a7aSWarner Losh LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
878e3e3a7aSWarner Losh                               StkId res, TMS event);
880495ed39SKyle Evans LUAI_FUNC void luaT_tryconcatTM (lua_State *L);
890495ed39SKyle Evans LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1,
900495ed39SKyle Evans        const TValue *p2, int inv, StkId res, TMS event);
910495ed39SKyle Evans LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,
920495ed39SKyle Evans                                int inv, StkId res, TMS event);
938e3e3a7aSWarner Losh LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,
948e3e3a7aSWarner Losh                                 const TValue *p2, TMS event);
950495ed39SKyle Evans LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
960495ed39SKyle Evans                                  int inv, int isfloat, TMS event);
978e3e3a7aSWarner Losh 
980495ed39SKyle Evans LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams,
99*a9490b81SWarner Losh                                    CallInfo *ci, const Proto *p);
100*a9490b81SWarner Losh LUAI_FUNC void luaT_getvarargs (lua_State *L, CallInfo *ci,
1010495ed39SKyle Evans                                               StkId where, int wanted);
1028e3e3a7aSWarner Losh 
1038e3e3a7aSWarner Losh 
1048e3e3a7aSWarner Losh #endif
105