d99a015343
Authored by: Chris Williamson <chris.williamson@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: John Kennedy <john.kennedy@delphix.com> Reviewed by: Dan Kimmel <dan.kimmel@delphix.com> Approved by: Garrett D'Amore <garrett@damore.org> Ported-by: Don Brady <don.brady@delphix.com> Ported-by: John Kennedy <john.kennedy@delphix.com> OpenZFS-issue: https://www.illumos.org/issues/7431 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/dfc11533 Porting Notes: * The CLI long option arguments for '-t' and '-m' don't parse on linux * Switched from kmem_alloc to vmem_alloc in zcp_lua_alloc * Lua implementation is built as its own module (zlua.ko) * Lua headers consumed directly by zfs code moved to 'include/sys/lua/' * There is no native setjmp/longjump available in stock Linux kernel. Brought over implementations from illumos and FreeBSD * The get_temporary_prop() was adapted due to VFS platform differences * Use of inline functions in lua parser to reduce stack usage per C call * Skip some ZFS Test Suite ZCP tests on sparc64 to avoid stack overflow
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
/* BEGIN CSTYLED */
|
|
/*
|
|
** $Id: ltm.c,v 2.14.1.1 2013/04/12 18:48:47 roberto Exp $
|
|
** Tag methods
|
|
** See Copyright Notice in lua.h
|
|
*/
|
|
|
|
|
|
#define ltm_c
|
|
#define LUA_CORE
|
|
|
|
#include <sys/lua/lua.h>
|
|
|
|
#include "lobject.h"
|
|
#include "lstate.h"
|
|
#include "lstring.h"
|
|
#include "ltable.h"
|
|
#include "ltm.h"
|
|
|
|
|
|
static const char udatatypename[] = "userdata";
|
|
|
|
LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
|
|
"no value",
|
|
"nil", "boolean", udatatypename, "number",
|
|
"string", "table", "function", udatatypename, "thread",
|
|
"proto", "upval" /* these last two cases are used for tests only */
|
|
};
|
|
|
|
|
|
void luaT_init (lua_State *L) {
|
|
static const char *const luaT_eventname[] = { /* ORDER TM */
|
|
"__index", "__newindex",
|
|
"__gc", "__mode", "__len", "__eq",
|
|
"__add", "__sub", "__mul", "__div", "__mod",
|
|
"__pow", "__unm", "__lt", "__le",
|
|
"__concat", "__call"
|
|
};
|
|
int i;
|
|
for (i=0; i<TM_N; i++) {
|
|
G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
|
|
luaS_fix(G(L)->tmname[i]); /* never collect these names */
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
** function to be used with macro "fasttm": optimized for absence of
|
|
** tag methods
|
|
*/
|
|
const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
|
|
const TValue *tm = luaH_getstr(events, ename);
|
|
lua_assert(event <= TM_EQ);
|
|
if (ttisnil(tm)) { /* no tag method? */
|
|
events->flags |= cast_byte(1u<<event); /* cache this fact */
|
|
return NULL;
|
|
}
|
|
else return tm;
|
|
}
|
|
|
|
|
|
const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
|
|
Table *mt;
|
|
switch (ttypenv(o)) {
|
|
case LUA_TTABLE:
|
|
mt = hvalue(o)->metatable;
|
|
break;
|
|
case LUA_TUSERDATA:
|
|
mt = uvalue(o)->metatable;
|
|
break;
|
|
default:
|
|
mt = G(L)->mt[ttypenv(o)];
|
|
}
|
|
return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
|
|
}
|
|
/* END CSTYLED */
|