Esempio n. 1
0
static int intf_wml_matches_filter(lua_State* L)
{
	config cfg = luaW_checkconfig(L, 1);
	config filter = luaW_checkconfig(L, 2);
	lua_pushboolean(L, cfg.matches(filter));
	return 1;
}
Esempio n. 2
0
/**
* Dumps a wml table or userdata wml object into a pretty string.
* - Arg 1: wml table or vconfig userdata
* - Ret 1: string
*/
static int intf_wml_tostring(lua_State* L) {
	const config& arg = luaW_checkconfig(L, 1);
	std::ostringstream stream;
	write(stream, arg);
	lua_pushstring(L, stream.str().c_str());
	return 1;
}
Esempio n. 3
0
static int impl_unit_attack_match(lua_State* L)
{
	const_attack_ptr atk = luaW_toweapon(L, 1);
	config cfg = luaW_checkconfig(L, 2);
	lua_pushboolean(L, atk->matches_filter(cfg));
	return 1;
}
Esempio n. 4
0
/**
 * Gets a property of a units attack (__index metamethod).
 * - Arg 1: table containing the userdata containing the unit id. and a string identyfying the attack.
 * - Arg 2: string
 * - Ret 1:
 */
static int impl_unit_attack_set(lua_State *L)
{
	attack_type& attack = luaW_checkweapon(L, 1);
	char const *m = luaL_checkstring(L, 2);
	modify_tstring_attrib("description", attack.set_name(value));
	modify_string_attrib("name", attack.set_id(value));
	modify_string_attrib("type", attack.set_type(value));
	modify_string_attrib("icon", attack.set_icon(value));
	modify_string_attrib("range", attack.set_range(value));
	modify_int_attrib("damage", attack.set_damage(value));
	modify_int_attrib("number", attack.set_num_attacks(value));
	modify_int_attrib("attack_weight", attack.set_attack_weight(value));
	modify_int_attrib("defense_weight", attack.set_defense_weight(value));
	modify_int_attrib("accuracy", attack.set_accuracy(value));
	modify_int_attrib("movement_used", attack.set_movement_used(value));
	modify_int_attrib("parry", attack.set_parry(value));

	if(strcmp(m, "specials") == 0) {
		attack.set_specials(luaW_checkconfig(L, 3));
		return 0;
	}

	std::string err_msg = "unknown modifiable property of attack: ";
	err_msg += m;
	return luaL_argerror(L, 2, err_msg.c_str());
}
Esempio n. 5
0
config luaW_checkconfig(lua_State *L, int index, const vconfig*& vcfg)
{
	config result = luaW_checkconfig(L, index);
	if(void* p = luaL_testudata(L, index, vconfigKey)) {
		vcfg = static_cast<vconfig*>(p);
	}
	return result;
}
static int impl_unit_attack_match(lua_State* L)
{
	const_attack_ptr atk = luaW_toweapon(L, 1);
	config cfg = luaW_checkconfig(L, 2);
	if(!atk) {
		return luaL_argerror(L, 1, "invalid attack");
	}
	lua_pushboolean(L, atk->matches_filter(cfg));
	return 1;
}
Esempio n. 7
0
/**
 * Returns a clone (deep copy) of the passed config, which can be either a normal config or a vconfig
 * If it is a vconfig, the underlying config is also cloned.
 * - Arg 1: a config
 * - Ret: the cloned config
 */
static int intf_clone_wml(lua_State* L)
{
	const vconfig* vcfg = nullptr;
	const config& cfg = luaW_checkconfig(L, 1, vcfg);
	if(vcfg) {
		config clone_underlying = vcfg->get_config();
		vconfig clone(clone_underlying);
		luaW_pushvconfig(L, clone);
	} else {
		luaW_pushconfig(L, cfg);
	}
	return 1;
}
Esempio n. 8
0
static int intf_format(lua_State* L)
{
	config cfg = luaW_checkconfig(L, 2);
	config_variable_set variables(cfg);
	if(lua_isstring(L, 1)) {
		std::string str = lua_tostring(L, 1);
		lua_push(L, utils::interpolate_variables_into_string(str, variables));
		return 1;
	}
	t_string str = luaW_checktstring(L, 1);
	lua_push(L, utils::interpolate_variables_into_tstring(str, variables));
	return 1;
}
static int impl_context_backend(lua_State * L, std::shared_ptr<lua_context_backend> backend, std::string req_name)
{
	if (!backend->valid) {
		luaL_error(L , "Error, you tried to use an invalid context object in a lua thread");
	}

	plugins_manager::event evt;
	evt.name = req_name;
	evt.data = luaW_checkconfig(L, -1);

	backend->requests.push_back(evt);
	return 0;
}
Esempio n. 10
0
/**
 * Sets a canvas on a widget of the current dialog.
 * - Arg 1: integer.
 * - Arg 2: WML table.
 * - Args 3..n: path of strings and integers.
 */
