forked from github/server
fixing luabind
This commit is contained in:
parent
e32eebfd15
commit
c23da92768
14 changed files with 213 additions and 158 deletions
|
@ -193,7 +193,7 @@ object_set(attrib * a, object_type type, variant value)
|
||||||
data->type = type;
|
data->type = type;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSTRING:
|
case TSTRING:
|
||||||
data->data.str = strdup(value.v);
|
data->data.str = value.v?strdup(value.v):NULL;
|
||||||
break;
|
break;
|
||||||
case TINTEGER:
|
case TINTEGER:
|
||||||
data->data.i = value.i;
|
data->data.i = value.i;
|
||||||
|
|
|
@ -1897,13 +1897,12 @@ eval_race(struct opstack ** stack, const void * userdata)
|
||||||
static void
|
static void
|
||||||
eval_order(struct opstack ** stack, const void * userdata) /* order -> string */
|
eval_order(struct opstack ** stack, const void * userdata) /* order -> string */
|
||||||
{
|
{
|
||||||
const faction * report = (const faction*)userdata;
|
|
||||||
const struct order * ord = (const struct order *)opop(stack).v;
|
const struct order * ord = (const struct order *)opop(stack).v;
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
size_t len;
|
size_t len;
|
||||||
variant var;
|
variant var;
|
||||||
|
|
||||||
unused(report);
|
unused(userdata);
|
||||||
write_order(ord, buf, sizeof(buf));
|
write_order(ord, buf, sizeof(buf));
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
var.v = strcpy(balloc(len+1), buf);
|
var.v = strcpy(balloc(len+1), buf);
|
||||||
|
|
|
@ -27,7 +27,7 @@ extern "C" {
|
||||||
|
|
||||||
extern int force_color;
|
extern int force_color;
|
||||||
|
|
||||||
struct state * state_open();
|
struct state * state_open(void);
|
||||||
void state_close(struct state * );
|
void state_close(struct state * );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -171,5 +171,8 @@ bind_building(lua_State * L)
|
||||||
.def_readwrite("size", &building::size)
|
.def_readwrite("size", &building::size)
|
||||||
.def("add_action", &building_addaction)
|
.def("add_action", &building_addaction)
|
||||||
.property("objects", &eressea::get_objects<building>)
|
.property("objects", &eressea::get_objects<building>)
|
||||||
|
.scope [
|
||||||
|
def("create", &add_building)
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,5 +332,8 @@ bind_faction(lua_State * L)
|
||||||
.property("alliance", &faction_getalliance, &faction_setalliance)
|
.property("alliance", &faction_getalliance, &faction_setalliance)
|
||||||
.property("race", &faction_getrace, &faction_setrace)
|
.property("race", &faction_getrace, &faction_setrace)
|
||||||
.property("objects", &eressea::get_objects<faction>)
|
.property("objects", &eressea::get_objects<faction>)
|
||||||
|
.scope [
|
||||||
|
def("create", &add_faction)
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,14 @@ static tag *
|
||||||
next_tag(int hash, const state * st)
|
next_tag(int hash, const state * st)
|
||||||
{
|
{
|
||||||
while (st && hash!=MAXTHASH) {
|
while (st && hash!=MAXTHASH) {
|
||||||
tag * t = st->selected->tags[hash];
|
tag * node = st->selected->tags[hash];
|
||||||
if (t!=NULL) return t;
|
while (node!=NULL) {
|
||||||
|
region * r = findregion((short)node->coord.x, (short)node->coord.y);
|
||||||
|
if (r) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
node = node->nexthash;
|
||||||
|
}
|
||||||
++hash;
|
++hash;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -42,15 +48,18 @@ next_tag(int hash, const state * st)
|
||||||
|
|
||||||
class selectedregion {
|
class selectedregion {
|
||||||
public:
|
public:
|
||||||
static tag * next(tag * node) {
|
static tag * next(tag * self) {
|
||||||
if (node->nexthash) {
|
tag * node = self->nexthash;
|
||||||
return node->nexthash;
|
while (node) {
|
||||||
|
region * r = findregion((short)node->coord.x, (short)node->coord.y);
|
||||||
|
if (r) return node;
|
||||||
|
node = node->nexthash;
|
||||||
}
|
}
|
||||||
coordinate * c = &node->coord;
|
coordinate * c = &self->coord;
|
||||||
unsigned int key = ((c->x << 12) ^ c->y);
|
unsigned int key = ((c->x << 12) ^ c->y);
|
||||||
unsigned int hash = key & (MAXTHASH-1);
|
unsigned int hash = key & (MAXTHASH-1);
|
||||||
|
|
||||||
return next_tag(++hash, current_state);
|
return next_tag(hash+1, current_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static region * value(tag * node) {
|
static region * value(tag * node) {
|
||||||
|
@ -66,21 +75,33 @@ selected_regions(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gmtool_select_coordinate(int x, int y, int select)
|
gmtool_select_coordinate(int x, int y, bool select)
|
||||||
{
|
{
|
||||||
select_coordinate(current_state->selected, x, y, select);
|
select_coordinate(current_state->selected, x, y, select?1:0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gmtool_select_region(region& r, int select)
|
gmtool_select_region(region& r, bool select)
|
||||||
{
|
{
|
||||||
select_coordinate(current_state->selected, r.x, r.y, select);
|
select_coordinate(current_state->selected, r.x, r.y, select?1:0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gmtool_open(void)
|
||||||
|
{
|
||||||
|
state_open();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gmtool_close(void)
|
||||||
|
{
|
||||||
|
state_close(current_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bind_gmtool(lua_State * L)
|
bind_gmtool(lua_State * L)
|
||||||
{
|
{
|
||||||
module(L, "gmtool")[
|
module(L, "gmtool")[
|
||||||
|
def("open", &gmtool_open),
|
||||||
|
def("close", &gmtool_close),
|
||||||
def("editor", &run_mapper),
|
def("editor", &run_mapper),
|
||||||
def("get_selection", &selected_regions, return_stl_iterator),
|
def("get_selection", &selected_regions, return_stl_iterator),
|
||||||
def("get_cursor", ¤t_region),
|
def("get_cursor", ¤t_region),
|
||||||
|
|
|
@ -190,7 +190,6 @@ bind_message(lua_State * L)
|
||||||
.def(constructor<const char *>())
|
.def(constructor<const char *>())
|
||||||
.def(tostring(const_self))
|
.def(tostring(const_self))
|
||||||
|
|
||||||
.def("create", create_lua_message)
|
|
||||||
.def("set_unit", &lua_message::set_unit)
|
.def("set_unit", &lua_message::set_unit)
|
||||||
.def("set_region", &lua_message::set_region)
|
.def("set_region", &lua_message::set_region)
|
||||||
.def("set_resource", &lua_message::set_resource)
|
.def("set_resource", &lua_message::set_resource)
|
||||||
|
@ -198,5 +197,8 @@ bind_message(lua_State * L)
|
||||||
.def("set_string", &lua_message::set_string)
|
.def("set_string", &lua_message::set_string)
|
||||||
.def("send_faction", &lua_message::send_faction)
|
.def("send_faction", &lua_message::send_faction)
|
||||||
.def("send_region", &lua_message::send_region)
|
.def("send_region", &lua_message::send_region)
|
||||||
|
.scope [
|
||||||
|
def("create", &create_lua_message)
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace eressea {
|
||||||
case TSHIP:
|
case TSHIP:
|
||||||
return object(L, (ship*) val.v);
|
return object(L, (ship*) val.v);
|
||||||
case TSTRING:
|
case TSTRING:
|
||||||
return object(L, std::string((const char*) val.v));
|
return object(L, (const char*) val.v);
|
||||||
default:
|
default:
|
||||||
assert(!"not implemented");
|
assert(!"not implemented");
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ namespace eressea {
|
||||||
template<> void objects::set<const char *, TSTRING>(const char * name,
|
template<> void objects::set<const char *, TSTRING>(const char * name,
|
||||||
const char * value) {
|
const char * value) {
|
||||||
variant val = { 0 };
|
variant val = { 0 };
|
||||||
val.v = strdup(value);
|
if (value) val.v = strdup(value);
|
||||||
set_object(mAttribPtr, name, TSTRING, val);
|
set_object(mAttribPtr, name, TSTRING, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -377,5 +377,8 @@ bind_region(lua_State * L)
|
||||||
.property("buildings", ®ion_buildings, return_stl_iterator)
|
.property("buildings", ®ion_buildings, return_stl_iterator)
|
||||||
.property("ships", ®ion_ships, return_stl_iterator)
|
.property("ships", ®ion_ships, return_stl_iterator)
|
||||||
.property("objects", &eressea::get_objects<region>)
|
.property("objects", &eressea::get_objects<region>)
|
||||||
|
.scope [
|
||||||
|
def("create", ®ion_terraform)
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,5 +107,8 @@ bind_ship(lua_State * L)
|
||||||
.def_readwrite("size", &ship::size)
|
.def_readwrite("size", &ship::size)
|
||||||
.def_readwrite("coast", &ship::coast)
|
.def_readwrite("coast", &ship::coast)
|
||||||
.property("objects", &eressea::get_objects<ship>)
|
.property("objects", &eressea::get_objects<ship>)
|
||||||
|
.scope [
|
||||||
|
def("create", &add_ship)
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
using namespace luabind;
|
using namespace luabind;
|
||||||
|
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
#include <util/rng.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/skill.h>
|
#include <kernel/skill.h>
|
||||||
#include <kernel/terrainid.h>
|
#include <kernel/terrainid.h>
|
||||||
|
|
|
@ -600,5 +600,8 @@ bind_unit(lua_State * L)
|
||||||
.property("race", &unit_getrace, &unit_setrace)
|
.property("race", &unit_getrace, &unit_setrace)
|
||||||
.property("hp_max", &unit_hpmax)
|
.property("hp_max", &unit_hpmax)
|
||||||
.property("objects", &eressea::get_objects<unit>)
|
.property("objects", &eressea::get_objects<unit>)
|
||||||
|
.scope [
|
||||||
|
def("create", &add_unit)
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
local function test_pure()
|
||||||
|
free_game()
|
||||||
|
local r = region.create(0, 0, "plain")
|
||||||
|
end
|
||||||
|
|
||||||
local function test_read_write()
|
local function test_read_write()
|
||||||
free_game()
|
free_game()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
|
@ -48,7 +53,7 @@ local function test_gmtool()
|
||||||
selections=selections+1
|
selections=selections+1
|
||||||
end
|
end
|
||||||
assert(selections==2)
|
assert(selections==2)
|
||||||
print(gmtool.get_cursor())
|
assert(gmtool.get_cursor()==nil)
|
||||||
|
|
||||||
gmtool.close()
|
gmtool.close()
|
||||||
end
|
end
|
||||||
|
@ -163,11 +168,23 @@ local function test_hashtable()
|
||||||
end
|
end
|
||||||
|
|
||||||
loadscript("extensions.lua")
|
loadscript("extensions.lua")
|
||||||
test_read_write()
|
tests = {
|
||||||
test_region()
|
["test_pure"] = test_pure,
|
||||||
test_faction()
|
["test_read_write"] = test_read_write,
|
||||||
test_building()
|
["test_faction"] = test_faction,
|
||||||
test_unit()
|
["test_region"] = test_region,
|
||||||
test_message()
|
["test_building"] = test_building,
|
||||||
test_hashtable()
|
["test_unit"] = test_unit,
|
||||||
test_gmtool()
|
["test_message"] = test_message,
|
||||||
|
["test_hashtable"] = test_hashtable,
|
||||||
|
["test_gmtool"] = test_gmtool
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v in pairs(tests) do
|
||||||
|
local status, err = pcall(v)
|
||||||
|
if not status then
|
||||||
|
print("[FAIL] " .. k .. ": " .. err)
|
||||||
|
else
|
||||||
|
print("[OK] " .. k)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue