Freeciv21
Develop your civilization from humble roots to a global empire
luascript_types.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 
12 // utility
13 #include "genlist.h"
14 
15 // common
16 #include "achievements.h"
17 #include "actions.h"
18 #include "city.h"
19 #include "connection.h"
20 #include "events.h"
21 #include "fc_types.h"
22 #include "game.h"
23 #include "government.h"
24 #include "improvement.h"
25 #include "nation.h"
26 #include "player.h"
27 #include "tech.h"
28 #include "terrain.h"
29 #include "tile.h"
30 #include "unit.h"
31 #include "unittype.h"
32 
33 // Classes.
34 /* If a new class is defined, an entry should be added to the enum api_types
35  * below and the class name should be added to the api_types list in
36  * tolua_common_z.pkg. */
37 typedef struct player Player;
38 typedef struct player_ai Player_ai;
39 typedef struct city City;
40 typedef struct unit Unit;
41 typedef struct tile Tile;
42 typedef struct government Government;
43 typedef struct nation_type Nation_Type;
44 typedef struct impr_type Building_Type;
45 typedef struct unit_type Unit_Type;
46 typedef struct advance Tech_Type;
47 typedef struct terrain Terrain;
48 typedef struct connection Connection;
49 typedef enum direction8 Direction;
50 typedef struct disaster_type Disaster;
51 typedef struct achievement Achievement;
52 typedef struct action Action;
53 
54 typedef void Nonexistent;
55 
56 /* List Classes.
57  * NOTE: These should not to be exposed since the pointers are not safe. They
58  * are only used by the API internally.
59  * Separate types makes use from lua type safe. */
60 typedef const struct unit_list_link Unit_List_Link;
61 typedef const struct city_list_link City_List_Link;
62 
63 #define SPECENUM_NAME api_types
64 #define SPECENUM_VALUE0 API_TYPE_INT
65 #define SPECENUM_VALUE0NAME "Int"
66 #define SPECENUM_VALUE1 API_TYPE_BOOL
67 #define SPECENUM_VALUE1NAME "Bool"
68 #define SPECENUM_VALUE2 API_TYPE_STRING
69 #define SPECENUM_VALUE2NAME "String"
70 #define SPECENUM_VALUE3 API_TYPE_PLAYER
71 #define SPECENUM_VALUE3NAME "Player"
72 #define SPECENUM_VALUE4 API_TYPE_CITY
73 #define SPECENUM_VALUE4NAME "City"
74 #define SPECENUM_VALUE5 API_TYPE_UNIT
75 #define SPECENUM_VALUE5NAME "Unit"
76 #define SPECENUM_VALUE6 API_TYPE_TILE
77 #define SPECENUM_VALUE6NAME "Tile"
78 #define SPECENUM_VALUE7 API_TYPE_GOVERNMENT
79 #define SPECENUM_VALUE7NAME "Government"
80 #define SPECENUM_VALUE8 API_TYPE_BUILDING_TYPE
81 #define SPECENUM_VALUE8NAME "Building_Type"
82 #define SPECENUM_VALUE9 API_TYPE_NATION_TYPE
83 #define SPECENUM_VALUE9NAME "Nation_Type"
84 #define SPECENUM_VALUE10 API_TYPE_UNIT_TYPE
85 #define SPECENUM_VALUE10NAME "Unit_Type"
86 #define SPECENUM_VALUE11 API_TYPE_TECH_TYPE
87 #define SPECENUM_VALUE11NAME "Tech_Type"
88 #define SPECENUM_VALUE12 API_TYPE_TERRAIN
89 #define SPECENUM_VALUE12NAME "Terrain"
90 #define SPECENUM_VALUE13 API_TYPE_CONNECTION
91 #define SPECENUM_VALUE13NAME "Connection"
92 #define SPECENUM_VALUE14 API_TYPE_DIRECTION
93 #define SPECENUM_VALUE14NAME "Direction"
94 #define SPECENUM_VALUE15 API_TYPE_DISASTER
95 #define SPECENUM_VALUE15NAME "Disaster"
96 #define SPECENUM_VALUE16 API_TYPE_ACHIEVEMENT
97 #define SPECENUM_VALUE16NAME "Achievement"
98 #define SPECENUM_VALUE17 API_TYPE_ACTION
99 #define SPECENUM_VALUE17NAME "Action"
100 #include "specenum_gen.h"
101 
102 // Define compatibility functions to translate between tolua and sol2. See:
103 // https://sol2.readthedocs.io/en/latest/api/stack.html#extension-points
104 #include "sol/forward.hpp"
105 #include "tolua.h"
106 
107 #define DEFINE_SOL_TOLUA_COMPAT(TYPE_) \
108  inline TYPE_ *sol_lua_check(sol::types<TYPE_ *>, lua_State *L, int index, \
109  sol::stack::record &) \
110  { \
111  return (TYPE_ *) tolua_tousertype(L, index, 0); \
112  } \
113  \
114  template <typename Handler> \
115  inline bool sol_lua_check(sol::types<TYPE_ *> expected, lua_State *L, \
116  int index, Handler &&handler, \
117  sol::stack::record &) \
118  { \
119  tolua_Error err; \
120  if (tolua_isusertype(L, index, #TYPE_, 0, &err)) \
121  return true; \
122  /* Use LUA_TUSERDATA instead of sol::type::userdata to avoid including \
123  * sol.hpp everywhere. */ \
124  handler(L, index, (sol::type) LUA_TUSERDATA, \
125  (sol::type) lua_type(L, index), \
126  "could not convert to " #TYPE_); \
127  return false; \
128  } \
129  \
130  inline int sol_lua_push(sol::types<TYPE_ *>, lua_State *L, TYPE_ *object) \
131  { \
132  tolua_pushusertype(L, (void *) object, #TYPE_); \
133  return 1; \
134  }
135 
138 
139 #undef DEFINE_SOL_TOLUA_COMPAT
const struct city_list_link City_List_Link
enum direction8 Direction
void Nonexistent
const struct unit_list_link Unit_List_Link
#define DEFINE_SOL_TOLUA_COMPAT(TYPE_)
Definition: tech.h:113
Definition: city.h:291
Definition: player.h:231
Definition: tile.h:42
Definition: unit.h:134