Author: anonymissimus
Date: Sun May 8 23:36:53 2011
New Revision: 49444
URL: http://svn.gna.org/viewcvs/wesnoth?rev=49444&view=rev
Log:
minor improvements to wesnoth.get_sides; comments
Modified:
trunk/src/scripting/lua.cpp
Modified: trunk/src/scripting/lua.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/scripting/lua.cpp?rev=49444&r1=49443&r2=49444&view=diff
==============================================================================
--- trunk/src/scripting/lua.cpp (original)
+++ trunk/src/scripting/lua.cpp Sun May 8 23:36:53 2011
@@ -2903,14 +2903,16 @@
return 1;
}
+/**
+ * Returns a proxy table array for all sides matching the given SSF.
+ * - Arg 1: SSF (without a tag)
+ * - Arg 2: hidden optional argument, SSF with outer [filter_side] tag, for
backwards-compatibility
+ * - Ret 1: proxy table array
+ */
static int intf_get_sides(lua_State* L)
{
std::set<int> sides;
- if(!lua_isnoneornil(L, 2)) {
- const vconfig ssf_with_filter_tag = luaW_checkvconfig(L, 2);
- sides = game_events::get_sides_set(ssf_with_filter_tag);
- }
- else {
+ if(lua_isnoneornil(L, 2)) {
const vconfig ssf = luaW_checkvconfig(L, 1, true);
if (ssf.null()) {
for(unsigned side_number = 1; side_number <=
resources::teams->size(); ++side_number) {
@@ -2919,6 +2921,10 @@
}
else sides = game_events::get_sides_set(ssf, true);
}
+ else {
+ const vconfig ssf_with_filter_tag = luaW_checkvconfig(L, 2);
+ sides = game_events::get_sides_set(ssf_with_filter_tag);
+ }
//keep this stack in the loop:
//1: getsideKey getmetatable
@@ -2932,6 +2938,7 @@
lua_createtable(L, sides.size(), 0);
unsigned index = 1;
foreach(int side, sides) {
+ // Create a full userdata containing a pointer to the team.
team** t = static_cast<team**>(lua_newuserdata(L,
sizeof(team*)));
*t = &((*resources::teams)[side - 1]);
lua_pushvalue(L, 1);
@@ -3346,6 +3353,9 @@
lua_State *L = mState;
// Create the sides table.
+ // note:
+ // This table is redundant to the return value of wesnoth.get_sides({}).
+ // Still needed for backwards compatibility.
lua_getglobal(L, "wesnoth");
std::vector<team> &teams = *resources::teams;
lua_pushlightuserdata(L, (void *)&getsideKey);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits