Freeciv-3.1
Loading...
Searching...
No Matches
api_signal_base.c
Go to the documentation of this file.
1/*****************************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12*****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* common/scriptcore */
19#include "luascript_signal.h"
20#include "luascript.h"
21
22#include "api_signal_base.h"
23
24/**********************************************************************/
27void api_signal_connect(lua_State *L, const char *signal_name,
28 const char *callback_name)
29{
30 struct fc_lua *fcl;
31
33 LUASCRIPT_CHECK_ARG_NIL(L, signal_name, 2, string);
34 LUASCRIPT_CHECK_ARG_NIL(L, callback_name, 3, string);
35
36 fcl = luascript_get_fcl(L);
37
38 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!");
39
40 luascript_signal_callback(fcl, signal_name, callback_name, TRUE);
41}
42
43/**********************************************************************/
46void api_signal_remove(lua_State *L, const char *signal_name,
47 const char *callback_name)
48{
49 struct fc_lua *fcl;
50
52 LUASCRIPT_CHECK_ARG_NIL(L, signal_name, 2, string);
53 LUASCRIPT_CHECK_ARG_NIL(L, callback_name, 3, string);
54
55 fcl = luascript_get_fcl(L);
56
57 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!");
58
59 luascript_signal_callback(fcl, signal_name, callback_name, FALSE);
60}
61
62/**********************************************************************/
65bool api_signal_defined(lua_State *L, const char *signal_name,
66 const char *callback_name)
67{
68 struct fc_lua *fcl;
69
71 LUASCRIPT_CHECK_ARG_NIL(L, signal_name, 2, string, FALSE);
72 LUASCRIPT_CHECK_ARG_NIL(L, callback_name, 3, string, FALSE);
73
74 fcl = luascript_get_fcl(L);
75
76 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", FALSE);
77
78 return luascript_signal_callback_defined(fcl, signal_name, callback_name);
79}
80
81/**********************************************************************/
84const char *api_signal_callback_by_index(lua_State *L,
85 const char *signal_name,
86 int sindex)
87{
88 struct fc_lua *fcl;
89
90 LUASCRIPT_CHECK_STATE(L, NULL);
91 LUASCRIPT_CHECK_ARG_NIL(L, signal_name, 2, string, NULL);
92
93 fcl = luascript_get_fcl(L);
94
95 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", NULL);
96
97 return luascript_signal_callback_by_index(fcl, signal_name, sindex);
98}
99
100/**********************************************************************/
104const char *api_signal_by_index(lua_State *L, int sindex)
105{
106 struct fc_lua *fcl;
107
108 LUASCRIPT_CHECK_STATE(L, NULL);
109
110 fcl = luascript_get_fcl(L);
111
112 LUASCRIPT_CHECK(L, fcl != NULL, "Undefined Freeciv lua state!", NULL);
113
114 return luascript_signal_by_index(fcl, sindex);
115}
const char * api_signal_callback_by_index(lua_State *L, const char *signal_name, int sindex)
bool api_signal_defined(lua_State *L, const char *signal_name, const char *callback_name)
const char * api_signal_by_index(lua_State *L, int sindex)
void api_signal_connect(lua_State *L, const char *signal_name, const char *callback_name)
void api_signal_remove(lua_State *L, const char *signal_name, const char *callback_name)
struct fc_lua * luascript_get_fcl(lua_State *L)
Definition luascript.c:366
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
#define LUASCRIPT_CHECK(L, check, msg,...)
Definition luascript.h:124
bool luascript_signal_callback_defined(struct fc_lua *fcl, const char *signal_name, const char *callback_name)
const char * luascript_signal_by_index(struct fc_lua *fcl, int sindex)
const char * luascript_signal_callback_by_index(struct fc_lua *fcl, const char *signal_name, int sindex)
void luascript_signal_callback(struct fc_lua *fcl, const char *signal_name, const char *callback_name, bool create)
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47