Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
lua.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2013-2016 Jérémy Rosen.
4 Copyright (C) 2013-2016 Tobias Ellinghaus.
5 Copyright (C) 2016 Roman Lebedev.
6 Copyright (C) 2017 luzpaz.
7 Copyright (C) 2020 Pascal Obry.
8 Copyright (C) 2022 Martin Bařinka.
9
10 darktable is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 darktable is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with darktable. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26/* this file can safely be included when lua is disabled */
27
28
29/* these include are out of the ifdef to avoid compile errors when compiling with/without lua
30 users that accidentally use it won't be affected by the ifdef USE_LUA
31 */
32#include "common/dtpthread.h"
33#include <glib.h>
34
35#ifdef USE_LUA
36#include <lautoc.h>
37#include <lauxlib.h>
38#include <lua.h>
39#include <lualib.h>
40
46
54void dt_lua_goto_subtable(lua_State *L, const char *sub_name);
55
56
57void dt_lua_init_lock();
58void dt_lua_lock_internal(const char *function, const char *file, int line, gboolean silent);
59void dt_lua_unlock_internal(const char *function, int line);
60
61#define dt_lua_debug_stack(L) dt_lua_debug_stack_internal(L, __FUNCTION__, __LINE__)
62void dt_lua_debug_stack_internal(lua_State *L, const char *function, int line);
63#define dt_lua_debug_table(L, index) dt_lua_debug_table_internal(L, index, __FUNCTION__, __LINE__)
64void dt_lua_debug_table_internal(lua_State *L, int t, const char *function, int line);
65
66
67#define dt_lua_lock() dt_lua_lock_internal(__FUNCTION__, __FILE__, __LINE__, FALSE)
68#define dt_lua_lock_silent() dt_lua_lock_internal(__FUNCTION__, __FILE__, __LINE__, TRUE)
69#define dt_lua_unlock() dt_lua_unlock_internal( __FUNCTION__, __LINE__)
70
71typedef struct
72{
73 lua_State *state; // main lua context
74
75 dt_pthread_mutex_t mutex; // mutex protecting the lua condition variable
76 pthread_cond_t cond; // condition variable to wait for the lua lock
77 bool exec_lock; // true if some lua code is running. this is logically a mutex
78
79 bool ending; // true if we are in the process of terminating DT
80
81 GMainLoop *loop; // loop running the lua context
82 GMainContext *context; // the lua context responsible for dispatching tasks
83 GThreadPool *pool; // pool of threads to run lua tasks on (should be one or two at most, unless lot of blocking lua threads
84 GAsyncQueue * stacked_job_queue; // queue of jobs whose arguments are on a lua stack
85 GAsyncQueue * alien_job_queue; // queue of jobs coming from C, args are passed in a glist
86 GAsyncQueue * string_job_queue; // queue of jobs as lua expressions, passed with args as a string
87
89
90
92
93#else
94/* defines to easily have a few lua types when lua is not available */
95typedef int lua_State;
96typedef int (*lua_CFunction)(lua_State *L);
97typedef int luaA_Type;
98#define LUAA_INVALID_TYPE -1
99typedef struct
100{
101 int unused; // if this is empty clang++ complains that the struct has size 0 in C and size 1 in C++
103#endif
104
105// clang-format off
106// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
107// vim: shiftwidth=2 expandtab tabstop=2 cindent
108// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
109// clang-format on
110
const float L
Definition colorspaces_inline_conversions.h:724
static int mutex
Definition dtpthread.h:370
const int t
Definition iop_profile.h:227
void dt_lua_goto_subtable(lua_State *L, const char *sub_name)
Definition lua.c:96
void dt_lua_init_lock()
Definition lua.c:124
void dt_lua_lock_internal(const char *function, const char *file, int line, gboolean silent)
Definition lua.c:138
void dt_lua_debug_stack_internal(lua_State *L, const char *function, int line)
Definition lua.c:28
void dt_lua_redraw_screen()
Definition lua.c:176
int dt_lua_push_darktable_lib(lua_State *L)
Definition lua.c:80
void dt_lua_unlock_internal(const char *function, int line)
Definition lua.c:159
void dt_lua_debug_table_internal(lua_State *L, int t, const char *function, int line)
Definition lua.c:52
int luaA_Type
Definition lua.h:97
int(* lua_CFunction)(lua_State *L)
Definition lua.h:96
int lua_State
Definition lua.h:95
Definition lua.h:100
int unused
Definition lua.h:101