int intf_set_dialog_canvas(lua_State *L)
{
	int i = luaL_checkinteger(L, 1);
	gui2::twidget *w = find_widget(L, 3, true);
	gui2::tcontrol *c = dynamic_cast<gui2::tcontrol *>(w);
	if (!c) return luaL_argerror(L, lua_gettop(L), "unsupported widget");

	std::vector<gui2::tcanvas> &cv = c->canvas();
	if (i < 1 || unsigned(i) > cv.size())
		return luaL_argerror(L, 1, "out of bounds");

	config cfg = luaW_checkconfig(L, 2);
	cv[i - 1].set_cfg(cfg);
	return 0;
}
Esempio n. 11
0
static int impl_unit_attacks_set(lua_State* L)
{
	if(!lua_istable(L, 1)) {
		return luaW_type_error(L, 1, "unit attacks");
	}
	lua_rawgeti(L, 1, 0);
	const unit_type* ut = luaW_tounittype(L, -1);
	if(ut) {
		return luaL_argerror(L, 1, "unit type attack table is immutable");
	}

	unit& u = luaW_checkunit(L, -1);
	attack_ptr atk = lua_isnumber(L, 2) ? find_attack(&u, luaL_checkinteger(L, 2) - 1) : find_attack(&u, luaL_checkstring(L, 2));
	if(lua_isnumber(L, 2) && lua_tonumber(L, 2) - 1 > u.attacks().size()) {
		return luaL_argerror(L, 2, "attack can only be added at the end of the list");
	}

	if(lua_isnil(L, 3)) {
		// Delete the attack
		u.remove_attack(atk);
		return 0;
	}

	auto iter = get_attack_iter(u, atk), end = u.attacks().end();
	if(const_attack_ptr atk2 = luaW_toweapon(L, 3)) {
		if(iter == end) {
			atk = u.add_attack(end, *atk2);
		} else {
			iter.base()->reset(new attack_type(*atk2));
			atk = *iter.base();
		}
	} else {
		config cfg = luaW_checkconfig(L, 3);
		if(iter == end) {
			atk = u.add_attack(end, cfg);
		} else {
			iter.base()->reset(new attack_type(cfg));
			atk = *iter.base();
		}
	}
	if(!lua_isnumber(L, 2)) {
		atk->set_id(lua_tostring(L, 2));
	}
	return 0;
}
Esempio n. 12
0
/**
 * Displays a window.
 * - Arg 1: WML table describing the window.
 * - Arg 2: function called at pre-show.
 * - Arg 3: function called at post-show.
 * - Ret 1: integer.
 */
int show_dialog(lua_State *L, CVideo & video)
{
	config def_cfg = luaW_checkconfig(L, 1);

	gui2::twindow_builder::tresolution def(def_cfg);
	scoped_dialog w(L, gui2::build(video, &def));

	if (!lua_isnoneornil(L, 2)) {
		lua_pushvalue(L, 2);
		lua_call(L, 0, 0);
	}

	int v = scoped_dialog::current->window->show(true, 0);

	if (!lua_isnoneornil(L, 3)) {
		lua_pushvalue(L, 3);
		lua_call(L, 0, 0);
	}

	lua_pushinteger(L, v);
	return 1;
}
Esempio n. 13
0
	typename boost::enable_if<typename boost::is_same<T, config>::type, config>::type lua_check(lua_State *L, int n)
	{
		return luaW_checkconfig(L, n);
	}
Esempio n. 14
0
static int intf_create_attack(lua_State* L)
{
	auto atk = std::make_shared<attack_type>(luaW_checkconfig(L, 1));
	luaW_pushweapon(L, atk);
	return 1;
}