34 static const char *
Race =
"race";
35 static const char *
Gen =
"name generator";
46 char const* m = luaL_checkstring(L, 2);
55 if (strcmp(m,
"traits") == 0) {
59 const std::string&
id = trait[
"id"];
60 lua_pushlstring(L,
id.c_str(),
id.length());
66 const std::string&
id = trait[
"id"];
67 lua_pushlstring(L,
id.c_str(),
id.length());
73 if (strcmp(m,
"male_name_gen") == 0) {
75 luaL_getmetatable(L,
Gen);
76 lua_setmetatable(L, -2);
79 if (strcmp(m,
"female_name_gen") == 0) {
81 luaL_getmetatable(L,
Gen);
82 lua_setmetatable(L, -2);
95 std::ostringstream str;
96 str <<
"race: <" << race.
id() <<
'>';
105 luaL_newmetatable(L,
Race);
107 static luaL_Reg
const callbacks[] {
112 luaL_setfuncs(L, callbacks, 0);
114 lua_pushstring(L,
"race");
115 lua_setfield(L, -2,
"__metatable");
117 return "Adding getrace metatable...\n";
123 lua_createtable(L, 0, 1);
124 lua_pushstring(L, race.
id().c_str());
125 lua_setfield(L, -2,
"id");
126 luaL_setmetatable(L,
Race);
132 lua_createtable(L, 0, races.size());
134 for (
const race_map::value_type &race : races)
136 assert(race.first == race.second.id());
138 lua_setfield(L, -2, race.first.c_str());
144 lua_pushstring(L,
"id");
148 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