Example #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))));
}
Example #2
0
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);
}
Example #3
0
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);
}
Example #4
0
LUA_API int lua_isuserdata (lua_State *L, int idx) {
  const TValue *o = index2addr(L, idx);
  return (ttisuserdata(o) || ttislightuserdata(o));
}
Example #5
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)));
}