示例#1
0
/*
** The next function tells whether a key or value can be cleared from
** a weak table. Non-collectable objects are never removed from weak
** tables. Strings behave as `values', so are never removed too. for
** other objects: if really collected, cannot keep them; for userdata
** being finalized, keep them in keys, but not in values
*/
static int iscleared (const TValue *o, int iskey) {
  if (!iscollectable(o)) return 0;
  if (ttisstring(o)) {
    stringmark(rawtsvalue(o));  /* strings are `values', so are never weak */
    return 0;
  }
  return iswhite(gcvalue(o)) ||
    (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));
}
示例#2
0
文件: lapi.c 项目: Ilgrim/MAMEHub
LUA_API void lua_getuservalue (lua_State *L, int idx) {
	StkId o;
	lua_lock(L);
	o = index2addr(L, idx);
	api_check(L, ttisuserdata(o), "userdata expected");
	if (uvalue(o)->env) {
	sethvalue(L, L->top, uvalue(o)->env);
	} else
	setnilvalue(L->top);
	api_incr_top(L);
	lua_unlock(L);
}
示例#3
0
文件: lapi.c 项目: Ilgrim/MAMEHub
LUA_API void lua_setuservalue (lua_State *L, int idx) {
	StkId o;
	lua_lock(L);
	api_checknelems(L, 1);
	o = index2addr(L, idx);
	api_check(L, ttisuserdata(o), "userdata expected");
	if (ttisnil(L->top - 1))
	uvalue(o)->env = NULL;
	else {
	api_check(L, ttistable(L->top - 1), "table expected");
	uvalue(o)->env = hvalue(L->top - 1);
	luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
	}
	L->top--;
	lua_unlock(L);
}
示例#4
0
文件: lapi.c 项目: AdunSG/Pktgen-DPDK
LUA_API int lua_isuserdata (lua_State *L, int idx) {
  const TValue *o = index2addr(L, idx);
  return (ttisuserdata(o) || ttislightuserdata(o));
}
示例#5
0
文件: lapi.c 项目: TheWaWaR/my-lua5.0
LUA_API int lua_isuserdata (lua_State *L, int idx) {
  const TObject *o = luaA_indexAcceptable(L, idx);
  return (o != NULL && (ttisuserdata(o) || ttislightuserdata(o)));
}