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)
This commit is contained in:
Anonymissimus 2011-08-22 22:35:10 +00:00
parent 026566f0af
commit f6ca5cdbf7
2 changed files with 23 additions and 0 deletions

View file

@ -31,6 +31,8 @@ Version 1.9.8+svn:
* 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

View file

@ -3144,6 +3144,26 @@ static int intf_get_sides(lua_State* L)
return 1;
}
/**
* .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.
@ -3367,6 +3387,7 @@ LuaKernel::LuaKernel(const config &cfg)
{ "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 },