forked from darktable-org/darktable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.c
176 lines (148 loc) · 5.01 KB
/
configuration.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
This file is part of darktable,
copyright (c) 2012 Jeremy Rosen
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
darktable is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with darktable. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "common/darktable.h"
#include "common/file_location.h"
#include "lua/configuration.h"
#include "lua/lua.h"
static int check_version(lua_State *L)
{
const char *module_name = "<unnamed module>";
if(!lua_isnil(L,1)) module_name = luaL_checkstring(L, 1);
gboolean valid = false;
for(int i = 2; i <= lua_gettop(L); i++)
{
lua_pushinteger(L, 1);
lua_gettable(L, i);
int major = luaL_checkinteger(L, -1);
lua_pop(L, 1);
lua_pushinteger(L, 2);
lua_gettable(L, i);
int minor = luaL_checkinteger(L, -1);
lua_pop(L, 1);
/*
patch number is not needed to check for compatibility
but let's take the good habits
lua_pushinteger(L,3);
lua_gettable(L,i);
int patch= luaL_checkinteger(L,-1);
lua_pop(L,1);
*/
if(major == LUA_API_VERSION_MAJOR && minor <= LUA_API_VERSION_MINOR)
{
valid = true;
}
}
if(valid)
{
// nothing
}
else if(strlen(LUA_API_VERSION_SUFFIX) == 0)
{
luaL_error(L, "Module %s is not compatible with API %d.%d.%d", module_name, LUA_API_VERSION_MAJOR,
LUA_API_VERSION_MINOR, LUA_API_VERSION_PATCH);
}
else
{
dt_print(DT_DEBUG_LUA, "LUA ERROR Module %s is not compatible with API %d.%d.%d-%s\n", module_name,
LUA_API_VERSION_MAJOR, LUA_API_VERSION_MINOR, LUA_API_VERSION_PATCH, LUA_API_VERSION_SUFFIX);
}
return 0;
}
typedef enum
{
os_windows,
os_macos,
os_linux,
os_unix
} lua_os_type;
#if defined(_WIN32)
static const lua_os_type cur_os = os_windows;
#elif defined(__MACH__) || defined(__APPLE__)
static const lua_os_type cur_os = os_macos;
#elif defined(__linux__)
static const lua_os_type cur_os = os_linux;
#else
static const lua_os_type cur_os = os_unix;
#endif
int dt_lua_init_configuration(lua_State *L)
{
char tmp_path[PATH_MAX] = { 0 };
dt_lua_push_darktable_lib(L);
dt_lua_goto_subtable(L, "configuration");
// build the table containing the configuration info
lua_pushstring(L, "tmp_dir");
dt_loc_get_tmp_dir(tmp_path, sizeof(tmp_path));
lua_pushstring(L, tmp_path);
lua_settable(L, -3);
lua_pushstring(L, "config_dir");
dt_loc_get_user_config_dir(tmp_path, sizeof(tmp_path));
lua_pushstring(L, tmp_path);
lua_settable(L, -3);
lua_pushstring(L, "cache_dir");
dt_loc_get_user_cache_dir(tmp_path, sizeof(tmp_path));
lua_pushstring(L, tmp_path);
lua_settable(L, -3);
lua_pushstring(L, "version");
lua_pushstring(L, darktable_package_version);
lua_settable(L, -3);
lua_pushstring(L, "verbose");
lua_pushboolean(L, darktable.unmuted & DT_DEBUG_LUA);
lua_settable(L, -3);
lua_pushstring(L, "has_gui");
lua_pushboolean(L, darktable.gui != NULL);
lua_settable(L, -3);
lua_pushstring(L, "api_version_major");
lua_pushinteger(L, LUA_API_VERSION_MAJOR);
lua_settable(L, -3);
lua_pushstring(L, "api_version_minor");
lua_pushinteger(L, LUA_API_VERSION_MINOR);
lua_settable(L, -3);
lua_pushstring(L, "api_version_patch");
lua_pushinteger(L, LUA_API_VERSION_PATCH);
lua_settable(L, -3);
lua_pushstring(L, "api_version_suffix");
lua_pushstring(L, LUA_API_VERSION_SUFFIX);
lua_settable(L, -3);
lua_pushstring(L, "api_version_string");
if(LUA_API_VERSION_SUFFIX[0] == '\0')
{
lua_pushfstring(L, "%d.%d.%d", LUA_API_VERSION_MAJOR, LUA_API_VERSION_MINOR, LUA_API_VERSION_PATCH);
}
else
{
lua_pushfstring(L, "%d.%d.%d-%s", LUA_API_VERSION_MAJOR, LUA_API_VERSION_MINOR, LUA_API_VERSION_PATCH,
LUA_API_VERSION_SUFFIX);
}
lua_settable(L, -3);
lua_pushstring(L, "check_version");
lua_pushcfunction(L, check_version);
lua_settable(L, -3);
luaA_enum(L, lua_os_type);
luaA_enum_value_name(L, lua_os_type, os_windows, "windows");
luaA_enum_value_name(L, lua_os_type, os_macos, "macos");
luaA_enum_value_name(L, lua_os_type, os_linux, "linux");
luaA_enum_value_name(L, lua_os_type, os_unix, "unix");
lua_pushstring(L, "running_os");
luaA_push(L, lua_os_type, &cur_os);
lua_settable(L, -3);
lua_pop(L, 1); // remove the configuration table from the stack
return 0;
}
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;