static int lua_member_lookup(lua_State* L) { #define IFLUA_NUM_MEMB_LOOKUP(n, m) \ if (strncmp(cstr, n, sizeof(n))==0){\ lua_pushnumber(L, m );\ } bind_t* state = lunar_t::check(L, 1); const char* cstr = lua_tostring(L, 2); EffectiveStats* stats = state->get_stats(L); if (!stats) { lua_pushnil(L); return 1; } if (strncmp(cstr, "spells", sizeof("spells")) == 0) { auto table = LuaValue::newtable(L); for (spell_id id : stats->spells.spell_id_list()) { table[table.objlen() + 1] = game_spell_data.get(id); } table.push(); return 1; } IFLUA_NUM_MEMB_LOOKUP("hp", stats->core.hp) else IFLUA_NUM_MEMB_LOOKUP("mp", stats->core.mp) else IFLUA_NUM_MEMB_LOOKUP("max_hp", stats->core.max_hp) else IFLUA_NUM_MEMB_LOOKUP("max_mp", stats->core.max_mp) else IFLUA_NUM_MEMB_LOOKUP("hpregen", stats->core.hpregen) else IFLUA_NUM_MEMB_LOOKUP("mpregen", stats->core.mpregen) else IFLUA_NUM_MEMB_LOOKUP("strength", stats->core.strength) else IFLUA_NUM_MEMB_LOOKUP("spell_velocity_multiplier", stats->core.spell_velocity_multiplier) else IFLUA_NUM_MEMB_LOOKUP("magic", stats->core.magic) else IFLUA_NUM_MEMB_LOOKUP("defence", stats->core.defence) else IFLUA_NUM_MEMB_LOOKUP("willpower", stats->core.willpower) else IFLUA_NUM_MEMB_LOOKUP("speed", stats->movespeed) else IFLUA_NUM_MEMB_LOOKUP("cooldown_mult", stats->cooldown_mult) else IFLUA_NUM_MEMB_LOOKUP("melee_cooldown_multiplier", stats->cooldown_modifiers.melee_cooldown_multiplier) else IFLUA_NUM_MEMB_LOOKUP("ranged_cooldown_multiplier", stats->cooldown_modifiers.ranged_cooldown_multiplier) else IFLUA_NUM_MEMB_LOOKUP("spell_cooldown_multiplier", stats->cooldown_modifiers.spell_cooldown_multiplier) // Allowed actions are lookup only else IFLUA_NUM_MEMB_LOOKUP("can_use_weapons", stats->allowed_actions.can_use_weapons) else IFLUA_NUM_MEMB_LOOKUP("can_use_spells", stats->allowed_actions.can_use_spells) else IFLUA_NUM_MEMB_LOOKUP("can_use_rest", stats->allowed_actions.can_use_rest) else IFLUA_NUM_MEMB_LOOKUP("can_use_stairs", stats->allowed_actions.can_use_stairs) else { lua_getglobal(L, bind_t::className); int tableind = lua_gettop(L); lua_pushvalue(L, 2); lua_gettable(L, tableind); lua_replace(L, tableind); } return 1; }
static int add(lua_State * L) { int nargs = lua_gettop(L); buffer<transition> ts; luaL_checktype(L, 2, LUA_TTABLE); int sz = objlen(L, 2); for (int i = 1; i <= sz; i++) { lua_rawgeti(L, 2, i); if (lua_isstring(L, -1) || is_name(L, -1)) { ts.push_back(transition(to_name_ext(L, -1), mk_expr_action())); lua_pop(L, 1); } else { luaL_checktype(L, -1, LUA_TTABLE); lua_rawgeti(L, -1, 1); lua_rawgeti(L, -2, 2); ts.push_back(transition(to_name_ext(L, -2), to_notation_action_ext(L, -1))); lua_pop(L, 3); } } bool overload = (nargs <= 3) || lua_toboolean(L, 4); return push_parse_table(L, to_parse_table(L, 1).add(ts.size(), ts.data(), to_expr(L, 3), LEAN_DEFAULT_NOTATION_PRIORITY, overload)); }