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-2020 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/* this file can safely be included when lua is disabled */
22
23
24/* these include are out of the ifdef to avoid compile errors when compiling with/without lua
25 users that accidentally use it won't be affected by the ifdef USE_LUA
26 */
27#include "common/dtpthread.h"
28#include <glib.h>
29
30#ifdef USE_LUA
31#include <lautoc.h>
32#include <lauxlib.h>
33#include <lua.h>
34#include <lualib.h>
35
41
49void dt_lua_goto_subtable(lua_State *L, const char *sub_name);
50
51
52void dt_lua_init_lock();
53void dt_lua_lock_internal(const char *function, const char *file, int line, gboolean silent);
54void dt_lua_unlock_internal(const char *function, int line);
55
56#define dt_lua_debug_stack(L) dt_lua_debug_stack_internal(L, __FUNCTION__, __LINE__)
57void dt_lua_debug_stack_internal(lua_State *L, const char *function, int line);
58#define dt_lua_debug_table(L, index) dt_lua_debug_table_internal(L, index, __FUNCTION__, __LINE__)
59void dt_lua_debug_table_internal(lua_State *L, int t, const char *function, int line);
60
61
62#define dt_lua_lock() dt_lua_lock_internal(__FUNCTION__, __FILE__, __LINE__, FALSE)
63#define dt_lua_lock_silent() dt_lua_lock_internal(__FUNCTION__, __FILE__, __LINE__, TRUE)
64#define dt_lua_unlock() dt_lua_unlock_internal( __FUNCTION__, __LINE__)
65
66typedef struct
67{
68 lua_State *state; // main lua context
69
70 dt_pthread_mutex_t mutex; // mutex protecting the lua condition variable
71 pthread_cond_t cond; // condition variable to wait for the lua lock
72 bool exec_lock; // true if some lua code is running. this is logically a mutex
73
74 bool ending; // true if we are in the process of terminating DT
75
76 GMainLoop *loop; // loop running the lua context
77 GMainContext *context; // the lua context responsible for dispatching tasks
78 GThreadPool *pool; // pool of threads to run lua tasks on (should be one or two at most, unless lot of blocking lua threads
79 GAsyncQueue * stacked_job_queue; // queue of jobs whose arguments are on a lua stack
80 GAsyncQueue * alien_job_queue; // queue of jobs coming from C, args are passed in a glist
81 GAsyncQueue * string_job_queue; // queue of jobs as lua expressions, passed with args as a string
82
84
85
87
88#else
89/* defines to easily have a few lua types when lua is not available */
90typedef int lua_State;
91typedef int (*lua_CFunction)(lua_State *L);
92typedef int luaA_Type;
93#define LUAA_INVALID_TYPE -1
94typedef struct
95{
96 int unused; // if this is empty clang++ complains that the struct has size 0 in C and size 1 in C++
98#endif
99
100// clang-format off
101// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
102// vim: shiftwidth=2 expandtab tabstop=2 cindent
103// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
104// clang-format on
105
static int mutex
Definition dtpthread.h:315
void dt_lua_goto_subtable(lua_State *L, const char *sub_name)
Definition lua.c:91
void dt_lua_init_lock()
Definition lua.c:119
void dt_lua_lock_internal(const char *function, const char *file, int line, gboolean silent)
Definition lua.c:133
void dt_lua_debug_stack_internal(lua_State *L, const char *function, int line)
Definition lua.c:23
void dt_lua_redraw_screen()
Definition lua.c:171
int dt_lua_push_darktable_lib(lua_State *L)
Definition lua.c:75
void dt_lua_unlock_internal(const char *function, int line)
Definition lua.c:154
void dt_lua_debug_table_internal(lua_State *L, int t, const char *function, int line)
Definition lua.c:47
int luaA_Type
Definition lua.h:92
int(* lua_CFunction)(lua_State *L)
Definition lua.h:91
int lua_State
Definition lua.h:90
Definition lua.h:95
int unused
Definition lua.h:96