1
2 /*
3 This file is part of darktable,
4 Copyright (C) 2013-2020 darktable developers.
5
6 darktable is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 darktable is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with darktable. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "common/darktable.h"
20 #include "control/control.h"
21 #include "lua/lua.h"
22
lua_print(lua_State * L)23 static int lua_print(lua_State *L)
24 {
25 const int init_gui = (darktable.gui != NULL);
26 if(init_gui)
27 dt_control_log("%s", luaL_checkstring(L, -1));
28 else
29 printf("%s\n", luaL_checkstring(L, -1));
30
31 return 0;
32 }
33
lua_print_toast(lua_State * L)34 static int lua_print_toast(lua_State *L)
35 {
36
37 const int init_gui = (darktable.gui != NULL);
38 if(init_gui)
39 dt_toast_log("%s", luaL_checkstring(L, -1));
40 else
41 printf("%s\n", luaL_checkstring(L, -1));
42
43 return 0;
44 }
45
lua_print_hinter(lua_State * L)46 static int lua_print_hinter(lua_State *L)
47 {
48
49 const int init_gui = (darktable.gui != NULL);
50 if(init_gui)
51 {
52
53 char msg[256];
54 if(snprintf(msg, sizeof(msg), "%s", luaL_checkstring(L, -1)) > 0)
55 {
56 dt_control_hinter_message(darktable.control, msg);
57 }
58 }
59 else
60 printf("%s\n", luaL_checkstring(L, -1));
61
62 return 0;
63 }
64
65
lua_print_log(lua_State * L)66 static int lua_print_log(lua_State *L)
67 {
68 dt_print(DT_DEBUG_LUA, "LUA %s\n", luaL_checkstring(L, -1));
69 return 0;
70 }
71
lua_print_error(lua_State * L)72 static int lua_print_error(lua_State *L)
73 {
74 dt_print(DT_DEBUG_LUA, "LUA ERROR %s\n", luaL_checkstring(L, -1));
75 return 0;
76 }
77
dt_lua_init_print(lua_State * L)78 int dt_lua_init_print(lua_State *L)
79 {
80 dt_lua_push_darktable_lib(L);
81
82 lua_pushstring(L, "print");
83 lua_pushcfunction(L, &lua_print);
84 lua_settable(L, -3);
85
86 lua_pushstring(L, "print_toast");
87 lua_pushcfunction(L, &lua_print_toast);
88 lua_settable(L, -3);
89
90 lua_pushstring(L, "print_hinter");
91 lua_pushcfunction(L, &lua_print_hinter);
92 lua_settable(L, -3);
93
94 lua_pushstring(L, "print_log");
95 lua_pushcfunction(L, &lua_print_log);
96 lua_settable(L, -3);
97
98 lua_pushstring(L, "print_error");
99 lua_pushcfunction(L, &lua_print_error);
100 lua_settable(L, -3);
101
102 lua_pop(L, 1); // remove the configuration table from the stack
103 return 0;
104 }
105
106
107
108 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
109 // vim: shiftwidth=2 expandtab tabstop=2 cindent
110 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
111