Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/scriptcore/api_signal_base.c Source File

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/**********************************************************************/
27 void api_signal_connect(lua_State *L, const char *signal_name,
28 const char *callback_name)
29{
30 struct fc_lua *fcl;
31
32 LUASCRIPT_CHECK_STATE(L);
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/**********************************************************************/
46 void api_signal_remove(lua_State *L, const char *signal_name,
47 const char *callback_name)
48{
49 struct fc_lua *fcl;
50
51 LUASCRIPT_CHECK_STATE(L);
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/**********************************************************************/
65 bool api_signal_defined(lua_State *L, const char *signal_name,
66 const char *callback_name)
67{
68 struct fc_lua *fcl;
69
70 LUASCRIPT_CHECK_STATE(L, FALSE);
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/**********************************************************************/
84 const 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/**********************************************************************/
104 const 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}
api_signal_callback_by_index
const char * api_signal_callback_by_index(lua_State *L, const char *signal_name, int sindex)
Definition api_signal_base.c:84
api_signal_defined
bool api_signal_defined(lua_State *L, const char *signal_name, const char *callback_name)
Definition api_signal_base.c:65
api_signal_by_index
const char * api_signal_by_index(lua_State *L, int sindex)
Definition api_signal_base.c:104
api_signal_connect
void api_signal_connect(lua_State *L, const char *signal_name, const char *callback_name)
Definition api_signal_base.c:27
api_signal_remove
void api_signal_remove(lua_State *L, const char *signal_name, const char *callback_name)
Definition api_signal_base.c:46
api_signal_base.h
luascript_get_fcl
struct fc_lua * luascript_get_fcl(lua_State *L)
Definition luascript.c:366
luascript.h
LUASCRIPT_CHECK_STATE
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
LUASCRIPT_CHECK_ARG_NIL
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
LUASCRIPT_CHECK
#define LUASCRIPT_CHECK(L, check, msg,...)
Definition luascript.h:124
luascript_signal_callback_defined
bool luascript_signal_callback_defined(struct fc_lua *fcl, const char *signal_name, const char *callback_name)
Definition luascript_signal.c:343
luascript_signal_by_index
const char * luascript_signal_by_index(struct fc_lua *fcl, int sindex)
Definition luascript_signal.c:403
luascript_signal_callback_by_index
const char * luascript_signal_callback_by_index(struct fc_lua *fcl, const char *signal_name, int sindex)
Definition luascript_signal.c:415
luascript_signal_callback
void luascript_signal_callback(struct fc_lua *fcl, const char *signal_name, const char *callback_name, bool create)
Definition luascript_signal.c:298
luascript_signal.h
fc_lua
Definition luascript.h:44
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47