Author: silene
Date: Sun Mar 22 20:00:11 2009
New Revision: 34049

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34049&view=rev
Log:
Passed event arguments by complete table and added the "args" tag to it.

Modified:
    trunk/src/game_events.cpp
    trunk/src/scripting/lua.cpp
    trunk/src/scripting/lua.hpp

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=34049&r1=34048&r2=34049&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Sun Mar 22 20:00:11 2009
@@ -519,8 +519,7 @@
 
        WML_HANDLER_FUNCTION(lua, handler, ev, cfg)
        {
-               // Go through get_config for the script, otherwise it gets 
interpolated.
-               lua_kernel->run_event(cfg.get_config()["code"].c_str(), ev, 
&handler, units);
+               lua_kernel->run_event(cfg, ev, &handler, units);
        }
 
        WML_HANDLER_FUNCTION(remove_shroud, , , cfg)

Modified: trunk/src/scripting/lua.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.cpp?rev=34049&r1=34048&r2=34049&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Sun Mar 22 20:00:11 2009
@@ -602,7 +602,7 @@
 /**
  * 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)
 {
        lua_State *L = mState;
@@ -615,22 +615,38 @@
        eh->units = units;
        lua_settable(L, LUA_REGISTRYINDEX);
 
-       // Push location arguments.
-       int args = 0;
-       if (ev.loc1.valid())
-       {
+       // Get user-defined arguments; append locations and weapons to it.
+       config args;
+       vconfig vargs = cfg.child("args");
+       if (!vargs.null()) {
+               args = vargs.get_parsed_config();
+       }
+       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);
-               args += 2;
-               if (ev.loc2.valid())
-               {
-                       lua_pushinteger(L, ev.loc2.x + 1);
-                       lua_pushinteger(L, ev.loc2.y + 1);
-                       args += 2;
-               }
-       }
-
-       execute(prog, args, 0);
+               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");
+       }
+
+       // 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.
        lua_pushlightuserdata(L, (void *)&handlerKey);

Modified: trunk/src/scripting/lua.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.hpp?rev=34049&r1=34048&r2=34049&view=diff
==============================================================================
--- trunk/src/scripting/lua.hpp (original)
+++ trunk/src/scripting/lua.hpp Sun Mar 22 20:00:11 2009
@@ -26,7 +26,7 @@
 public:
        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 *);
        void run(char const *prog);
 };


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to