lua bindings

This commit is contained in:
Enno Rehling 2003-12-14 10:02:29 +00:00
parent a8c63c8a7c
commit 601f562ad4
24 changed files with 366 additions and 108 deletions

View File

@ -24,7 +24,7 @@
AdditionalIncludeDirectories="../kernel,../util,../..,.." AdditionalIncludeDirectories="../kernel,../util,../..,.."
PreprocessorDefinitions="_WINDOWS,WIN32,_DEBUG" PreprocessorDefinitions="_WINDOWS,WIN32,_DEBUG"
BasicRuntimeChecks="0" BasicRuntimeChecks="0"
RuntimeLibrary="5" RuntimeLibrary="3"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
PrecompiledHeaderThrough="stdafx.h" PrecompiledHeaderThrough="stdafx.h"
@ -76,7 +76,7 @@
AdditionalIncludeDirectories="../kernel,../util,../..,.." AdditionalIncludeDirectories="../kernel,../util,../..,.."
PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="4" RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE" EnableFunctionLevelLinking="TRUE"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="2" UsePrecompiledHeader="2"

View File

@ -78,7 +78,7 @@
extern const char *directions[]; extern const char *directions[];
extern const char *spelldata[]; extern const char *spelldata[];
extern int quiet; extern int quiet;
extern boolean opt_cr_absolute_coords; boolean opt_cr_absolute_coords = false;
/* globals */ /* globals */
#define C_REPORT_VERSION 64 #define C_REPORT_VERSION 64

View File

