Freeciv-3.3: /fast/freeciv/nightly/main/common/scriptcore/api_specenum.h File Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Macros | Functions
api_specenum.h File Reference

Go to the source code of this file.

## Macros

#define | API_SPECENUM_INDEX_NAME(type) api_specenum_##type##_index
#define | API_SPECENUM_NAME_NAME(type) api_specenum_##type##_name
#define | API_SPECENUM_DEFINE_INDEX(type_name, prefix)
#define | API_SPECENUM_DEFINE_INDEX_REV(type_name)
#define | API_SPECENUM_CREATE_TABLE(L, type, name) api_specenum_create_table((L), (name), API_SPECENUM_INDEX_NAME(type))
#define | API_SPECENUM_CREATE_TABLE_REV(L, type, name) api_specenum_create_table((L), (name), API_SPECENUM_NAME_NAME(type))

## Functions

void | api_specenum_create_table (lua_State *L, const char *name, lua_CFunction findex)

## Macro Definition Documentation

## ◆ API_SPECENUM_CREATE_TABLE

#define API_SPECENUM_CREATE_TABLE | ( |  | L,
|  |  | type,
|  |  | name
| ) |  | api_specenum_create_table((L), (name), API_SPECENUM_INDEX_NAME(type))

Definition at line 81 of file api_specenum.h.

## ◆ API_SPECENUM_CREATE_TABLE_REV

#define API_SPECENUM_CREATE_TABLE_REV | ( |  | L,
|  |  | type,
|  |  | name
| ) |  | api_specenum_create_table((L), (name), API_SPECENUM_NAME_NAME(type))

Definition at line 83 of file api_specenum.h.

## ◆ API_SPECENUM_DEFINE_INDEX

#define API_SPECENUM_DEFINE_INDEX | ( |  | type_name,
|  |  | prefix
| ) |  |

Value:
static int (API_SPECENUM_INDEX_NAME(type_name))(lua_State *L) \
{ \
static char _buf[128]; \
const char *_key; \
enum type_name _value; \
luaL_checktype(L, 1, LUA_TTABLE); \
_key = luaL_checkstring(L, 2); \
fc_snprintf(_buf, sizeof(_buf), prefix "%s", _key); \
_value = type_name##_by_name(_buf, strcmp); \
if (_value != type_name##_invalid()) { \
/* T[_key] = _value */ \
lua_pushstring(L, _key); \
lua_pushinteger(L, _value); \
lua_rawset(L, 1); \
lua_pushinteger(L, _value); \
} else { \
lua_pushnil(L); \
} \
return 1; \
}
API_SPECENUM_INDEX_NAME
#define API_SPECENUM_INDEX_NAME(type)
Definition api_specenum.h:20
incite_cost
char * incite_cost
Definition comments.c:74
_by_name
static enum SPECENUM_NAME SPECENUM_FOO() _by_name(const char *name, int(*strcmp_func)(const char *, const char *))
Definition specenum_gen.h:7163

Define a the __index (table, key) -> value metamethod Return the enum value whose name is the concatenation of prefix and key. The fetched value is written back to the lua table, and further accesses will resolve there instead of this function.

Definition at line 29 of file api_specenum.h.

## ◆ API_SPECENUM_DEFINE_INDEX_REV

#define API_SPECENUM_DEFINE_INDEX_REV | ( |  | type_name | ) |

Value:
static int (API_SPECENUM_NAME_NAME(type_name))(lua_State *L) \
{ \
enum type_name _key; \
const char *_value; \
luaL_checktype(L, 1, LUA_TTABLE); \
_key = luaL_checkinteger(L, 2); \
if (type_name##_is_valid(_key)) { \
_value = type_name##_name(_key); \
/* T[_key] = _value */ \
lua_pushinteger(L, _key); \
lua_pushstring(L, _value); \
lua_rawset(L, 1); \
lua_pushstring(L, _value); \
} else { \
lua_pushnil(L); \
} \
return 1; \
}
API_SPECENUM_NAME_NAME
#define API_SPECENUM_NAME_NAME(type)
Definition api_specenum.h:21

Define the __index (table, key) -> value metamethod Return the enum name whose value is supplied. The fetched value is written back to the lua table, and further accesses will resolve there instead of this function. Note that the indices usually go from 0, not 1.

Definition at line 58 of file api_specenum.h.

## ◆ API_SPECENUM_INDEX_NAME

#define API_SPECENUM_INDEX_NAME | ( |  | type | ) | api_specenum_##type##_index

Definition at line 20 of file api_specenum.h.

## ◆ API_SPECENUM_NAME_NAME

#define API_SPECENUM_NAME_NAME | ( |  | type | ) | api_specenum_##type##_name

Definition at line 21 of file api_specenum.h.

## Function Documentation

## ◆ api_specenum_create_table()

void api_specenum_create_table | ( | lua_State * | L,
|  | const char * | name,
|  | lua_CFunction | findex
| ) |  |

Create a module table and set the member lookup function.

Definition at line 29 of file api_specenum.c.