static int TreeGetUserId(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); int id = (int)luaL_checkinteger(L,2); tree_push_userid(L, IupTreeGetUserId(ih, id)); return 1; }
static void cfTreeSetTableId(void) { Ihandle* ih = iuplua_checkihandle(1); int id = luaL_check_int(2); lua_Object o3 = lua_getparam(3); if(lua_isnil(o3)) { int ref; /* Setting in the id table the reference as nil */ o3 = tree_gettable(ih, id); if(o3 != LUA_NOOBJECT) tree_setnumberintable(o3, 0); ref = (int)IupTreeGetUserId(ih, id); lua_unref(ref); lua_pushnumber(IupTreeSetUserId(ih, id, NULL)); } else { int ref; lua_pushobject(o3); ref = lua_ref(1); lua_pushnumber(IupTreeSetUserId(ih, id, (void*)(ref+1))); tree_setnumberintable(o3, ref+1); } }
static int TreeSetUserId(lua_State *L) { Ihandle *ih = iuplua_checkihandle(L,1); int id = (int)luaL_checkinteger(L, 2); int ref = (int)IupTreeGetUserId(ih, id); if (ref != 0) /* userid is not NULL */ { if (ref > 0) ref--; /* only positive references are shifted */ /* release the previous object referenced there */ lua_rawgeti(L, LUA_REGISTRYINDEX, ref); tree_settableref(L, 4, LUA_NOREF); luaL_unref(L, LUA_REGISTRYINDEX, ref); lua_pop(L, 1); } if (lua_isnil(L, 3)) IupTreeSetUserId(ih, id, NULL); else { /* add a new reference */ lua_pushvalue(L, 3); ref = luaL_ref(L, LUA_REGISTRYINDEX); tree_settableref(L, 3, ref); if (ref >= 0) ref++; /* only positive references are shifted */ IupTreeSetUserId(ih, id, (void*)ref); } return 0; }
VALUE rb_IupTreeGetUserId(VALUE node,VALUE v_id) { int id = NUM2INT(v_id); void* v; VALUE v_ih = rb_iv_get(node,"@ihandle"); v = IupTreeGetUserId((Ihandle*)NUM2ULONG(v_ih),id); return ULONG2NUM((unsigned long)v); }
static lua_Object tree_gettable(Ihandle* ih, int id) { int ref = (int)IupTreeGetUserId(ih, id); if(ref == 0) return LUA_NOOBJECT; else return lua_getref(ref-1); }
static int TreeGetUserId(lua_State *L) { int ref; Ihandle *h = iuplua_checkihandle(L,1); int id = (int)luaL_checknumber(L,2); ref = (int) IupTreeGetUserId(h, id); lua_getref(L, ref-1); return 1; }
static int TreeSetUserId(lua_State *L) { Ihandle *h = iuplua_checkihandle(L,1); int id = (int)luaL_checknumber(L,2); if(lua_isnil(L, 3)) { int ref = (int) IupTreeGetUserId(h, id); lua_getref(L, ref-1); settableref(L, 4, 0); lua_unref(L, ref-1); IupTreeSetUserId(h, id, NULL); lua_pop(L, 1); } else { int ref; lua_pushvalue(L, 3); ref = lua_ref(L, 1); IupTreeSetUserId(h, id, (char*) ref+1); settableref(L, 3, ref+1); } return 0; }
static void cfTreeGetUserId(void) { lua_pushusertag(IupTreeGetUserId(iuplua_checkihandle(1), luaL_check_int(2)), LUA_ANYTAG); }