13#ifndef FC__API_SPECENUM_H
14#define FC__API_SPECENUM_H
20#define API_SPECENUM_INDEX_NAME(type) api_specenum_##type##_index
21#define API_SPECENUM_NAME_NAME(type) api_specenum_##type##_name
29#define API_SPECENUM_DEFINE_INDEX(type_name, prefix) \
30 static int (API_SPECENUM_INDEX_NAME(type_name))(lua_State *L) \
32 static char _buf[128]; \
34 enum type_name _value; \
35 luaL_checktype(L, 1, LUA_TTABLE); \
36 _key = luaL_checkstring(L, 2); \
37 fc_snprintf(_buf, sizeof(_buf), prefix "%s", _key); \
38 _value = type_name##_by_name(_buf, strcmp); \
39 if (_value != type_name##_invalid()) { \
41 lua_pushstring(L, _key); \
42 lua_pushinteger(L, _value); \
44 lua_pushinteger(L, _value); \
58#define API_SPECENUM_DEFINE_INDEX_REV(type_name) \
59 static int (API_SPECENUM_NAME_NAME(type_name))(lua_State *L) \
61 enum type_name _key; \
63 luaL_checktype(L, 1, LUA_TTABLE); \
64 _key = luaL_checkinteger(L, 2); \
65 if (type_name##_is_valid(_key)) { \
66 _value = type_name##_name(_key); \
68 lua_pushinteger(L, _key); \
69 lua_pushstring(L, _value); \
71 lua_pushstring(L, _value); \
81#define API_SPECENUM_CREATE_TABLE(L, type, name) \
82 api_specenum_create_table((L), (name), API_SPECENUM_INDEX_NAME(type))
83#define API_SPECENUM_CREATE_TABLE_REV(L, type, name) \
84 api_specenum_create_table((L), (name), API_SPECENUM_NAME_NAME(type))
void api_specenum_create_table(lua_State *L, const char *name, lua_CFunction findex)