@ -1144,7 +1144,7 @@ maintain(building * b, boolean first)
boolean paid = true, work = first; boolean paid = true, work = first;
unit * u; unit * u;
if (fval(b, BLD_MAINTAINED)) return true; if (fval(b, BLD_MAINTAINED)) return true;
if (b->type->maintenance==NULL) return true; if (b->type==NULL || b->type->maintenance==NULL) return true;
if (is_cursed(b->attribs, C_NOCOST, 0)) { if (is_cursed(b->attribs, C_NOCOST, 0)) {
fset(b, BLD_MAINTAINED); fset(b, BLD_MAINTAINED);
fset(b, BLD_WORKING); fset(b, BLD_WORKING);

View File

@ -24,7 +24,7 @@
AdditionalIncludeDirectories="../kernel,../util,../..,.." AdditionalIncludeDirectories="../kernel,../util,../..,.."
PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="4" RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE" EnableFunctionLevelLinking="TRUE"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="2" UsePrecompiledHeader="2"
@ -128,7 +128,7 @@
AdditionalIncludeDirectories="../kernel,../util,../..,.." AdditionalIncludeDirectories="../kernel,../util,../..,.."
PreprocessorDefinitions="_WINDOWS,WIN32" PreprocessorDefinitions="_WINDOWS,WIN32"
BasicRuntimeChecks="0" BasicRuntimeChecks="0"
RuntimeLibrary="5" RuntimeLibrary="3"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
PrecompiledHeaderThrough="stdafx.h" PrecompiledHeaderThrough="stdafx.h"

View File

@ -113,8 +113,8 @@ RemoveNMRNewbie(void) {
static void static void
restart(unit *u, const race * rc) restart(unit *u, const race * rc)
{ {
faction *f = addplayer(u->region, u->faction->email, u->faction->passw, rc, u->faction->locale, u->faction->subscription)->faction; faction *f = addfaction(u->faction->email, u->faction->passw, rc, u->faction->locale, u->faction->subscription);
unit * nu = f->units; unit * nu = addplayer(u->region, f);
strlist ** o=&u->orders; strlist ** o=&u->orders;
f->subscription = u->faction->subscription; f->subscription = u->faction->subscription;
fset(f, FFL_RESTART); fset(f, FFL_RESTART);

View File

@ -30,6 +30,7 @@
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
#include <string.h>
const int FIREWORK_RANGE=10; const int FIREWORK_RANGE=10;

View File

@ -24,7 +24,7 @@
AdditionalIncludeDirectories="../kernel,../util,../..,.." AdditionalIncludeDirectories="../kernel,../util,../..,.."
PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="4" RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE" EnableFunctionLevelLinking="TRUE"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="2" UsePrecompiledHeader="2"
@ -75,7 +75,7 @@
AdditionalIncludeDirectories="../kernel,../util,../..,.." AdditionalIncludeDirectories="../kernel,../util,../..,.."
PreprocessorDefinitions="_WINDOWS,WIN32" PreprocessorDefinitions="_WINDOWS,WIN32"
BasicRuntimeChecks="0" BasicRuntimeChecks="0"
RuntimeLibrary="5" RuntimeLibrary="3"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
PrecompiledHeaderThrough="stdafx.h" PrecompiledHeaderThrough="stdafx.h"

View File

@ -86,6 +86,14 @@ const struct race * new_race[MAXRACES];
boolean sqlpatch = false; boolean sqlpatch = false;
int turn; int turn;
char *
strnzcpy(char * dst, const char *src, size_t len)
{
strncpy(dst, src, len);
dst[len]=0;
return dst;
}
static attrib_type at_creator = { static attrib_type at_creator = {
"creator" "creator"
/* Rest ist NULL; temporäres, nicht alterndes Attribut */ /* Rest ist NULL; temporäres, nicht alterndes Attribut */
@ -2066,7 +2074,7 @@ kernel_done(void)
} }
const char * localenames[] = { const char * localenames[] = {
"de", "en", "fr", "de", "en",
NULL NULL
}; };

View File

@ -30,6 +30,7 @@
/* libc includes */ /* libc includes */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
const unit * const unit *
@ -86,49 +87,56 @@ unused_faction_id(void)
return id; return id;
} }
unit * faction *
addplayer(region *r, const char *email, const char * password, addfaction(const char *email, const char * password,
const struct race * frace, const struct locale *loc, const struct race * frace, const struct locale *loc,
int subscription) int subscription)
{
int i;
faction *f;
assert(frace != new_race[RC_ORC]);
f = calloc(sizeof(faction), 1);
set_string(&f->email, email);
if (password) {
set_string(&f->passw, password);
} else {
for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0;
set_string(&f->passw, buf);
}
for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0;
set_string(&f->override, buf);
f->lastorders = turn;
f->alive = 1;
f->age = 0;
f->race = frace;
f->magiegebiet = 0;
f->locale = loc;
f->subscription = subscription;
f->options = Pow(O_REPORT) | Pow(O_ZUGVORLAGE) | Pow(O_SILBERPOOL) | Pow(O_COMPUTER) | Pow(O_COMPRESS) | Pow(O_ADRESSEN) | Pow(O_STATISTICS);
f->no = unused_faction_id();
register_faction_id(f->no);
sprintf(buf, "%s %s", LOC(loc, "factiondefault"), factionid(f));
set_string(&f->name, buf);
fset(f, FL_UNNAMED);
addlist(&factions, f);
return f;
}
unit *
addplayer(region *r, faction * f)
{ {
int i;
unit *u; unit *u;
faction *f;
assert(frace != new_race[RC_ORC]);
f = calloc(sizeof(faction), 1);
set_string(&f->email, email);
if (password) {
set_string(&f->passw, password);
} else {
for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0;
set_string(&f->passw, buf);
}
for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0;
set_string(&f->override, buf);
f->lastorders = turn;
f->alive = 1;
f->age = 0;
f->race = frace;
f->magiegebiet = 0;
f->locale = loc;
f->subscription = subscription;
set_ursprung(f, 0, r->x, r->y);
f->options = Pow(O_REPORT) | Pow(O_ZUGVORLAGE) | Pow(O_SILBERPOOL) | Pow(O_COMPUTER) | Pow(O_COMPRESS) | Pow(O_ADRESSEN) | Pow(O_STATISTICS);
f->no = unused_faction_id();
register_faction_id(f->no);
sprintf(buf, "%s %s", LOC(loc, "factiondefault"), factionid(f));
set_string(&f->name, buf);
fset(f, FL_UNNAMED);
addlist(&factions, f);
assert(f->units==NULL);
set_ursprung(f, 0, r->x, r->y);
u = createunit(r, f, 1, f->race); u = createunit(r, f, 1, f->race);
give_starting_equipment(r, u); give_starting_equipment(r, u);
fset(u, UFL_ISNEW); fset(u, UFL_ISNEW);

View File

@ -106,9 +106,10 @@ typedef struct faction_list {
extern const struct unit * random_unit_in_faction(const struct faction *f); extern const struct unit * random_unit_in_faction(const struct faction *f);
extern const char * factionname(const struct faction * f); extern const char * factionname(const struct faction * f);
extern void * resolve_faction(void * data); extern void * resolve_faction(void * data);
extern struct unit * addplayer(struct region *r, const char *email, extern struct unit * addplayer(struct region *r, faction * f);
const char* password, const struct race * frace, extern struct faction * addfaction(const char *email, const char* password,
const struct locale *loc, int subscription); const struct race * frace,
const struct locale *loc, int subscription);
extern boolean checkpasswd(const faction * f, const char * passwd, boolean shortp); extern boolean checkpasswd(const faction * f, const char * passwd, boolean shortp);
extern void destroyfaction(faction * f); extern void destroyfaction(faction * f);

View File

@ -76,7 +76,7 @@
AdditionalIncludeDirectories="../util,../..,.." AdditionalIncludeDirectories="../util,../..,.."
PreprocessorDefinitions="_WINDOWS,WIN32" PreprocessorDefinitions="_WINDOWS,WIN32"
BasicRuntimeChecks="0" BasicRuntimeChecks="0"
RuntimeLibrary="5" RuntimeLibrary="3"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
PrecompiledHeaderThrough="stdafx.h" PrecompiledHeaderThrough="stdafx.h"
@ -128,7 +128,7 @@
AdditionalIncludeDirectories="../util,../..,.." AdditionalIncludeDirectories="../util,../..,.."
PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS" PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS"
StringPooling="TRUE" StringPooling="TRUE"
RuntimeLibrary="4" RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE" EnableFunctionLevelLinking="TRUE"
DisableLanguageExtensions="TRUE" DisableLanguageExtensions="TRUE"
UsePrecompiledHeader="2" UsePrecompiledHeader="2"

View File

@ -1130,7 +1130,7 @@ spellpower(region * r, unit * u, spell * sp, int cast_level)
} }
#ifdef MAGICPOWER #ifdef MAGICPOWER
force = force * MAGICPOWER; force = (int)(force * MAGICPOWER);
#endif #endif
return max(force, 0); return max(force, 0);
@ -1498,7 +1498,7 @@ regeneration(unit * u)
aura = (rand() % d + rand() % d)/2 + 1; aura = (rand() % d + rand() % d)/2 + 1;
#ifdef MAGICREGEN #ifdef MAGICREGEN
aura = aura * MAGICREGEN; aura = (int)(aura * MAGICREGEN);
#endif #endif
return aura; return aura;

View File

@ -150,20 +150,16 @@
# define HAVE_SNPRINTF # define HAVE_SNPRINTF
/* MSVC has _access */ /* MSVC has _access */
_CRTIMP int __cdecl _access(const char *, int);
# define access(f, m) _access(f, m) # define access(f, m) _access(f, m)
# define HAVE_ACCESS # define HAVE_ACCESS
/* MSVC has _strdup */ /* MSVC has _strdup */
_CRTIMP char * __cdecl _strdup(const char *);
# define strdup(s) _strdup(s) # define strdup(s) _strdup(s)
# define HAVE_STRDUP # define HAVE_STRDUP
_CRTIMP int __cdecl _stricmp(const char *, const char *);
# define stricmp(a, b) _stricmp(a, b) # define stricmp(a, b) _stricmp(a, b)
# define HAVE_STRICMP # define HAVE_STRICMP
_CRTIMP int __cdecl _strnicmp(const char *, const char *, size_t);
# define strnicmp(a, b, c) _strnicmp(a, b, c) # define strnicmp(a, b, c) _strnicmp(a, b, c)
# define HAVE_STRNICMP # define HAVE_STRNICMP
# undef HAVE_STRCASECMP # undef HAVE_STRCASECMP
@ -236,6 +232,7 @@ extern char * strdup(const char *s);
# define true ((boolean)!false) # define true ((boolean)!false)
#endif #endif
#define strnzcpy(dst, src, len) (strncpy(dst, src, len), len?dst[len]=0:0, dst) /* this function must be implemented in a .o file */
extern char * strnzcpy(char * dst, const char *src, size_t len);
#endif #endif

View File

@ -0,0 +1,32 @@
#include <config.h>
#include <eressea.h>
#include "list.h"
// kernel includes
#include <kernel/region.h>
#include <modules/alliance.h>
// lua includes
#include <lua.hpp>
#include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp>
using namespace luabind;
static eressea::list<alliance>
get_alliances(void) {
return eressea::list<alliance>(alliances);
}
void
bind_alliance(lua_State * L)
{
module(L)[
def("alliances", &get_alliances, return_stl_iterator),
def("get_alliance", &findalliance),
class_<struct alliance>("alliance")
.def_readonly("name", &alliance::name)
.def_readonly("id", &alliance::id)
];
}

View File

@ -1,5 +1,5 @@
#ifndef BINDINGS_H #ifndef LUA_BINDINGS_H
#define BINDINGS_H #define LUA_BINDINGS_H
struct lua_State; struct lua_State;
@ -7,33 +7,8 @@ extern void bind_region(struct lua_State * L);
extern void bind_unit(struct lua_State * L); extern void bind_unit(struct lua_State * L);
extern void bind_ship(struct lua_State * L); extern void bind_ship(struct lua_State * L);
extern void bind_building(struct lua_State * L); extern void bind_building(struct lua_State * L);
extern void bind_faction(struct lua_State * L);
namespace eressea { extern void bind_alliance(struct lua_State * L);
template<class T> extern void bind_eressea(struct lua_State * L);
class list {
public:
class iterator {
public:
iterator(T * index) : m_index(index) {}
T * operator*() { return m_index; }
bool operator==(const iterator& iter) {
return iter.m_index==m_index;
}
iterator& operator++() {
if (m_index) m_index = m_index->next;
return *this;
}
private:
T * m_index;
};
typedef iterator const_iterator;
list<T>(T * clist) : m_clist(clist) {}
iterator begin() const { return iterator(m_clist); }
iterator end() const { return iterator(NULL); }
public:
T * m_clist;
};
};
#endif #endif

View File

@ -1,6 +1,6 @@
#include <config.h> #include <config.h>
#include <cstring>
#include <eressea.h> #include <eressea.h>
#include "bindings.h"
// kernel includes // kernel includes
#include <building.h> #include <building.h>
@ -11,7 +11,6 @@
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
using namespace luabind; using namespace luabind;
using namespace eressea;
void void
bind_building(lua_State * L) bind_building(lua_State * L)

View File

@ -0,0 +1,49 @@
#include <config.h>
#include <cstring>
#include <eressea.h>
// kernel includes
#include <modules/alliance.h>
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <kernel/region.h>
#include <util/language.h>
// lua includes
#include <lua.hpp>
#include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp>
using namespace luabind;
static faction *
add_faction(const char * email, const char * passwd, const char * racename, const char * lang)
{
const race * frace = findrace(racename, default_locale);
locale * loc = find_locale(lang);
faction * f = addfaction(email, passwd, frace, loc, 0);
return f;
}
static unit *
add_unit(faction * f, region * r)
{
if (f->units==NULL) return addplayer(r, f);
return createunit(r, f, 0, f->race);
}
static alliance *
add_alliance(int id, const char * name)
{
return makealliance(id, name);
}
void
bind_eressea(lua_State * L)
{
module(L)[
def("add_unit", &add_unit),
def("add_faction", &add_faction),
def("add_alliance", &add_alliance)
];
}

12
src/eressea/lua/export.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef LUA_EXPORT_H
#define LUA_EXPORT_H
struct lua_State;
extern void bind_region(struct lua_State * L);
extern void bind_unit(struct lua_State * L);
extern void bind_ship(struct lua_State * L);
extern void bind_building(struct lua_State * L);
extern void bind_faction(struct lua_State * L);
#endif

View File

@ -0,0 +1,61 @@
#include <config.h>
#include <eressea.h>
#include "list.h"
// kernel includes
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <modules/alliance.h>
// lua includes
#include <lua.hpp>
#include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp>
using namespace luabind;
static eressea::list<faction>
get_factions(void) {
return eressea::list<faction>(factions);
}
class factionunit {
public:
static unit * next(unit * node) { return node->nextF; }
static unit * value(unit * node) { return node; }
};
static eressea::list<unit, unit, factionunit>
faction_units(const faction& f)
{
return eressea::list<unit, unit, factionunit>(f.units);
}
static void
faction_setalliance(faction& f, alliance * team)
{
if (f.alliance==0) setalliance(&f, team);
}
static alliance *
faction_getalliance(const faction& f)
{
return f.alliance;
}
void
bind_faction(lua_State * L)
{
module(L)[
def("factions", &get_factions, return_stl_iterator),
def("get_faction", &findfaction),
class_<struct faction>("faction")
.def_readonly("name", &faction::name)
.def_readonly("id", &faction::no)
.property("units", &faction_units, return_stl_iterator)
.property("alliance", &faction_getalliance, &faction_setalliance)
];
}

41
src/eressea/lua/list.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef LUA_LIST_H
#define LUA_LIST_H
namespace eressea {
template<class T, class N = T>
class listnode {
public:
static N * next(N * node) { return node->next; }
static T * value(N * node) { return node; }
};
template<class T, class N = T, class nodetype = listnode<T, N> >
class list {
public:
class iterator {
public:
iterator(N * index) : m_index(index) {}
T * operator*() { return nodetype::value(m_index); }
bool operator==(const iterator& iter) {
return iter.m_index==m_index;
}
iterator& operator++() {
if (m_index) m_index = nodetype::next(m_index);
return *this;
}
private:
N * m_index;
};
typedef iterator const_iterator;
list<T, N, nodetype>(N * clist) : m_clist(clist) {}
iterator begin() const { return iterator(m_clist); }
iterator end() const { return iterator(NULL); }
public:
N * m_clist;
};
};
#endif

View File

@ -1,6 +1,6 @@
#include <config.h> #include <config.h>
#include <eressea.h> #include <eressea.h>
#include "bindings.h" #include "list.h"
// kernel includes // kernel includes
#include <region.h> #include <region.h>
@ -14,7 +14,6 @@
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
using namespace luabind; using namespace luabind;
using namespace eressea;
static eressea::list<region> static eressea::list<region>
get_regions(void) { get_regions(void) {
@ -44,25 +43,24 @@ region_setname(region& r, const char * name) {
static const char * static const char *
region_getname(const region& r) { region_getname(const region& r) {
if (r.land) return r.land->name; if (r.land) return r.land->name;
return r.terrain->name; return terrain[r.terrain].name;
} }
static void static void
region_setinfo(region& r, const char * info) { region_setinfo(region& r, const char * info) {
if (r.land) set_string(&r.land->display, info); set_string(&r.display, info);
} }
static const char * static const char *
region_getinfo(const region& r) { region_getinfo(const region& r) {
if (r.land) return r.land->display; return r.display;
return NULL;
} }
void void
bind_region(lua_State * L) bind_region(lua_State * L)
{ {
module(L)[ module(L)[
def("get_regions", &get_regions, return_stl_iterator), def("regions", &get_regions, return_stl_iterator),
def("get_region", &findregion), def("get_region", &findregion),
class_<struct region>("region") class_<struct region>("region")

View File

@ -1,6 +1,5 @@
#include <config.h> #include <config.h>
#include <eressea.h> #include <eressea.h>
#include "bindings.h"
// kernel includes // kernel includes
#include <ship.h> #include <ship.h>
@ -12,7 +11,6 @@
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
using namespace luabind; using namespace luabind;
using namespace eressea;
void void
bind_ship(lua_State * L) bind_ship(lua_State * L)

View File

@ -1,10 +1,12 @@
#include <config.h> #include <config.h>
#include <eressea.h> #include <eressea.h>
#include "bindings.h"
// kernel includes // kernel includes
#include <region.h> #include <kernel/region.h>
#include <unit.h> #include <kernel/item.h>
#include <kernel/faction.h>
#include <kernel/skill.h>
#include <kernel/unit.h>
// lua includes // lua includes
#include <lua.hpp> #include <lua.hpp>
@ -12,7 +14,71 @@
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
using namespace luabind; using namespace luabind;
using namespace eressea;
static void
unit_setnumber(unit& u, int number)
{
if (u.number==0) set_number(&u, number);
}
static int
unit_getnumber(const unit& u)
{
return u.number;
}
static int
unit_getitem(const unit& u, const char * iname)
{
const item_type * itype = it_find(iname);
if (itype!=NULL) {
return i_get(u.items, itype);
}
return -1;
}
static int
unit_additem(unit& u, const char * iname, int number)
{
const item_type * itype = it_find(iname);
if (itype!=NULL) {
item * i = i_change(&u.items, itype, number);
return i?i->number:0;
} // if (itype!=NULL)
return -1;
}
static int
unit_getskill(const unit& u, const char * skname)
{
skill_t sk = sk_find(skname);
if (sk!=NOSKILL) {
skill * sv = get_skill(&u, sk);
return sv->level;
}
return -1;
}
static int
unit_effskill(const unit& u, const char * skname)
{
skill_t sk = sk_find(skname);
if (sk!=NOSKILL) {
return effskill(&u, sk);
}
return -1;
}
static int
unit_setskill(unit& u, const char * skname, int level)
{
skill_t sk = sk_find(skname);
if (sk!=NOSKILL) {
set_level(&u, sk, level);
return level;
} // if (sk!=NULL)
return -1;
}
void void
bind_unit(lua_State * L) bind_unit(lua_State * L)
@ -23,6 +89,13 @@ bind_unit(lua_State * L)
class_<struct unit>("unit") class_<struct unit>("unit")
.def_readonly("name", &unit::name) .def_readonly("name", &unit::name)
.def_readonly("region", &unit::region) .def_readonly("region", &unit::region)
.def_readonly("faction", &unit::faction)
.def_readonly("id", &unit::no) .def_readonly("id", &unit::no)
.def("get_item", &unit_getitem)
.def("add_item", &unit_additem)
.def("get_skill", &unit_getskill)
.def("eff_skill", &unit_effskill)
.def("set_skill", &unit_setskill)
.property("number", &unit_getnumber, &unit_setnumber)
]; ];
} }

5
src/lua.hpp Normal file
View File

@ -0,0 +1,5 @@
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}