lua extensions:

- building.type
- tostring for ships
stricter const's
This commit is contained in:
Enno Rehling 2004-09-26 18:00:49 +00:00
parent bcab633424
commit 29ea980738
5 changed files with 30 additions and 4 deletions

View File

@ -96,7 +96,7 @@ building_setregion(building& b, region& r)
}
static std::ostream&
operator<<(std::ostream& stream, building& b)
operator<<(std::ostream& stream, const building& b)
{
stream << b.name;
stream << " (" << itoa36(b.no) << ")";
@ -132,6 +132,10 @@ building_units(const building& b) {
return eressea::list<unit *, unit *, buildingunit>(u);
}
const char *
building_gettype(const building& b) {
return b.type->_name;
}
void
bind_building(lua_State * L)
@ -148,6 +152,7 @@ bind_building(lua_State * L)
.property("info", &building_getinfo, &building_setinfo)
.property("units", &building_units, return_stl_iterator)
.property("region", &building_getregion, &building_setregion)
.def("type", &building_gettype)
.def_readonly("id", &building::no)
.def_readwrite("size", &building::size)
.def("add_action", &building_addaction)

View File

@ -74,7 +74,7 @@ faction_locale(const faction& f)
}
static std::ostream&
operator<<(std::ostream& stream, faction& f)
operator<<(std::ostream& stream, const faction& f)
{
stream << factionname(&f);
return stream;

View File

@ -80,7 +80,7 @@ region_addnotice(region& r, const char * str)
}
static std::ostream&
operator<<(std::ostream& stream, region& r)
operator<<(std::ostream& stream, const region& r)
{
stream << regionname(&r, NULL) << ", " << region_getterrain(r);
return stream;

View File

@ -10,8 +10,27 @@
#include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp>
#include <util/base36.h>
#include <ostream>
using namespace luabind;
static std::ostream&
operator<<(std::ostream& stream, const ship& sh)
{
stream << sh.name;
stream << " (" << itoa36(sh.no) << ")";
stream << ", " << sh.type->name;
stream << " size " << sh.size;
return stream;
}
static bool
operator==(const ship& a, const ship& sh)
{
return a.no==sh.no;
}
void
bind_ship(lua_State * L)
{
@ -19,6 +38,8 @@ bind_ship(lua_State * L)
def("get_ship", &findship),
class_<struct ship>("ship")
.def(self == ship())
.def(tostring(self))
.def_readonly("name", &ship::name)
.def_readonly("region", &ship::region)
.def_readonly("id", &ship::no)

View File

@ -325,7 +325,7 @@ set_flag(unit& u, const char * name, bool value)
}
static std::ostream&
operator<<(std::ostream& stream, unit& u)
operator<<(std::ostream& stream, const unit& u)
{
const char * rcname = get_racename(u.attribs);
stream << u.name << " (" << itoa36(u.no) << "), " << u.number << " " << u.race->_name[0];