Example #1
0
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;
}
Example #2
0
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);
  }
} 
Example #3
0
VALUE rb_IupTreeSetUserId(VALUE node,VALUE v_id,VALUE v_userid)
{
    int id = NUM2INT(v_id);
    void *userid = (void*)NUM2ULONG(v_userid);
    int v;
    VALUE v_ih = rb_iv_get(node,"@ihandle");
    v = IupTreeSetUserId((Ihandle*)NUM2ULONG(v_ih),id,userid);
    return INT2FIX((int)v);
}
Example #4
0
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;
}
Example #5
0
static void cfTreeSetUserId(void)
{
  lua_pushnumber(IupTreeSetUserId(iuplua_checkihandle(1), luaL_check_int(2), check_userdata(3)));
}