Freeciv21
Develop your civilization from humble roots to a global empire
luascript_signal.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9 **************************************************************************/
10 #pragma once
11 // utility
12 #include "support.h"
13 
14 #include "luascript_types.h"
15 struct fc_lua;
16 
17 typedef char *signal_deprecator;
18 
19 // Signal callback datastructure.
21  char *name; // callback function name
22 };
23 
24 // Signal datastructure.
25 struct signal {
26  int nargs; // number of arguments to pass
27  enum api_types *arg_types; // argument types
28  QList<signal_callback *> *callbacks; // connected callbacks
29  char *depr_msg; // deprecation message to show if handler added
30 };
31 
32 void luascript_signal_init(struct fc_lua *fcl);
33 void luascript_signal_free(struct fc_lua *fcl);
34 
36  const char *signal_name, va_list args);
37 void luascript_signal_emit(struct fc_lua *fcl, const char *signal_name, ...);
39  const char *signal_name,
40  int nargs, ...);
41 void deprecate_signal(signal_deprecator *deprecator, const char *signal_name,
42  const char *replacement, const char *deprecated_since);
43 void luascript_signal_callback(struct fc_lua *fcl, const char *signal_name,
44  const char *callback_name, bool create);
46  const char *signal_name,
47  const char *callback_name);
48 
49 QString luascript_signal_by_index(struct fc_lua *fcl, int sindex);
51  const char *signal_name,
52  int sindex);
void luascript_signal_free(struct fc_lua *fcl)
Free script signals and callbacks.
void luascript_signal_init(struct fc_lua *fcl)
Initialize script signals and callbacks.
bool luascript_signal_callback_defined(struct fc_lua *fcl, const char *signal_name, const char *callback_name)
Returns if a callback function to a certain signal is defined.
signal_deprecator * luascript_signal_create(struct fc_lua *fcl, const char *signal_name, int nargs,...)
Create a new signal type.
void deprecate_signal(signal_deprecator *deprecator, const char *signal_name, const char *replacement, const char *deprecated_since)
Mark signal deprecated.
void luascript_signal_emit_valist(struct fc_lua *fcl, const char *signal_name, va_list args)
Invoke all the callback functions attached to a given signal.
const char * luascript_signal_callback_by_index(struct fc_lua *fcl, const char *signal_name, int sindex)
Return the name of the 'index' callback function of the signal with the name 'signal_name'.
void luascript_signal_emit(struct fc_lua *fcl, const char *signal_name,...)
Invoke all the callback functions attached to a given signal.
void luascript_signal_callback(struct fc_lua *fcl, const char *signal_name, const char *callback_name, bool create)
Connects a callback function to a certain signal.
char * signal_deprecator
QString luascript_signal_by_index(struct fc_lua *fcl, int sindex)
Return the name of the signal with the given index.
static void static sol::state * fcl
Lua virtual machine state.
Definition: script_fcdb.cpp:48
enum api_types * arg_types
char * depr_msg
QList< signal_callback * > * callbacks