30 #define API_SPECENUM_INDEX_NAME(type) api_specenum_##type##_index
31 #define API_SPECENUM_CREATE_TABLE(L, type, name) \
32 api_specenum_create_table((L), (name), API_SPECENUM_INDEX_NAME(type))
40 #define API_SPECENUM_DEFINE_INDEX(type_name, prefix) \
41 static int(API_SPECENUM_INDEX_NAME(type_name))(lua_State * L) \
43 static char _buf[128]; \
45 enum type_name _value; \
46 luaL_checktype(L, 1, LUA_TTABLE); \
47 _key = luaL_checkstring(L, 2); \
48 fc_snprintf(_buf, sizeof(_buf), prefix "%s", _key); \
49 _value = type_name##_by_name(_buf, strcmp); \
50 if (_value != type_name##_invalid()) { \
52 lua_pushstring(L, _key); \
53 lua_pushinteger(L, _value); \
55 lua_pushinteger(L, _value); \
70 lua_getglobal(L,
name);
71 if (lua_isnil(L, -1)) {
74 lua_setglobal(L,
name);
79 lua_pushliteral(L,
"__index");
80 lua_pushcfunction(L, findex);
82 lua_setmetatable(L, -2);
#define API_SPECENUM_CREATE_TABLE(L, type, name)
static void api_specenum_create_table(lua_State *L, const char *name, lua_CFunction findex)
Create a module table and set the member lookup function.
#define API_SPECENUM_DEFINE_INDEX(type_name, prefix)
Define a the __index (table, key) -> value metamethod Return the enum value whose name is the concate...
int api_specenum_open(lua_State *L)
Define the __index function for each exported specenum type.
#define fc_assert_ret(condition)