Author: anonymissimus
Date: Tue Aug 23 00:35:10 2011
New Revision: 50889

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50889&view=rev
Log:
New function wesnoth.get_traits returning a table holding the global traits 
known to the engine.
Creating a proxy table for this seems kind of overkill for now, and it is 
possible to add the function in the "compatibility" file later on just in case.
(FR bug #18362)

Modified:
    trunk/changelog
    trunk/src/scripting/lua.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=50889&r1=50888&r2=50889&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Tue Aug 23 00:35:10 2011
@@ -31,6 +31,8 @@
    * Added: function wesnoth.set_dialog_active (patch #2767)
    * Expanded wesnoth.races entries to return the wml object a race was 
constructed
      from via the __cfg field.
+   * New function wesnoth.get_traits returning a table holding the global 
traits
+     known to the engine.
  * Multiplayer:
    * Updated maps: Aethermaw, Hornshark Island, Sablestone Delta, Thousand
      Stings Garrison

Modified: trunk/src/scripting/lua.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.cpp?rev=50889&r1=50888&r2=50889&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Tue Aug 23 00:35:10 2011
@@ -3145,6 +3145,26 @@
 }
 
 /**
+ * .Returns information about the global traits known to the engine.
+ * - Ret 1: Table with named fields holding wml tables describing the traits.
+ */
+static int intf_get_traits(lua_State* L)
+{
+       lua_newtable(L);
+       foreach(const config& trait, unit_types.traits()) {
+               const std::string& id = trait["id"];
+               //It seems the engine does nowhere check the id field for 
emptyness or duplicates
+               //(also not later on).
+               //However, the worst thing to happen is that the trait read 
later overwrites the older one,
+               //and this is not the right place for such checks.
+               lua_pushstring(L, id.c_str());
+               luaW_pushconfig(L, trait);
+               lua_rawset(L, -3);
+       }
+       return 1;
+}
+
+/**
  * Adds a modification to a unit.
  * - Arg 1: unit.
  * - Arg 2: string.
@@ -3367,6 +3387,7 @@
                { "get_terrain",              &intf_get_terrain              },
                { "get_terrain_info",         &intf_get_terrain_info         },
                { "get_time_of_day",          &intf_get_time_of_day          },
+               { "get_traits",               &intf_get_traits               },
                { "get_unit",                 &intf_get_unit                 },
                { "get_units",                &intf_get_units                },
                { "get_variable",             &intf_get_variable             },


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

Reply via email to