Skip to content

Commit 826e29e

Browse files
authored
Add inter script communication to Lua API (#17300)
* src/CMakeLists.txt - added lua/util.c module src/lua/configuration.h - bumped API to 9.4.0 src/lua/init.c - added util module src/lua/util.c - added inter-script-communication event. src/lua/util.h Added darktable.util.message() function to the API for sending messages between scripts * lua/util - fixed copyright
1 parent e5cafa1 commit 826e29e

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ if(USE_LUA)
747747
"lua/styles.c"
748748
"lua/tags.c"
749749
"lua/types.c"
750+
"lua/util.c"
750751
"lua/view.c"
751752
"lua/widget/box.c"
752753
"lua/widget/button.c"

src/lua/configuration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
// 4.4.0 was 9.1.0 (added mimic and dt_lua_image_t changes)
4141
// 4.6.0 was 9.2.0 (added change_timestamp to dt_image_t)
4242
// 4.8.0 was 9.3.0 (added button and box widget enhancements)
43+
// 5.0.0 was 9.4.0 (added group events and uuid)
4344
/* incompatible API change */
4445
#define LUA_API_VERSION_MAJOR 9
4546
/* backward compatible API change */
46-
#define LUA_API_VERSION_MINOR 3
47+
#define LUA_API_VERSION_MINOR 4
4748
/* bugfixes that should not change anything to the API */
4849
#define LUA_API_VERSION_PATCH 0
4950
/* suffix for unstable version */

src/lua/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "lua/styles.h"
4444
#include "lua/tags.h"
4545
#include "lua/types.h"
46+
#include "lua/util.h"
4647
#include "lua/view.h"
4748
#include "lua/widget/widget.h"
4849

@@ -138,7 +139,7 @@ static lua_CFunction init_funcs[]
138139
dt_lua_init_luastorages, dt_lua_init_tags, dt_lua_init_film, dt_lua_init_call,
139140
dt_lua_init_view, dt_lua_init_events, dt_lua_init_init, dt_lua_init_widget,
140141
dt_lua_init_lualib, dt_lua_init_gettext, dt_lua_init_guides, dt_lua_init_cairo,
141-
dt_lua_init_password, NULL };
142+
dt_lua_init_password, dt_lua_init_util, NULL };
142143

143144

144145
void dt_lua_init(lua_State *L, const char *lua_command)

src/lua/util.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
This file is part of darktable,
3+
Copyright (C) 2024 darktable developers.
4+
5+
darktable is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
darktable is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with darktable. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
#include "lua/preferences.h"
19+
#include "lua/call.h"
20+
#include "lua/events.h"
21+
#include <glib.h>
22+
#include <stdlib.h>
23+
#include <string.h>
24+
25+
static int message(lua_State *L)
26+
{
27+
const char *sender = luaL_checkstring(L, 1);
28+
const char *receiver = luaL_checkstring(L, 2);
29+
const char *message = luaL_checkstring(L, 3);
30+
31+
dt_lua_async_call_alien(dt_lua_event_trigger_wrapper,
32+
0, NULL, NULL,
33+
LUA_ASYNC_TYPENAME, "const char*", "inter-script-communication",
34+
LUA_ASYNC_TYPENAME, "const char*", sender,
35+
LUA_ASYNC_TYPENAME, "const char*", receiver,
36+
LUA_ASYNC_TYPENAME, "const char*", message,
37+
LUA_ASYNC_DONE);
38+
39+
return 0;
40+
}
41+
42+
43+
int dt_lua_init_util(lua_State *L)
44+
{
45+
dt_lua_push_darktable_lib(L);
46+
dt_lua_goto_subtable(L, "util");
47+
48+
lua_pushcfunction(L, message);
49+
lua_setfield(L, -2, "message");
50+
51+
lua_pop(L, 1);
52+
53+
54+
lua_pushcfunction(L, dt_lua_event_multiinstance_register);
55+
lua_pushcfunction(L, dt_lua_event_multiinstance_destroy);
56+
lua_pushcfunction(L, dt_lua_event_multiinstance_trigger);
57+
dt_lua_event_add(L, "inter-script-communication");
58+
59+
return 0;
60+
}
61+
// clang-format off
62+
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
63+
// vim: shiftwidth=2 expandtab tabstop=2 cindent
64+
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
65+
// clang-format on
66+

src/lua/util.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
This file is part of darktable,
3+
Copyright (C) 2024 darktable developers.
4+
5+
darktable is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
darktable is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with darktable. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
int dt_lua_init_util(lua_State *L);
22+
23+
// clang-format off
24+
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
25+
// vim: shiftwidth=2 expandtab tabstop=2 cindent
26+
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
27+
// clang-format on
28+

0 commit comments

Comments
 (0)