Copy / Modify dt_lua_image_t image objects

I’d like to add some fields to images object of dt_lua_image_t type, but it seems impossible, doesn’t it?
So, I tried to create a new image table adding fields one by one, but if I copy all fields in a cycle then it seems to become the same dt_lua_image_t image object and I can’t modify more.

How can duplicate images table (I no need method fields, just string fields are enough) adding then new fields?

Thank you.

You would have to modify the underlying darktable C code and database. Once that’s done then you can extend the dt_lua_image_t, again in the C code.

Ok…so no way by lua, is it?

But… how to recognize if a field of a table is a string, a number, or function?

If I copy some fields of my interest I do not have problems: is there a field which identify the kind of object dt_lua_image_t? If so, how to recognize it and don’t to copy it?


Thanks, but I know that page and the dt_lua_image_t structure.
My question is how to copy just string and number fields automatically: is there a command to recognize the variable type?


Perhaps if you tell me what you’re trying to do I can give you better answers. I’m answering the questions you are asking, but that doesn’t seem to be the answer you’re looking for.

As above, I need to copy a dt_lua_image_t image in a new object, a different table having just all their string and numeric fields (e.i .filename, .rating, .id, etc…)
That’s why I can’t modify a dt_lua_image_t object adding new fields that I need, I have error!

I found function type() to check field types but I can’t understand how cycling correctly now…

I meant more high level like “I want to write a program that will do …”.

I understand what you’re asking, but I don’t understand the purpose. The only way to do what you are asking is to start up a database program and run a separate database with the data you copy, but I’m not sure doing it in Lua is a realistic idea.

If I understood the “big picture” then I might be able to suggest another way to do what you want

My programm exports in a customized album the images after several elaboration.
Now I manage my pictures by two table: images (the native dt_lua_image_t objects) and my album.images table with other fields: I’d like to have just one table to use in my function callings.
Solutions can be two:

  1. now I have copied one by one single field of my interest (e.i. filename, rating, etc) and works but, adding new features to my program I need to copy even more fields in my album.images table,
  2. so I’d like to copy just in a cycle (?!? I am not able…,) all fields (less methods, so ‘string’, ‘number’, ‘boolean’…). The question is I don’t know how, but I copy even the dt_lua_image_t mark and then I cannot add new fields in my table album.images as before by single copies.

I hope I’ve been more clear, now.


dt_lua_image_t is a subset of the information in the image table. All of the fields in dt_lua_image_t are described in the documentation link I posted above. If you want more fields that contain information about the image then you need to run the exiv2 command against the image, parse the output to get the information you want, then store it in your album.images table.

That’s is what I did:

  1. if I copy manually single fields, I don’t have problem;
  2. if I do “for _,field in ipairs(images) do”, I receive “bad argument #1 to ‘for iterator’ (table expected, got dt_lua_image_t)”: I don’t know how to parse automatically the image to extract fields of my interest (numeric / string) —>>that’s the question!

images is a table of images, not a table of fields so you need to do

for _, img in ipairs(images) do
  <your variable> = img.filename
  <another variable> = img.path

and so on

There are a lot of scripts in the darktable lua-scripts repository that show how to use tables of images.

Sorry… I meant “for _,field in ipairs(image) do”, a cycle on single image, in order to copy all fields of single image.

Your cycle copy manually single specified fields of every image, in other words my first case as above iterated (and I don’t have problem for it): I do not want write each single field (.filename, .rating, etc…), I do want automatically create a new copy of an image whit their fields (whit or whitout methods) and then add new fields on it (but if system recognizes it as dt_lua_image_t, it can’t permit to change structure adding a news field.)

Anyway… at this point the question is for me a case study having already “solved” writing by hand all fields of my interest.

However, I thank you.

1 Like

But such a for loop works on tables, i.e. (key,value) pairs, with a given type for the keys, and a given type for the values. Those key and value types are the same for all items in the table.

dt_lua_image_t is an class, which is a sequences of fields of different types (with associated methods). The names of those fields you see in source code do not exist in the final program.

That means you cannot use a for loop to work on the fields of a class object. It also means you cannot add fields to an object at run time (it would break any other code that uses such a class in “interesting” ways).

But why not create your own object in your source, and add a method to it to read the relevant fields into it from the dt_lua_image_t you pass to it. Using a method to do the translation means you keep all relevant information together in case you ever have to change the fields in your class

so… no way to duplicate an image to a modifiable one…ok… my desire was just to have a lean code.
Anyway, now I’m already run my own object, created adding one by one the relevant fields into it from the dt_lua_image_t…
If there is no betetr way… ok…
topic closed :-/