Exemple #1
0
///////////////
// toplevel and common
///////////////
static int image_luaautoc_member(lua_State *L)
{
  dt_lua_image_t imgid;
  luaA_to(L, dt_lua_image_t, &imgid, 1);
  const char *member_name = luaL_checkstring(L, 2);
  if(lua_gettop(L) != 3)
  {
    const dt_image_t *image = checkreadimage(L, 1);
    luaA_struct_push_member_name(L, dt_image_t, member_name, image);
    releasereadimage(L, image);
    return 1;
  }
  else
  {
    dt_image_t *image = checkwriteimage(L, 1);
    luaA_struct_to_member_name(L, dt_image_t, member_name, image, 3);
    releasewriteimage(L, image);
    return 0;
  }
}
Exemple #2
0
static int image_newindex(lua_State *L)
{
  const char* membername = lua_tostring(L, -2);
  dt_image_t * my_image=checkwriteimage(L,-3);
  if(luaA_struct_has_member_name(L,dt_image_t,membername))
  {
    if(luaA_type_has_to_func(luaA_struct_typeof_member_name(L,dt_image_t,membername)))
    {
      luaA_struct_to_member_name(L, dt_image_t, my_image, membername,-1);
    }
    else
    {
      releasewriteimage(L,my_image);
      luaL_error(L,"%s is read only",membername);
    }
    releasewriteimage(L,my_image);
    return 0;
  }
  switch(luaL_checkoption(L,-2,NULL,image_fields_name))
  {
    case RATING:
      {
        int my_score = luaL_checkinteger(L,-1);
        if(my_score > 5)
        {
          releasewriteimage(L,my_image);
          return luaL_error(L,"rating too high : %d",my_score);
        }
        if(my_score == -1) my_score = 6;
        if(my_score < -1)
        {
          releasewriteimage(L,my_image);
          return luaL_error(L,"rating too low : %d",my_score);
        }
        my_image->flags &= ~0x7;
        my_image->flags |= my_score;
        break;
      }

    case CREATOR:
      dt_metadata_set(my_image->id,"Xmp.dc.creator",luaL_checkstring(L,-1));
      dt_image_synch_xmp(my_image->id);
      break;
    case PUBLISHER:
      dt_metadata_set(my_image->id,"Xmp.dc.publisher",luaL_checkstring(L,-1));
      dt_image_synch_xmp(my_image->id);
      break;
    case TITLE:
      dt_metadata_set(my_image->id,"Xmp.dc.title",luaL_checkstring(L,-1));
      dt_image_synch_xmp(my_image->id);
      break;
    case DESCRIPTION:
      dt_metadata_set(my_image->id,"Xmp.dc.description",luaL_checkstring(L,-1));
      dt_image_synch_xmp(my_image->id);
      break;
    case RIGHTS:
      dt_metadata_set(my_image->id,"Xmp.dc.title",luaL_checkstring(L,-1));
      dt_image_synch_xmp(my_image->id);
      break;
    case LOCAL_COPY:
      {
        int imgid = my_image->id;
        luaL_checktype(L,-1,LUA_TBOOLEAN);
        // we need to release write image for the other functions to use it
        releasewriteimage(L,my_image);
        if(lua_toboolean(L,-1)) {
          dt_image_local_copy_set(imgid);
        } else {
          dt_image_local_copy_reset(imgid);
        }
        return 0;
      }
    default:
      releasewriteimage(L,my_image);
      return luaL_error(L,"unknown index for image : ",lua_tostring(L,-2));

  }
  releasewriteimage(L,my_image);
  return 0;
}