33 static const char *
Race =
"race";
34 static const char *
Gen =
"name generator";
45 char const* m = luaL_checkstring(L, 2);
54 if (strcmp(m,
"traits") == 0) {
58 const std::string&
id = trait[
"id"];
59 lua_pushlstring(L,
id.c_str(),
id.length());
65 const std::string&
id = trait[
"id"];
66 lua_pushlstring(L,
id.c_str(),
id.length());
72 if (strcmp(m,
"male_name_gen") == 0) {
74 luaL_getmetatable(L,
Gen);
75 lua_setmetatable(L, -2);
78 if (strcmp(m,
"female_name_gen") == 0) {
80 luaL_getmetatable(L,
Gen);
81 lua_setmetatable(L, -2);
94 std::ostringstream str;
95 str <<
"race: <" << race.
id() <<
'>';
104 luaL_newmetatable(L,
Race);
106 static luaL_Reg
const callbacks[] {
111 luaL_setfuncs(L, callbacks, 0);
113 lua_pushstring(L,
"race");
114 lua_setfield(L, -2,
"__metatable");
116 return "Adding getrace metatable...\n";
122 lua_createtable(L, 0, 1);
123 lua_pushstring(L, race.
id().c_str());
124 lua_setfield(L, -2,
"id");
125 luaL_setmetatable(L,
Race);
131 lua_createtable(L, 0, races.size());
133 for (
const race_map::value_type &race : races)
135 assert(race.first == race.second.id());
137 lua_setfield(L, -2, race.first.c_str());
143 lua_pushstring(L,
"id");
147 luaL_argerror(L, idx,
"unknown race");
A config object defines a single node in a WML file, with access to child nodes.
const std::string & id() const
bool uses_global_traits() const
const t_string & name(GENDER gender=MALE) const
const std::string & undead_variation() const
const t_string & plural_name() const
const t_string & description() const
const config & get_cfg() const
unsigned int num_traits() const
const config::const_child_itors & additional_traits() const
const name_generator & generator(GENDER gender) const
const race_map & races() const
const unit_race * find_race(const std::string &) const
config_array_view traits() const
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
#define return_string_attrib(name, accessor)
#define return_cfgref_attrib(name, accessor)
#define return_int_attrib(name, accessor)
#define return_bool_attrib(name, accessor)
#define return_tstring_attrib(name, accessor)
static int impl_race_get(lua_State *L)
Gets some data on a race (__index metamethod).
static int impl_race_tostring(lua_State *L)
Turns a lua proxy race to string.
static const char * Race
Implementation for a lua reference to a race, used by the wesnoth in-game races table.
void luaW_pushrace(lua_State *L, const unit_race &race)
void luaW_pushracetable(lua_State *L)
const unit_race & luaW_checkrace(lua_State *L, int idx)
This namespace contains bindings for lua to hold a pointer to a race, and to access and modify it.
std::string register_metatable(lua_State *L)
void lua_push(lua_State *L, const T &val)
std::map< std::string, unit_race > race_map
unit_type_data unit_types