mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-28 22:36:23 +00:00
Passed event arguments by complete table and added the "args" tag to it.
This commit is contained in:
parent
8a20afcc2f
commit
e24d85c5d9
@ -519,8 +519,7 @@ namespace {
|
|||||||
|
|
||||||
WML_HANDLER_FUNCTION(lua, handler, ev, cfg)
|
WML_HANDLER_FUNCTION(lua, handler, ev, cfg)
|
||||||
{
|
{
|
||||||
// Go through get_config for the script, otherwise it gets interpolated.
|
lua_kernel->run_event(cfg, ev, &handler, units);
|
||||||
lua_kernel->run_event(cfg.get_config()["code"].c_str(), ev, &handler, units);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WML_HANDLER_FUNCTION(remove_shroud, , , cfg)
|
WML_HANDLER_FUNCTION(remove_shroud, , , cfg)
|
||||||
|
@ -602,7 +602,7 @@ LuaKernel::~LuaKernel()
|
|||||||
/**
|
/**
|
||||||
* Runs a script from an event handler.
|
* Runs a script from an event handler.
|
||||||
*/
|
*/
|
||||||
void LuaKernel::run_event(char const *prog, game_events::queued_event const &ev,
|
void LuaKernel::run_event(vconfig const &cfg, game_events::queued_event const &ev,
|
||||||
game_events::event_handler *handler, unit_map *units)
|
game_events::event_handler *handler, unit_map *units)
|
||||||
{
|
{
|
||||||
lua_State *L = mState;
|
lua_State *L = mState;
|
||||||
@ -615,22 +615,38 @@ void LuaKernel::run_event(char const *prog, game_events::queued_event const &ev,
|
|||||||
eh->units = units;
|
eh->units = units;
|
||||||
lua_settable(L, LUA_REGISTRYINDEX);
|
lua_settable(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
// Push location arguments.
|
// Get user-defined arguments; append locations and weapons to it.
|
||||||
int args = 0;
|
config args;
|
||||||
if (ev.loc1.valid())
|
vconfig vargs = cfg.child("args");
|
||||||
{
|
if (!vargs.null()) {
|
||||||
lua_pushinteger(L, ev.loc1.x + 1);
|
args = vargs.get_parsed_config();
|
||||||
lua_pushinteger(L, ev.loc1.y + 1);
|
|
||||||
args += 2;
|
|
||||||
if (ev.loc2.valid())
|
|
||||||
{
|
|
||||||
lua_pushinteger(L, ev.loc2.x + 1);
|
|
||||||
lua_pushinteger(L, ev.loc2.y + 1);
|
|
||||||
args += 2;
|
|
||||||
}
|
}
|
||||||
|
if (const config *weapon = ev.data.child("first")) {
|
||||||
|
args.add_child("weapon", *weapon);
|
||||||
|
}
|
||||||
|
if (const config *weapon = ev.data.child("first")) {
|
||||||
|
args.add_child("second_weapon", *weapon);
|
||||||
|
}
|
||||||
|
lua_newtable(L);
|
||||||
|
table_of_wml_config(L, args);
|
||||||
|
if (ev.loc1.valid()) {
|
||||||
|
lua_pushinteger(L, ev.loc1.x + 1);
|
||||||
|
lua_setfield(L, -2, "x1");
|
||||||
|
lua_pushinteger(L, ev.loc1.y + 1);
|
||||||
|
lua_setfield(L, -2, "y1");
|
||||||
|
}
|
||||||
|
if (ev.loc2.valid()) {
|
||||||
|
lua_pushinteger(L, ev.loc2.x + 1);
|
||||||
|
lua_setfield(L, -2, "x2");
|
||||||
|
lua_pushinteger(L, ev.loc2.y + 1);
|
||||||
|
lua_setfield(L, -2, "y2");
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(prog, args, 0);
|
// Get the code from the uninterpolated config object, so that $ symbols
|
||||||
|
// are not messed with.
|
||||||
|
const std::string &prog = cfg.get_config()["code"];
|
||||||
|
|
||||||
|
execute(prog.c_str(), 1, 0);
|
||||||
|
|
||||||
// Clear registry.
|
// Clear registry.
|
||||||
lua_pushlightuserdata(L, (void *)&handlerKey);
|
lua_pushlightuserdata(L, (void *)&handlerKey);
|
||||||
|
@ -26,7 +26,7 @@ class LuaKernel
|
|||||||
public:
|
public:
|
||||||
LuaKernel();
|
LuaKernel();
|
||||||
~LuaKernel();
|
~LuaKernel();
|
||||||
void run_event(char const *, game_events::queued_event const &,
|
void run_event(vconfig const &, game_events::queued_event const &,
|
||||||
game_events::event_handler *, unit_map *);
|
game_events::event_handler *, unit_map *);
|
||||||
void run(char const *prog);
|
void run(char const *prog);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user