stupidly named tolua_S renamed to just L, as is standard.

This commit is contained in:
Enno Rehling 2009-06-21 19:54:14 +00:00
parent 18e7e14fc9
commit 27d8628084
22 changed files with 1171 additions and 1170 deletions

View file

@ -21,12 +21,12 @@ without prior permission by the authors of Eressea.
#include <lua.h>
#include <tolua.h>
int tolua_buildinglist_next(lua_State *tolua_S)
int tolua_buildinglist_next(lua_State *L)
{
building** building_ptr = (building **)lua_touserdata(tolua_S, lua_upvalueindex(1));
building** building_ptr = (building **)lua_touserdata(L, lua_upvalueindex(1));
building * u = *building_ptr;
if (u != NULL) {
tolua_pushusertype(tolua_S, (void*)u, "building");
tolua_pushusertype(L, (void*)u, "building");
*building_ptr = u->next;
return 1;
}
@ -35,11 +35,11 @@ int tolua_buildinglist_next(lua_State *tolua_S)
static int
tolua_building_addaction(lua_State* tolua_S)
tolua_building_addaction(lua_State* L)
{
building* self = (building*)tolua_tousertype(tolua_S, 1, 0);
const char * fname = tolua_tostring(tolua_S, 2, 0);
const char * param = tolua_tostring(tolua_S, 3, 0);
building* self = (building*)tolua_tousertype(L, 1, 0);
const char * fname = tolua_tostring(L, 2, 0);
const char * param = tolua_tostring(L, 3, 0);
building_addaction(self, fname, param);
@ -47,133 +47,133 @@ tolua_building_addaction(lua_State* tolua_S)
}
static int
tolua_building_get_objects(lua_State* tolua_S)
tolua_building_get_objects(lua_State* L)
{
building * self = (building *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
building * self = (building *)tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, (void*)&self->attribs, "hashtable");
return 1;
}
static int tolua_building_get_region(lua_State* tolua_S)
static int tolua_building_get_region(lua_State* L)
{
building* self = (building*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushusertype(tolua_S, building_getregion(self), "region");
building* self = (building*) tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, building_getregion(self), "region");
return 1;
}
static int tolua_building_set_region(lua_State* tolua_S)
static int tolua_building_set_region(lua_State* L)
{
building* self = (building*)tolua_tousertype(tolua_S, 1, 0);
building_setregion(self, (region*)tolua_tousertype(tolua_S, 2, 0));
building* self = (building*)tolua_tousertype(L, 1, 0);
building_setregion(self, (region*)tolua_tousertype(L, 2, 0));
return 0;
}
static int tolua_building_get_name(lua_State* tolua_S)
static int tolua_building_get_name(lua_State* L)
{
building* self = (building*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, building_getname(self));
building* self = (building*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, building_getname(self));
return 1;
}
static int tolua_building_set_name(lua_State* tolua_S)
static int tolua_building_set_name(lua_State* L)
{
building* self = (building*)tolua_tousertype(tolua_S, 1, 0);
building_setname(self, tolua_tostring(tolua_S, 2, 0));
building* self = (building*)tolua_tousertype(L, 1, 0);
building_setname(self, tolua_tostring(L, 2, 0));
return 0;
}
static int tolua_building_get_size(lua_State* tolua_S)
static int tolua_building_get_size(lua_State* L)
{
building* self = (building*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, self->size);
building* self = (building*) tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, self->size);
return 1;
}
static int tolua_building_set_size(lua_State* tolua_S)
static int tolua_building_set_size(lua_State* L)
{
building* self = (building*)tolua_tousertype(tolua_S, 1, 0);
self->size = (int)tolua_tonumber(tolua_S, 2, 0);
building* self = (building*)tolua_tousertype(L, 1, 0);
self->size = (int)tolua_tonumber(L, 2, 0);
return 0;
}
static int
tolua_building_get_units(lua_State* tolua_S)
tolua_building_get_units(lua_State* L)
{
building * self = (building *)tolua_tousertype(tolua_S, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
building * self = (building *)tolua_tousertype(L, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
unit * u = self->region->units;
while (u && u->building!=self) u = u->next;
luaL_getmetatable(tolua_S, "unit");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "unit");
lua_setmetatable(L, -2);
*unit_ptr = u;
lua_pushcclosure(tolua_S, tolua_unitlist_nextb, 1);
lua_pushcclosure(L, tolua_unitlist_nextb, 1);
return 1;
}
static int
tolua_building_get_id(lua_State* tolua_S)
tolua_building_get_id(lua_State* L)
{
building * self = (building *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->no);
building * self = (building *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->no);
return 1;
}
static int
tolua_building_create(lua_State* tolua_S)
tolua_building_create(lua_State* L)
{
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
const char * bname = tolua_tostring(tolua_S, 2, 0);
region * r = (region *)tolua_tousertype(L, 1, 0);
const char * bname = tolua_tostring(L, 2, 0);
if (bname) {
const building_type * btype = bt_find(bname);
building * b = new_building(btype, r, NULL);
tolua_pushusertype(tolua_S, (void*)b, "building");
tolua_pushusertype(L, (void*)b, "building");
return 1;
}
return 0;
}
static int
tolua_building_tostring(lua_State *tolua_S)
tolua_building_tostring(lua_State *L)
{
building * self = (building *)tolua_tousertype(tolua_S, 1, 0);
lua_pushstring(tolua_S, buildingname(self));
building * self = (building *)tolua_tousertype(L, 1, 0);
lua_pushstring(L, buildingname(self));
return 1;
}
void
tolua_building_open(lua_State* tolua_S)
tolua_building_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "building");
tolua_usertype(tolua_S, "building_list");
tolua_usertype(L, "building");
tolua_usertype(L, "building_list");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_cclass(tolua_S, "building", "building", "", NULL);
tolua_beginmodule(tolua_S, "building");
tolua_cclass(L, "building", "building", "", NULL);
tolua_beginmodule(L, "building");
{
tolua_function(tolua_S, "__tostring", tolua_building_tostring);
tolua_function(L, "__tostring", tolua_building_tostring);
tolua_variable(tolua_S, "id", tolua_building_get_id, NULL);
tolua_variable(tolua_S, "name", tolua_building_get_name, tolua_building_set_name);
tolua_variable(tolua_S, "units", tolua_building_get_units, NULL);
tolua_variable(tolua_S, "region", tolua_building_get_region, tolua_building_set_region);
tolua_variable(tolua_S, "size", tolua_building_get_size, tolua_building_set_size);
tolua_function(tolua_S, "add_action", tolua_building_addaction);
tolua_variable(L, "id", tolua_building_get_id, NULL);
tolua_variable(L, "name", tolua_building_get_name, tolua_building_set_name);
tolua_variable(L, "units", tolua_building_get_units, NULL);
tolua_variable(L, "region", tolua_building_get_region, tolua_building_set_region);
tolua_variable(L, "size", tolua_building_get_size, tolua_building_set_size);
tolua_function(L, "add_action", tolua_building_addaction);
#ifdef TODO
.property("type", &building_gettype)
.def_readwrite("size", &building::size)
#endif
tolua_variable(tolua_S, "objects", tolua_building_get_objects, 0);
tolua_variable(L, "objects", tolua_building_get_objects, 0);
tolua_function(tolua_S, "create", tolua_building_create);
tolua_function(L, "create", tolua_building_create);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -15,8 +15,8 @@ extern "C" {
#endif
struct lua_State;
int tolua_buildinglist_next(struct lua_State *tolua_S);
void tolua_building_open(struct lua_State *tolua_S);
int tolua_buildinglist_next(struct lua_State *L);
void tolua_building_open(struct lua_State *L);
#ifdef __cplusplus
}

View file

@ -28,49 +28,49 @@ without prior permission by the authors of Eressea.
#include <tolua.h>
int tolua_factionlist_next(lua_State *tolua_S)
int tolua_factionlist_next(lua_State *L)
{
faction** faction_ptr = (faction **)lua_touserdata(tolua_S, lua_upvalueindex(1));
faction** faction_ptr = (faction **)lua_touserdata(L, lua_upvalueindex(1));
faction * f = *faction_ptr;
if (f != NULL) {
tolua_pushusertype(tolua_S, (void*)f, "faction");
tolua_pushusertype(L, (void*)f, "faction");
*faction_ptr = f->next;
return 1;
}
else return 0; /* no more values to return */
}
int tolua_factionlist_iter(lua_State *tolua_S)
int tolua_factionlist_iter(lua_State *L)
{
faction_list** faction_ptr = (faction_list **)lua_touserdata(tolua_S, lua_upvalueindex(1));
faction_list** faction_ptr = (faction_list **)lua_touserdata(L, lua_upvalueindex(1));
faction_list* flist = *faction_ptr;
if (flist != NULL) {
tolua_pushusertype(tolua_S, (void*)flist->data, "faction");
tolua_pushusertype(L, (void*)flist->data, "faction");
*faction_ptr = flist->next;
return 1;
}
else return 0; /* no more values to return */
}
static int tolua_faction_get_units(lua_State* tolua_S)
static int tolua_faction_get_units(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
faction * self = (faction *)tolua_tousertype(L, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
luaL_getmetatable(tolua_S, "unit");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "unit");
lua_setmetatable(L, -2);
*unit_ptr = self->units;
lua_pushcclosure(tolua_S, tolua_unitlist_nextf, 1);
lua_pushcclosure(L, tolua_unitlist_nextf, 1);
return 1;
}
int tolua_faction_add_item(lua_State *tolua_S)
int tolua_faction_add_item(lua_State *L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
const char * iname = tolua_tostring(tolua_S, 2, 0);
int number = (int)tolua_tonumber(tolua_S, 3, 0);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
const char * iname = tolua_tostring(L, 2, 0);
int number = (int)tolua_tonumber(L, 3, 0);
int result = -1;
if (iname!=NULL) {
@ -80,121 +80,121 @@ int tolua_faction_add_item(lua_State *tolua_S)
result = i?i->number:0;
} // if (itype!=NULL)
}
lua_pushnumber(tolua_S, result);
lua_pushnumber(L, result);
return 1;
}
static int
tolua_faction_get_maxheroes(lua_State* tolua_S)
tolua_faction_get_maxheroes(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)maxheroes(self));
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)maxheroes(self));
return 1;
}
static int
tolua_faction_get_heroes(lua_State* tolua_S)
tolua_faction_get_heroes(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)countheroes(self));
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)countheroes(self));
return 1;
}
static int
tolua_faction_get_score(lua_State* tolua_S)
tolua_faction_get_score(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->score);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->score);
return 1;
}
static int
tolua_faction_get_id(lua_State* tolua_S)
tolua_faction_get_id(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->no);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->no);
return 1;
}
static int
tolua_faction_set_id(lua_State* tolua_S)
tolua_faction_set_id(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
int id = (int)tolua_tonumber(tolua_S, 2, 0);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
int id = (int)tolua_tonumber(L, 2, 0);
if (findfaction(id)==NULL) {
renumber_faction(self, id);
lua_pushboolean(tolua_S, 1);
lua_pushboolean(L, 1);
} else {
lua_pushboolean(tolua_S, 0);
lua_pushboolean(L, 0);
}
return 1;
}
static int
tolua_faction_get_age(lua_State* tolua_S)
tolua_faction_get_age(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->age);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->age);
return 1;
}
static int
tolua_faction_set_age(lua_State* tolua_S)
tolua_faction_set_age(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
int age = (int)tolua_tonumber(tolua_S, 2, 0);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
int age = (int)tolua_tonumber(L, 2, 0);
self->age = age;
return 0;
}
static int
tolua_faction_get_flags(lua_State* tolua_S)
tolua_faction_get_flags(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->flags);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->flags);
return 1;
}
static int
tolua_faction_get_options(lua_State* tolua_S)
tolua_faction_get_options(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->options);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->options);
return 1;
}
static int
tolua_faction_get_lastturn(lua_State* tolua_S)
tolua_faction_get_lastturn(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->lastorders);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->lastorders);
return 1;
}
static int
tolua_faction_renumber(lua_State* tolua_S)
tolua_faction_renumber(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
int no = (int)tolua_tonumber(tolua_S, 2, 0);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
int no = (int)tolua_tonumber(L, 2, 0);
renumber_faction(self, no);
return 0;
}
static int
tolua_faction_get_objects(lua_State* tolua_S)
tolua_faction_get_objects(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
faction * self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, (void*)&self->attribs, "hashtable");
return 1;
}
static int
tolua_faction_get_policy(lua_State* tolua_S)
tolua_faction_get_policy(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
faction * other = (faction *)tolua_tousertype(tolua_S, 2, 0);
const char * policy = tolua_tostring(tolua_S, 3, 0);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
faction * other = (faction *)tolua_tousertype(L, 2, 0);
const char * policy = tolua_tostring(L, 3, 0);
int result = 0, mode;
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
@ -204,18 +204,18 @@ tolua_faction_get_policy(lua_State* tolua_S)
}
}
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_faction_set_policy(lua_State* tolua_S)
tolua_faction_set_policy(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
faction * other = (faction *)tolua_tousertype(tolua_S, 2, 0);
const char * policy = tolua_tostring(tolua_S, 3, 0);
int value = tolua_toboolean(tolua_S, 4, 0);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
faction * other = (faction *)tolua_tousertype(L, 2, 0);
const char * policy = tolua_tostring(L, 3, 0);
int value = tolua_toboolean(L, 4, 0);
int mode;
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
@ -233,9 +233,9 @@ tolua_faction_set_policy(lua_State* tolua_S)
}
static int
tolua_faction_get_origin(lua_State* tolua_S)
tolua_faction_get_origin(lua_State* L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
faction * self = (faction *)tolua_tousertype(L, 1, 0);
ursprung * origin = self->ursprung;
int x, y;
@ -250,17 +250,17 @@ tolua_faction_get_origin(lua_State* tolua_S)
y = 0;
}
tolua_pushnumber(tolua_S, (lua_Number)x);
tolua_pushnumber(tolua_S, (lua_Number)y);
tolua_pushnumber(L, (lua_Number)x);
tolua_pushnumber(L, (lua_Number)y);
return 2;
}
static int
tolua_faction_create(lua_State* tolua_S)
tolua_faction_create(lua_State* L)
{
const char * email = tolua_tostring(tolua_S, 1, 0);
const char * racename = tolua_tostring(tolua_S, 2, 0);
const char * lang = tolua_tostring(tolua_S, 3, 0);
const char * email = tolua_tostring(L, 1, 0);
const char * racename = tolua_tostring(L, 2, 0);
const char * lang = tolua_tostring(L, 3, 0);
struct locale * loc = find_locale(lang);
faction * f = NULL;
const struct race * frace = findrace(racename, default_locale);
@ -269,64 +269,64 @@ tolua_faction_create(lua_State* tolua_S)
if (frace!=NULL) {
f = addfaction(email, NULL, frace, loc, 0);
}
tolua_pushusertype(tolua_S, f, "faction");
tolua_pushusertype(L, f, "faction");
return 1;
}
static int tolua_faction_get_password(lua_State* tolua_S)
static int tolua_faction_get_password(lua_State* L)
{
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, faction_getpassword(self));
faction* self = (faction*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, faction_getpassword(self));
return 1;
}
static int tolua_faction_set_password(lua_State* tolua_S)
static int tolua_faction_set_password(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
faction_setpassword(self, tolua_tostring(tolua_S, 2, 0));
faction* self = (faction*)tolua_tousertype(L, 1, 0);
faction_setpassword(self, tolua_tostring(L, 2, 0));
return 0;
}
static int tolua_faction_get_email(lua_State* tolua_S)
static int tolua_faction_get_email(lua_State* L)
{
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, faction_getemail(self));
faction* self = (faction*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, faction_getemail(self));
return 1;
}
static int tolua_faction_set_email(lua_State* tolua_S)
static int tolua_faction_set_email(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
faction_setemail(self, tolua_tostring(tolua_S, 2, 0));
faction* self = (faction*)tolua_tousertype(L, 1, 0);
faction_setemail(self, tolua_tostring(L, 2, 0));
return 0;
}
static int tolua_faction_get_locale(lua_State* tolua_S)
static int tolua_faction_get_locale(lua_State* L)
{
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, locale_name(self->locale));
faction* self = (faction*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, locale_name(self->locale));
return 1;
}
static int tolua_faction_set_locale(lua_State* tolua_S)
static int tolua_faction_set_locale(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
faction* self = (faction*)tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
self->locale = find_locale(name);
return 0;
}
static int tolua_faction_get_race(lua_State* tolua_S)
static int tolua_faction_get_race(lua_State* L)
{
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, self->race->_name[0]);
faction* self = (faction*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->race->_name[0]);
return 1;
}
static int tolua_faction_set_race(lua_State* tolua_S)
static int tolua_faction_set_race(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
faction* self = (faction*)tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
race * rc = rc_find(name);
if (rc!=NULL) {
self->race = rc;
@ -335,45 +335,45 @@ static int tolua_faction_set_race(lua_State* tolua_S)
return 0;
}
static int tolua_faction_get_name(lua_State* tolua_S)
static int tolua_faction_get_name(lua_State* L)
{
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, faction_getname(self));
faction* self = (faction*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, faction_getname(self));
return 1;
}
static int tolua_faction_set_name(lua_State* tolua_S)
static int tolua_faction_set_name(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
faction_setname(self, tolua_tostring(tolua_S, 2, 0));
faction* self = (faction*)tolua_tousertype(L, 1, 0);
faction_setname(self, tolua_tostring(L, 2, 0));
return 0;
}
static int tolua_faction_get_info(lua_State* tolua_S)
static int tolua_faction_get_info(lua_State* L)
{
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, faction_getbanner(self));
faction* self = (faction*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, faction_getbanner(self));
return 1;
}
static int tolua_faction_set_info(lua_State* tolua_S)
static int tolua_faction_set_info(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
faction_setbanner(self, tolua_tostring(tolua_S, 2, 0));
faction* self = (faction*)tolua_tousertype(L, 1, 0);
faction_setbanner(self, tolua_tostring(L, 2, 0));
return 0;
}
static int tolua_faction_get_alliance(lua_State* tolua_S)
static int tolua_faction_get_alliance(lua_State* L)
{
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushusertype(tolua_S, self->alliance, "alliance");
faction* self = (faction*) tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, self->alliance, "alliance");
return 1;
}
static int tolua_faction_set_alliance(lua_State* tolua_S)
static int tolua_faction_set_alliance(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
alliance* alli = (alliance*)tolua_tousertype(tolua_S, 2, 0);
faction* self = (faction*)tolua_tousertype(L, 1, 0);
alliance* alli = (alliance*)tolua_tousertype(L, 2, 0);
if (!self->alliance) {
setalliance(self, alli);
@ -382,89 +382,89 @@ static int tolua_faction_set_alliance(lua_State* tolua_S)
return 0;
}
static int tolua_faction_get_items(lua_State* tolua_S)
static int tolua_faction_get_items(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
item ** item_ptr = (item **)lua_newuserdata(tolua_S, sizeof(item *));
faction* self = (faction*)tolua_tousertype(L, 1, 0);
item ** item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
luaL_getmetatable(tolua_S, "item");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "item");
lua_setmetatable(L, -2);
*item_ptr = self->items;
lua_pushcclosure(tolua_S, tolua_itemlist_next, 1);
lua_pushcclosure(L, tolua_itemlist_next, 1);
return 1;
}
static int
tolua_faction_tostring(lua_State *tolua_S)
tolua_faction_tostring(lua_State *L)
{
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
lua_pushstring(tolua_S, factionname(self));
faction * self = (faction *)tolua_tousertype(L, 1, 0);
lua_pushstring(L, factionname(self));
return 1;
}
static int tolua_faction_get_spells(lua_State* tolua_S)
static int tolua_faction_get_spells(lua_State* L)
{
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
faction* self = (faction*)tolua_tousertype(L, 1, 0);
spell_list * slist = self->spellbook;
if (slist) {
spell_list ** spell_ptr = (spell_list **)lua_newuserdata(tolua_S, sizeof(spell_list *));
luaL_getmetatable(tolua_S, "spell_list");
lua_setmetatable(tolua_S, -2);
spell_list ** spell_ptr = (spell_list **)lua_newuserdata(L, sizeof(spell_list *));
luaL_getmetatable(L, "spell_list");
lua_setmetatable(L, -2);
*spell_ptr = slist;
lua_pushcclosure(tolua_S, tolua_spelllist_next, 1);
lua_pushcclosure(L, tolua_spelllist_next, 1);
return 1;
}
lua_pushnil(tolua_S);
lua_pushnil(L);
return 1;
}
void
tolua_faction_open(lua_State* tolua_S)
tolua_faction_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "faction");
tolua_usertype(tolua_S, "faction_list");
tolua_usertype(L, "faction");
tolua_usertype(L, "faction_list");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_cclass(tolua_S, "faction", "faction", "", NULL);
tolua_beginmodule(tolua_S, "faction");
tolua_cclass(L, "faction", "faction", "", NULL);
tolua_beginmodule(L, "faction");
{
tolua_function(tolua_S, "__tostring", tolua_faction_tostring);
tolua_function(L, "__tostring", tolua_faction_tostring);
tolua_variable(tolua_S, "name", tolua_faction_get_name, tolua_faction_set_name);
tolua_variable(tolua_S, "info", tolua_faction_get_info, tolua_faction_set_info);
tolua_variable(tolua_S, "units", tolua_faction_get_units, NULL);
tolua_variable(tolua_S, "heroes", tolua_faction_get_heroes, NULL);
tolua_variable(tolua_S, "spells", tolua_faction_get_spells, 0);
tolua_variable(tolua_S, "maxheroes", tolua_faction_get_maxheroes, NULL);
tolua_variable(tolua_S, "password", tolua_faction_get_password, tolua_faction_set_password);
tolua_variable(tolua_S, "email", tolua_faction_get_email, tolua_faction_set_email);
tolua_variable(tolua_S, "locale", tolua_faction_get_locale, tolua_faction_set_locale);
tolua_variable(tolua_S, "race", tolua_faction_get_race, tolua_faction_set_race);
tolua_variable(tolua_S, "alliance", tolua_faction_get_alliance, tolua_faction_set_alliance);
tolua_variable(tolua_S, "score", tolua_faction_get_score, NULL);
tolua_variable(tolua_S, "id", tolua_faction_get_id, tolua_faction_set_id);
tolua_variable(tolua_S, "age", tolua_faction_get_age, tolua_faction_set_age);
tolua_variable(tolua_S, "options", tolua_faction_get_options, NULL);
tolua_variable(tolua_S, "flags", tolua_faction_get_flags, NULL);
tolua_variable(tolua_S, "lastturn", tolua_faction_get_lastturn, NULL);
tolua_variable(L, "name", tolua_faction_get_name, tolua_faction_set_name);
tolua_variable(L, "info", tolua_faction_get_info, tolua_faction_set_info);
tolua_variable(L, "units", tolua_faction_get_units, NULL);
tolua_variable(L, "heroes", tolua_faction_get_heroes, NULL);
tolua_variable(L, "spells", tolua_faction_get_spells, 0);
tolua_variable(L, "maxheroes", tolua_faction_get_maxheroes, NULL);
tolua_variable(L, "password", tolua_faction_get_password, tolua_faction_set_password);
tolua_variable(L, "email", tolua_faction_get_email, tolua_faction_set_email);
tolua_variable(L, "locale", tolua_faction_get_locale, tolua_faction_set_locale);
tolua_variable(L, "race", tolua_faction_get_race, tolua_faction_set_race);
tolua_variable(L, "alliance", tolua_faction_get_alliance, tolua_faction_set_alliance);
tolua_variable(L, "score", tolua_faction_get_score, NULL);
tolua_variable(L, "id", tolua_faction_get_id, tolua_faction_set_id);
tolua_variable(L, "age", tolua_faction_get_age, tolua_faction_set_age);
tolua_variable(L, "options", tolua_faction_get_options, NULL);
tolua_variable(L, "flags", tolua_faction_get_flags, NULL);
tolua_variable(L, "lastturn", tolua_faction_get_lastturn, NULL);
tolua_function(tolua_S, "set_policy", tolua_faction_set_policy);
tolua_function(tolua_S, "get_policy", tolua_faction_get_policy);
tolua_function(tolua_S, "get_origin", tolua_faction_get_origin);
tolua_function(L, "set_policy", tolua_faction_set_policy);
tolua_function(L, "get_policy", tolua_faction_get_policy);
tolua_function(L, "get_origin", tolua_faction_get_origin);
tolua_function(tolua_S, "add_item", tolua_faction_add_item);
tolua_variable(tolua_S, "items", tolua_faction_get_items, NULL);
tolua_function(L, "add_item", tolua_faction_add_item);
tolua_variable(L, "items", tolua_faction_get_items, NULL);
tolua_function(tolua_S, "renumber", tolua_faction_renumber);
tolua_function(tolua_S, "create", tolua_faction_create);
tolua_function(L, "renumber", tolua_faction_renumber);
tolua_function(L, "create", tolua_faction_create);
#ifdef TODO
def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)),
@ -475,9 +475,9 @@ tolua_faction_open(lua_State* tolua_S)
.def("add_notice", &faction_addnotice)
#endif
tolua_variable(tolua_S, "objects", tolua_faction_get_objects, NULL);
tolua_variable(L, "objects", tolua_faction_get_objects, NULL);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -15,9 +15,9 @@ extern "C" {
#endif
struct lua_State;
int tolua_factionlist_next(struct lua_State *tolua_S);
int tolua_factionlist_iter(struct lua_State *tolua_S);
void tolua_faction_open(struct lua_State *tolua_S);
int tolua_factionlist_next(struct lua_State *L);
int tolua_factionlist_iter(struct lua_State *L);
void tolua_faction_open(struct lua_State *L);
#ifdef __cplusplus
}

View file

@ -10,36 +10,36 @@
#include <tolua.h>
static int
tolua_run_mapper(lua_State* tolua_S)
tolua_run_mapper(lua_State* L)
{
run_mapper();
return 0;
}
static int
tolua_highlight_region(lua_State* tolua_S)
tolua_highlight_region(lua_State* L)
{
region * r = tolua_tousertype(tolua_S, 1, 0);
int select = tolua_toboolean(tolua_S, 2, 0);
region * r = tolua_tousertype(L, 1, 0);
int select = tolua_toboolean(L, 2, 0);
highlight_region(r, select);
return 0;
}
static int
tolua_current_region(lua_State* tolua_S)
tolua_current_region(lua_State* L)
{
map_region * mr = cursor_region(&current_state->display, &current_state->cursor);
tolua_pushusertype(tolua_S, mr?mr->r:NULL, "region");
tolua_pushusertype(L, mr?mr->r:NULL, "region");
return 1;
}
static int
tolua_select_coordinate(lua_State* tolua_S)
tolua_select_coordinate(lua_State* L)
{
int x = (int)tolua_tonumber(tolua_S, 1, 0);
int y = (int)tolua_tonumber(tolua_S, 2, 0);
int select = tolua_toboolean(tolua_S, 3, 0);
int x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0);
int select = tolua_toboolean(L, 3, 0);
if (current_state) {
select_coordinate(current_state->selected, x, y, select);
}
@ -47,10 +47,10 @@ tolua_select_coordinate(lua_State* tolua_S)
}
static int
tolua_select_region(lua_State* tolua_S)
tolua_select_region(lua_State* L)
{
region * r = tolua_tousertype(tolua_S, 1, 0);
int select = tolua_toboolean(tolua_S, 2, 0);
region * r = tolua_tousertype(L, 1, 0);
int select = tolua_toboolean(L, 2, 0);
if (current_state) {
select_coordinate(current_state->selected, r->x, r->y, select);
}
@ -105,11 +105,11 @@ tag_rewind(tag_iterator * iter)
}
static int
tolua_tags_next(lua_State *tolua_S)
tolua_tags_next(lua_State *L)
{
tag_iterator * iter = (tag_iterator *)lua_touserdata(tolua_S, lua_upvalueindex(1));
tag_iterator * iter = (tag_iterator *)lua_touserdata(L, lua_upvalueindex(1));
if (iter->node) {
tolua_pushusertype(tolua_S, (void*)iter->r, "region");
tolua_pushusertype(L, (void*)iter->r, "region");
tag_advance(iter);
return 1;
}
@ -119,59 +119,59 @@ tolua_tags_next(lua_State *tolua_S)
}
static int
tolua_selected_regions(lua_State* tolua_S)
tolua_selected_regions(lua_State* L)
{
tag_iterator * iter = (tag_iterator*)lua_newuserdata(tolua_S, sizeof(tag_iterator));
tag_iterator * iter = (tag_iterator*)lua_newuserdata(L, sizeof(tag_iterator));
luaL_getmetatable(tolua_S, "tag_iterator");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "tag_iterator");
lua_setmetatable(L, -2);
iter->list = current_state->selected;
tag_rewind(iter);
lua_pushcclosure(tolua_S, tolua_tags_next, 1);
lua_pushcclosure(L, tolua_tags_next, 1);
return 1;
}
static int
tolua_state_open(lua_State* tolua_S)
tolua_state_open(lua_State* L)
{
unused(tolua_S);
unused(L);
state_open();
return 0;
}
static int
tolua_state_close(lua_State* tolua_S)
tolua_state_close(lua_State* L)
{
unused(tolua_S);
unused(L);
state_close(current_state);
return 0;
}
void
tolua_gmtool_open(lua_State* tolua_S)
tolua_gmtool_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "tag_iterator");
tolua_usertype(L, "tag_iterator");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_module(tolua_S, "gmtool", 0);
tolua_beginmodule(tolua_S, "gmtool");
tolua_module(L, "gmtool", 0);
tolua_beginmodule(L, "gmtool");
{
tolua_function(tolua_S, "open", tolua_state_open);
tolua_function(tolua_S, "close", tolua_state_close);
tolua_function(L, "open", tolua_state_open);
tolua_function(L, "close", tolua_state_close);
tolua_function(tolua_S, "editor", tolua_run_mapper);
tolua_function(tolua_S, "get_selection", tolua_selected_regions);
tolua_function(tolua_S, "get_cursor", tolua_current_region);
tolua_function(tolua_S, "highlight", tolua_highlight_region);
tolua_function(tolua_S, "select", tolua_select_region);
tolua_function(tolua_S, "select_at", tolua_select_coordinate);
tolua_function(L, "editor", tolua_run_mapper);
tolua_function(L, "get_selection", tolua_selected_regions);
tolua_function(L, "get_cursor", tolua_current_region);
tolua_function(L, "highlight", tolua_highlight_region);
tolua_function(L, "select", tolua_select_region);
tolua_function(L, "select_at", tolua_select_coordinate);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -3,7 +3,7 @@ extern "C" {
#endif
struct lua_State;
void tolua_gmtool_open(struct lua_State *tolua_S);
void tolua_gmtool_open(struct lua_State *L);
#ifdef __cplusplus
}

View file

@ -29,10 +29,10 @@ without prior permission by the authors of Eressea.
#include <assert.h>
static int
tolua_hashtable_get(lua_State* tolua_S)
tolua_hashtable_get(lua_State* L)
{
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
attrib * a = a_find(*self, &at_object);
for (; a && a->type == &at_object; a = a->next) {
@ -44,28 +44,28 @@ tolua_hashtable_get(lua_State* tolua_S)
object_get(a, &type, &val);
switch (type) {
case TNONE:
lua_pushnil(tolua_S);
lua_pushnil(L);
break;
case TINTEGER:
lua_pushnumber(tolua_S, (lua_Number)val.i);
lua_pushnumber(L, (lua_Number)val.i);
break;
case TREAL:
lua_pushnumber(tolua_S, (lua_Number)val.f);
lua_pushnumber(L, (lua_Number)val.f);
break;
case TREGION:
tolua_pushusertype(tolua_S, val.v, "region");
tolua_pushusertype(L, val.v, "region");
break;
case TBUILDING:
tolua_pushusertype(tolua_S, val.v, "building");
tolua_pushusertype(L, val.v, "building");
break;
case TUNIT:
tolua_pushusertype(tolua_S, val.v, "unit");
tolua_pushusertype(L, val.v, "unit");
break;
case TSHIP:
tolua_pushusertype(tolua_S, val.v, "ship");
tolua_pushusertype(L, val.v, "ship");
break;
case TSTRING:
tolua_pushstring(tolua_S, (const char*) val.v);
tolua_pushstring(L, (const char*) val.v);
break;
default:
assert(!"not implemented");
@ -73,16 +73,16 @@ tolua_hashtable_get(lua_State* tolua_S)
return 1;
}
}
lua_pushnil(tolua_S);
lua_pushnil(L);
return 1;
}
static int
tolua_hashtable_set_number(lua_State* tolua_S)
tolua_hashtable_set_number(lua_State* L)
{
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
lua_Number value = tolua_tonumber(tolua_S, 3, 0);
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
lua_Number value = tolua_tonumber(L, 3, 0);
attrib * a = a_find(*self, &at_object);
variant val;
@ -100,11 +100,11 @@ tolua_hashtable_set_number(lua_State* tolua_S)
}
static int
tolua_hashtable_set_string(lua_State* tolua_S)
tolua_hashtable_set_string(lua_State* L)
{
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
const char * value = tolua_tostring(tolua_S, 3, 0);
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
const char * value = tolua_tostring(L, 3, 0);
attrib * a = a_find(*self, &at_object);
variant val;
@ -122,11 +122,11 @@ tolua_hashtable_set_string(lua_State* tolua_S)
}
static int
tolua_hashtable_set_usertype(lua_State* tolua_S, int type)
tolua_hashtable_set_usertype(lua_State* L, int type)
{
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
unit * value = tolua_tousertype(tolua_S, 3, 0);
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
unit * value = tolua_tousertype(L, 3, 0);
attrib * a = a_find(*self, &at_object);
variant val;
@ -145,43 +145,43 @@ tolua_hashtable_set_usertype(lua_State* tolua_S, int type)
static int
tolua_hashtable_set(lua_State* tolua_S)
tolua_hashtable_set(lua_State* L)
{
tolua_Error tolua_err;
if (tolua_isnumber(tolua_S, 3, 0, &tolua_err)) {
return tolua_hashtable_set_number(tolua_S);
} else if (tolua_isusertype(tolua_S, 3, "unit", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(tolua_S, TUNIT);
} else if (tolua_isusertype(tolua_S, 3, "faction", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(tolua_S, TFACTION);
} else if (tolua_isusertype(tolua_S, 3, "ship", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(tolua_S, TSHIP);
} else if (tolua_isusertype(tolua_S, 3, "building", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(tolua_S, TBUILDING);
} else if (tolua_isusertype(tolua_S, 3, "region", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(tolua_S, TREGION);
if (tolua_isnumber(L, 3, 0, &tolua_err)) {
return tolua_hashtable_set_number(L);
} else if (tolua_isusertype(L, 3, "unit", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(L, TUNIT);
} else if (tolua_isusertype(L, 3, "faction", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(L, TFACTION);
} else if (tolua_isusertype(L, 3, "ship", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(L, TSHIP);
} else if (tolua_isusertype(L, 3, "building", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(L, TBUILDING);
} else if (tolua_isusertype(L, 3, "region", 0, &tolua_err)) {
return tolua_hashtable_set_usertype(L, TREGION);
}
return tolua_hashtable_set_string(tolua_S);
return tolua_hashtable_set_string(L);
}
void
tolua_hashtable_open(lua_State* tolua_S)
tolua_hashtable_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "hashtable");
tolua_usertype(L, "hashtable");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_cclass(tolua_S, "hashtable", "hashtable", "", NULL);
tolua_beginmodule(tolua_S, "hashtable");
tolua_cclass(L, "hashtable", "hashtable", "", NULL);
tolua_beginmodule(L, "hashtable");
{
tolua_function(tolua_S, "get", tolua_hashtable_get);
tolua_function(tolua_S, "set", tolua_hashtable_set);
tolua_function(L, "get", tolua_hashtable_get);
tolua_function(L, "set", tolua_hashtable_set);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -15,7 +15,7 @@ extern "C" {
#endif
struct lua_State;
void tolua_hashtable_open(struct lua_State *tolua_S);
void tolua_hashtable_open(struct lua_State *L);
typedef struct attrib ** hashtable;

View file

@ -195,129 +195,129 @@ msg_send_region(lua_message * lmsg, region * r)
static int
tolua_msg_create(lua_State * tolua_S)
tolua_msg_create(lua_State * L)
{
const char * type = tolua_tostring(tolua_S, 1, 0);
const char * type = tolua_tostring(L, 1, 0);
lua_message * lmsg = msg_create_message(type);
tolua_pushusertype(tolua_S, (void*)lmsg, "message");
tolua_pushusertype(L, (void*)lmsg, "message");
return 1;
}
static int
tolua_msg_set_string(lua_State * tolua_S)
tolua_msg_set_string(lua_State * L)
{
lua_message * lmsg = (lua_message *)tolua_tousertype(tolua_S, 1, 0);
const char * param = tolua_tostring(tolua_S, 2, 0);
const char * value = tolua_tostring(tolua_S, 3, 0);
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char * param = tolua_tostring(L, 2, 0);
const char * value = tolua_tostring(L, 3, 0);
int result = msg_set_string(lmsg, param, value);
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_msg_set_int(lua_State * tolua_S)
tolua_msg_set_int(lua_State * L)
{
lua_message * lmsg = (lua_message *)tolua_tousertype(tolua_S, 1, 0);
const char * param = tolua_tostring(tolua_S, 2, 0);
int value = (int)tolua_tonumber(tolua_S, 3, 0);
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char * param = tolua_tostring(L, 2, 0);
int value = (int)tolua_tonumber(L, 3, 0);
int result = msg_set_int(lmsg, param, value);
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_msg_set_resource(lua_State * tolua_S)
tolua_msg_set_resource(lua_State * L)
{
lua_message * lmsg = (lua_message *)tolua_tousertype(tolua_S, 1, 0);
const char * param = tolua_tostring(tolua_S, 2, 0);
const char * value = tolua_tostring(tolua_S, 3, 0);
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char * param = tolua_tostring(L, 2, 0);
const char * value = tolua_tostring(L, 3, 0);
int result = msg_set_resource(lmsg, param, value);
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_msg_set_unit(lua_State * tolua_S)
tolua_msg_set_unit(lua_State * L)
{
lua_message * lmsg = (lua_message *)tolua_tousertype(tolua_S, 1, 0);
const char * param = tolua_tostring(tolua_S, 2, 0);
unit * value = (unit *)tolua_tousertype(tolua_S, 3, 0);
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char * param = tolua_tostring(L, 2, 0);
unit * value = (unit *)tolua_tousertype(L, 3, 0);
int result = msg_set_unit(lmsg, param, value);
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_msg_set_region(lua_State * tolua_S)
tolua_msg_set_region(lua_State * L)
{
lua_message * lmsg = (lua_message *)tolua_tousertype(tolua_S, 1, 0);
const char * param = tolua_tostring(tolua_S, 2, 0);
region * value = (region *)tolua_tousertype(tolua_S, 3, 0);
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char * param = tolua_tostring(L, 2, 0);
region * value = (region *)tolua_tousertype(L, 3, 0);
int result = msg_set_region(lmsg, param, value);
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_msg_set(lua_State * tolua_S)
tolua_msg_set(lua_State * L)
{
tolua_Error err;
if (tolua_isnumber(tolua_S, 3, 0, &err)) {
return tolua_msg_set_int(tolua_S);
} else if (tolua_isusertype(tolua_S, 3, "region", 0, &err)) {
return tolua_msg_set_region(tolua_S);
} else if (tolua_isusertype(tolua_S, 3, "unit", 0, &err)) {
return tolua_msg_set_unit(tolua_S);
if (tolua_isnumber(L, 3, 0, &err)) {
return tolua_msg_set_int(L);
} else if (tolua_isusertype(L, 3, "region", 0, &err)) {
return tolua_msg_set_region(L);
} else if (tolua_isusertype(L, 3, "unit", 0, &err)) {
return tolua_msg_set_unit(L);
}
tolua_pushnumber(tolua_S, (lua_Number)-1);
tolua_pushnumber(L, (lua_Number)-1);
return 1;
}
static int
tolua_msg_send_region(lua_State * tolua_S)
tolua_msg_send_region(lua_State * L)
{
lua_message * lmsg = (lua_message *)tolua_tousertype(tolua_S, 1, 0);
region * r = (region *)tolua_tousertype(tolua_S, 2, 0);
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
region * r = (region *)tolua_tousertype(L, 2, 0);
int result = msg_send_region(lmsg, r);
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_msg_send_faction(lua_State * tolua_S)
tolua_msg_send_faction(lua_State * L)
{
lua_message * lmsg = (lua_message *)tolua_tousertype(tolua_S, 1, 0);
faction * f = (faction *)tolua_tousertype(tolua_S, 2, 0);
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
faction * f = (faction *)tolua_tousertype(L, 2, 0);
int result = msg_send_faction(lmsg, f);
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
void
tolua_message_open(lua_State* tolua_S)
tolua_message_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "message");
tolua_usertype(L, "message");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_function(tolua_S, "message", tolua_msg_create);
tolua_function(L, "message", tolua_msg_create);
tolua_cclass(tolua_S, "message", "message", "", NULL);
tolua_beginmodule(tolua_S, "message");
tolua_cclass(L, "message", "message", "", NULL);
tolua_beginmodule(L, "message");
{
tolua_function(tolua_S, "set", tolua_msg_set);
tolua_function(tolua_S, "set_unit", tolua_msg_set_unit);
tolua_function(tolua_S, "set_region", tolua_msg_set_region);
tolua_function(tolua_S, "set_resource", tolua_msg_set_resource);
tolua_function(tolua_S, "set_int", tolua_msg_set_int);
tolua_function(tolua_S, "set_string", tolua_msg_set_string);
tolua_function(tolua_S, "send_faction", tolua_msg_send_faction);
tolua_function(tolua_S, "send_region", tolua_msg_send_region);
tolua_function(L, "set", tolua_msg_set);
tolua_function(L, "set_unit", tolua_msg_set_unit);
tolua_function(L, "set_region", tolua_msg_set_region);
tolua_function(L, "set_resource", tolua_msg_set_resource);
tolua_function(L, "set_int", tolua_msg_set_int);
tolua_function(L, "set_string", tolua_msg_set_string);
tolua_function(L, "send_faction", tolua_msg_send_faction);
tolua_function(L, "send_region", tolua_msg_send_region);
tolua_function(tolua_S, "create", tolua_msg_create);
tolua_function(L, "create", tolua_msg_create);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -15,7 +15,7 @@ extern "C" {
#endif
struct lua_State;
void tolua_message_open(struct lua_State *tolua_S);
void tolua_message_open(struct lua_State *L);
#ifdef __cplusplus
}

View file

@ -35,12 +35,12 @@ without prior permission by the authors of Eressea.
#include <lua.h>
#include <tolua.h>
int tolua_regionlist_next(lua_State *tolua_S)
int tolua_regionlist_next(lua_State *L)
{
region** region_ptr = (region **)lua_touserdata(tolua_S, lua_upvalueindex(1));
region** region_ptr = (region **)lua_touserdata(L, lua_upvalueindex(1));
region * u = *region_ptr;
if (u != NULL) {
tolua_pushusertype(tolua_S, (void*)u, "region");
tolua_pushusertype(L, (void*)u, "region");
*region_ptr = u->next;
return 1;
}
@ -48,90 +48,90 @@ int tolua_regionlist_next(lua_State *tolua_S)
}
static int
tolua_region_get_id(lua_State* tolua_S)
tolua_region_get_id(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->uid);
region * self = (region *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->uid);
return 1;
}
static int
tolua_region_get_x(lua_State* tolua_S)
tolua_region_get_x(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->x);
region * self = (region *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->x);
return 1;
}
static int
tolua_region_get_y(lua_State* tolua_S)
tolua_region_get_y(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->y);
region * self = (region *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->y);
return 1;
}
static int
tolua_region_get_terrain(lua_State* tolua_S)
tolua_region_get_terrain(lua_State* L)
{
region* self = (region*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, self->terrain->_name);
region* self = (region*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->terrain->_name);
return 1;
}
static int tolua_region_get_info(lua_State* tolua_S)
static int tolua_region_get_info(lua_State* L)
{
region* self = (region*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, region_getinfo(self));
region* self = (region*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, region_getinfo(self));
return 1;
}
static int tolua_region_set_info(lua_State* tolua_S)
static int tolua_region_set_info(lua_State* L)
{
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
region_setinfo(self, tolua_tostring(tolua_S, 2, 0));
region* self = (region*)tolua_tousertype(L, 1, 0);
region_setinfo(self, tolua_tostring(L, 2, 0));
return 0;
}
static int tolua_region_get_name(lua_State* tolua_S)
static int tolua_region_get_name(lua_State* L)
{
region* self = (region*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, region_getname(self));
region* self = (region*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, region_getname(self));
return 1;
}
static int tolua_region_set_name(lua_State* tolua_S)
static int tolua_region_set_name(lua_State* L)
{
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
region_setname(self, tolua_tostring(tolua_S, 2, 0));
region* self = (region*)tolua_tousertype(L, 1, 0);
region_setname(self, tolua_tostring(L, 2, 0));
return 0;
}
static int tolua_region_get_flag(lua_State* tolua_S)
static int tolua_region_get_flag(lua_State* L)
{
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
int bit = (int)tolua_tonumber(tolua_S, 2, 0);
region* self = (region*)tolua_tousertype(L, 1, 0);
int bit = (int)tolua_tonumber(L, 2, 0);
lua_pushboolean(tolua_S, (self->flags & (1<<bit)));
lua_pushboolean(L, (self->flags & (1<<bit)));
return 1;
}
static int tolua_region_get_adj(lua_State* tolua_S)
static int tolua_region_get_adj(lua_State* L)
{
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
direction_t dir = (direction_t)tolua_tonumber(tolua_S, 2, 0);
region* self = (region*)tolua_tousertype(L, 1, 0);
direction_t dir = (direction_t)tolua_tonumber(L, 2, 0);
tolua_pushusertype(tolua_S, (void*)r_connect(self, dir), "region");
tolua_pushusertype(L, (void*)r_connect(self, dir), "region");
return 1;
}
static int tolua_region_set_flag(lua_State* tolua_S)
static int tolua_region_set_flag(lua_State* L)
{
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
int bit = (int)tolua_tonumber(tolua_S, 2, 0);
int set = tolua_toboolean(tolua_S, 3, 0);
region* self = (region*)tolua_tousertype(L, 1, 0);
int bit = (int)tolua_tonumber(L, 2, 0);
int set = tolua_toboolean(L, 3, 0);
if (set) self->flags |= (1<<bit);
else self->flags &= ~(1<<bit);
@ -139,16 +139,16 @@ static int tolua_region_set_flag(lua_State* tolua_S)
}
static int
tolua_region_get_resourcelevel(lua_State* tolua_S)
tolua_region_get_resourcelevel(lua_State* L)
{
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
const char * type = tolua_tostring(tolua_S, 2, 0);
region * r = (region *)tolua_tousertype(L, 1, 0);
const char * type = tolua_tostring(L, 2, 0);
const resource_type * rtype = rt_find(type);
if (rtype!=NULL) {
const rawmaterial * rm;
for (rm=r->resources;rm;rm=rm->next) {
if (rm->type->rtype==rtype) {
tolua_pushnumber(tolua_S, (lua_Number)rm->level);
tolua_pushnumber(L, (lua_Number)rm->level);
return 1;
}
}
@ -157,10 +157,10 @@ tolua_region_get_resourcelevel(lua_State* tolua_S)
}
static int
tolua_region_get_resource(lua_State* tolua_S)
tolua_region_get_resource(lua_State* L)
{
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
const char * type = tolua_tostring(tolua_S, 2, 0);
region * r = (region *)tolua_tousertype(L, 1, 0);
const char * type = tolua_tostring(L, 2, 0);
const resource_type * rtype = rt_find(type);
int result = 0;
@ -174,16 +174,16 @@ tolua_region_get_resource(lua_State* tolua_S)
result = region_getresource(r, rtype);
}
tolua_pushnumber(tolua_S, (lua_Number)result);
tolua_pushnumber(L, (lua_Number)result);
return 1;
}
static int
tolua_region_set_resource(lua_State* tolua_S)
tolua_region_set_resource(lua_State* L)
{
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
const char * type = tolua_tostring(tolua_S, 2, 0);
int value = (int)tolua_tonumber(tolua_S, 3, 0);
region * r = (region *)tolua_tousertype(L, 1, 0);
const char * type = tolua_tostring(L, 2, 0);
int value = (int)tolua_tonumber(L, 3, 0);
const resource_type * rtype = rt_find(type);
if (rtype!=NULL) {
@ -207,19 +207,19 @@ tolua_region_set_resource(lua_State* tolua_S)
}
static int
tolua_region_get_objects(lua_State* tolua_S)
tolua_region_get_objects(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
region * self = (region *)tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, (void*)&self->attribs, "hashtable");
return 1;
}
static int
tolua_region_create(lua_State* tolua_S)
tolua_region_create(lua_State* L)
{
short x = (short)tolua_tonumber(tolua_S, 1, 0);
short y = (short)tolua_tonumber(tolua_S, 2, 0);
const char * tname = tolua_tostring(tolua_S, 3, 0);
short x = (short)tolua_tonumber(L, 1, 0);
short y = (short)tolua_tonumber(L, 2, 0);
const char * tname = tolua_tostring(L, 3, 0);
const terrain_type * terrain = get_terrain(tname);
region * r = findregion(x, y);
@ -241,82 +241,82 @@ tolua_region_create(lua_State* tolua_S)
}
fix_demand(result);
tolua_pushusertype(tolua_S, result, "region");
tolua_pushusertype(L, result, "region");
return 1;
}
static int tolua_region_get_units(lua_State* tolua_S)
static int tolua_region_get_units(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
region * self = (region *)tolua_tousertype(L, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
luaL_getmetatable(tolua_S, "unit");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "unit");
lua_setmetatable(L, -2);
*unit_ptr = self->units;
lua_pushcclosure(tolua_S, tolua_unitlist_next, 1);
lua_pushcclosure(L, tolua_unitlist_next, 1);
return 1;
}
static int tolua_region_get_buildings(lua_State* tolua_S)
static int tolua_region_get_buildings(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
building ** building_ptr = (building**)lua_newuserdata(tolua_S, sizeof(building *));
region * self = (region *)tolua_tousertype(L, 1, 0);
building ** building_ptr = (building**)lua_newuserdata(L, sizeof(building *));
luaL_getmetatable(tolua_S, "building");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "building");
lua_setmetatable(L, -2);
*building_ptr = self->buildings;
lua_pushcclosure(tolua_S, tolua_buildinglist_next, 1);
lua_pushcclosure(L, tolua_buildinglist_next, 1);
return 1;
}
static int tolua_region_get_ships(lua_State* tolua_S)
static int tolua_region_get_ships(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
ship ** ship_ptr = (ship**)lua_newuserdata(tolua_S, sizeof(ship *));
region * self = (region *)tolua_tousertype(L, 1, 0);
ship ** ship_ptr = (ship**)lua_newuserdata(L, sizeof(ship *));
luaL_getmetatable(tolua_S, "ship");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "ship");
lua_setmetatable(L, -2);
*ship_ptr = self->ships;
lua_pushcclosure(tolua_S, tolua_shiplist_next, 1);
lua_pushcclosure(L, tolua_shiplist_next, 1);
return 1;
}
static int tolua_region_get_age(lua_State* tolua_S)
static int tolua_region_get_age(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
region * self = (region *)tolua_tousertype(L, 1, 0);
if (self) {
lua_pushnumber(tolua_S, self->age);
lua_pushnumber(L, self->age);
return 1;
}
return 0;
}
static int
tolua_region_getkey(lua_State* tolua_S)
tolua_region_getkey(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
region * self = (region *)tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
int flag = atoi36(name);
attrib * a = find_key(self->attribs, flag);
lua_pushboolean(tolua_S, a!=NULL);
lua_pushboolean(L, a!=NULL);
return 1;
}
static int
tolua_region_setkey(lua_State* tolua_S)
tolua_region_setkey(lua_State* L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
const char * name = tolua_tostring(tolua_S, 2, 0);
int value = tolua_toboolean(tolua_S, 3, 0);
region * self = (region *)tolua_tousertype(L, 1, 0);
const char * name = tolua_tostring(L, 2, 0);
int value = tolua_toboolean(L, 3, 0);
int flag = atoi36(name);
attrib * a = find_key(self->attribs, flag);
@ -329,47 +329,47 @@ tolua_region_setkey(lua_State* tolua_S)
}
static int
tolua_region_tostring(lua_State *tolua_S)
tolua_region_tostring(lua_State *L)
{
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
lua_pushstring(tolua_S, regionname(self, NULL));
region * self = (region *)tolua_tousertype(L, 1, 0);
lua_pushstring(L, regionname(self, NULL));
return 1;
}
void
tolua_region_open(lua_State* tolua_S)
tolua_region_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "region");
tolua_usertype(L, "region");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_cclass(tolua_S, "region", "region", "", NULL);
tolua_beginmodule(tolua_S, "region");
tolua_cclass(L, "region", "region", "", NULL);
tolua_beginmodule(L, "region");
{
tolua_function(tolua_S, "create", tolua_region_create);
tolua_function(tolua_S, "__tostring", tolua_region_tostring);
tolua_function(L, "create", tolua_region_create);
tolua_function(L, "__tostring", tolua_region_tostring);
tolua_variable(tolua_S, "id", tolua_region_get_id, NULL);
tolua_variable(tolua_S, "x", tolua_region_get_x, NULL);
tolua_variable(tolua_S, "y", tolua_region_get_y, NULL);
tolua_variable(tolua_S, "name", tolua_region_get_name, tolua_region_set_name);
tolua_variable(tolua_S, "info", tolua_region_get_info, tolua_region_set_info);
tolua_variable(tolua_S, "units", tolua_region_get_units, NULL);
tolua_variable(tolua_S, "ships", tolua_region_get_ships, NULL);
tolua_variable(tolua_S, "age", tolua_region_get_age, NULL);
tolua_variable(tolua_S, "buildings", tolua_region_get_buildings, NULL);
tolua_variable(tolua_S, "terrain", tolua_region_get_terrain, NULL);
tolua_function(tolua_S, "get_resourcelevel", tolua_region_get_resourcelevel);
tolua_function(tolua_S, "get_resource", tolua_region_get_resource);
tolua_function(tolua_S, "set_resource", tolua_region_set_resource);
tolua_function(tolua_S, "get_flag", tolua_region_get_flag);
tolua_function(tolua_S, "set_flag", tolua_region_set_flag);
tolua_function(tolua_S, "next", tolua_region_get_adj);
tolua_variable(L, "id", tolua_region_get_id, NULL);
tolua_variable(L, "x", tolua_region_get_x, NULL);
tolua_variable(L, "y", tolua_region_get_y, NULL);
tolua_variable(L, "name", tolua_region_get_name, tolua_region_set_name);
tolua_variable(L, "info", tolua_region_get_info, tolua_region_set_info);
tolua_variable(L, "units", tolua_region_get_units, NULL);
tolua_variable(L, "ships", tolua_region_get_ships, NULL);
tolua_variable(L, "age", tolua_region_get_age, NULL);
tolua_variable(L, "buildings", tolua_region_get_buildings, NULL);
tolua_variable(L, "terrain", tolua_region_get_terrain, NULL);
tolua_function(L, "get_resourcelevel", tolua_region_get_resourcelevel);
tolua_function(L, "get_resource", tolua_region_get_resource);
tolua_function(L, "set_resource", tolua_region_set_resource);
tolua_function(L, "get_flag", tolua_region_get_flag);
tolua_function(L, "set_flag", tolua_region_set_flag);
tolua_function(L, "next", tolua_region_get_adj);
tolua_function(tolua_S, "get_key", tolua_region_getkey);
tolua_function(tolua_S, "set_key", tolua_region_setkey);
tolua_function(L, "get_key", tolua_region_getkey);
tolua_function(L, "set_key", tolua_region_setkey);
#if 0
.property("owner", &lua_region_getowner, &lua_region_setowner)
.property("herbtype", &region_getherbtype, &region_setherbtype)
@ -383,9 +383,9 @@ tolua_region_open(lua_State* tolua_S)
.property("items", &region_items, return_stl_iterator)
.property("plane_id", &region_plane)
#endif
tolua_variable(tolua_S, "objects", tolua_region_get_objects, 0);
tolua_variable(L, "objects", tolua_region_get_objects, 0);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -15,8 +15,8 @@ extern "C" {
#endif
struct lua_State;
void tolua_region_open(struct lua_State *tolua_S);
int tolua_regionlist_next(struct lua_State *tolua_S);
void tolua_region_open(struct lua_State *L);
int tolua_regionlist_next(struct lua_State *L);
#ifdef __cplusplus
}

View file

@ -24,12 +24,12 @@ without prior permission by the authors of Eressea.
#include <lua.h>
#include <tolua.h>
int tolua_shiplist_next(lua_State *tolua_S)
int tolua_shiplist_next(lua_State *L)
{
ship** ship_ptr = (ship **)lua_touserdata(tolua_S, lua_upvalueindex(1));
ship** ship_ptr = (ship **)lua_touserdata(L, lua_upvalueindex(1));
ship * u = *ship_ptr;
if (u != NULL) {
tolua_pushusertype(tolua_S, (void*)u, "ship");
tolua_pushusertype(L, (void*)u, "ship");
*ship_ptr = u->next;
return 1;
}
@ -37,83 +37,83 @@ int tolua_shiplist_next(lua_State *tolua_S)
}
static int
tolua_ship_get_id(lua_State* tolua_S)
tolua_ship_get_id(lua_State* L)
{
ship * self = (ship *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushnumber(tolua_S, (lua_Number)self->no);
ship * self = (ship *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number)self->no);
return 1;
}
static int tolua_ship_get_name(lua_State* tolua_S)
static int tolua_ship_get_name(lua_State* L)
{
ship* self = (ship*) tolua_tousertype(tolua_S, 1, 0);
tolua_pushstring(tolua_S, ship_getname(self));
ship* self = (ship*) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, ship_getname(self));
return 1;
}
static int tolua_ship_get_region(lua_State* tolua_S)
static int tolua_ship_get_region(lua_State* L)
{
ship* self = (ship*) tolua_tousertype(tolua_S, 1, 0);
ship* self = (ship*) tolua_tousertype(L, 1, 0);
if (self) {
tolua_pushusertype(tolua_S, self->region, "region");
tolua_pushusertype(L, self->region, "region");
return 1;
}
return 0;
}
static int tolua_ship_set_region(lua_State* tolua_S)
static int tolua_ship_set_region(lua_State* L)
{
ship* self = (ship*) tolua_tousertype(tolua_S, 1, 0);
region * r = (region*) tolua_tousertype(tolua_S, 1, 0);
ship* self = (ship*) tolua_tousertype(L, 1, 0);
region * r = (region*) tolua_tousertype(L, 1, 0);
if (self) {
move_ship(self, self->region, r, NULL);
}
return 0;
}
static int tolua_ship_set_name(lua_State* tolua_S)
static int tolua_ship_set_name(lua_State* L)
{
ship* self = (ship*)tolua_tousertype(tolua_S, 1, 0);
ship_setname(self, tolua_tostring(tolua_S, 2, 0));
ship* self = (ship*)tolua_tousertype(L, 1, 0);
ship_setname(self, tolua_tostring(L, 2, 0));
return 0;
}
static int
tolua_ship_get_units(lua_State* tolua_S)
tolua_ship_get_units(lua_State* L)
{
ship * self = (ship *)tolua_tousertype(tolua_S, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
ship * self = (ship *)tolua_tousertype(L, 1, 0);
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
unit * u = self->region->units;
while (u && u->ship!=self) u = u->next;
luaL_getmetatable(tolua_S, "unit");
lua_setmetatable(tolua_S, -2);
luaL_getmetatable(L, "unit");
lua_setmetatable(L, -2);
*unit_ptr = u;
lua_pushcclosure(tolua_S, tolua_unitlist_nexts, 1);
lua_pushcclosure(L, tolua_unitlist_nexts, 1);
return 1;
}
static int
tolua_ship_get_objects(lua_State* tolua_S)
tolua_ship_get_objects(lua_State* L)
{
ship * self = (ship *)tolua_tousertype(tolua_S, 1, 0);
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
ship * self = (ship *)tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, (void*)&self->attribs, "hashtable");
return 1;
}
static int
tolua_ship_create(lua_State* tolua_S)
tolua_ship_create(lua_State* L)
{
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
const char * sname = tolua_tostring(tolua_S, 2, 0);
region * r = (region *)tolua_tousertype(L, 1, 0);
const char * sname = tolua_tostring(L, 2, 0);
if (sname) {
const ship_type * stype = st_find(sname);
if (stype) {
ship * sh = new_ship(stype, NULL, r);
sh->size = stype->construction->maxsize;
tolua_pushusertype(tolua_S, (void*)sh, "ship");
tolua_pushusertype(L, (void*)sh, "ship");
return 1;
}
}
@ -121,30 +121,31 @@ tolua_ship_create(lua_State* tolua_S)
}
static int
tolua_ship_tostring(lua_State *tolua_S)
tolua_ship_tostring(lua_State *L)
{
ship * self = (ship *)tolua_tousertype(tolua_S, 1, 0);
lua_pushstring(tolua_S, shipname(self));
ship * self = (ship *)tolua_tousertype(L, 1, 0);
lua_pushstring(L, shipname(self));
return 1;
}
void
tolua_ship_open(lua_State* tolua_S)
tolua_ship_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "ship");
tolua_usertype(L, "ship");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_cclass(tolua_S, "ship", "ship", "", NULL);
tolua_beginmodule(tolua_S, "ship");
tolua_cclass(L, "ship", "ship", "", NULL);
tolua_beginmodule(L, "ship");
{
tolua_function(tolua_S, "__tostring", tolua_ship_tostring);
tolua_variable(tolua_S, "id", tolua_ship_get_id, NULL);
tolua_variable(tolua_S, "name", tolua_ship_get_name, tolua_ship_set_name);
tolua_variable(tolua_S, "units", tolua_ship_get_units, NULL);
tolua_variable(tolua_S, "region", tolua_ship_get_region, tolua_ship_set_region);
tolua_function(L, "__tostring", tolua_ship_tostring);
tolua_variable(L, "id", tolua_ship_get_id, NULL);
tolua_variable(L, "name", tolua_ship_get_name, tolua_ship_set_name);
tolua_variable(L, "units", tolua_ship_get_units, NULL);
tolua_variable(L, "region", tolua_ship_get_region, tolua_ship_set_region);
#ifdef TODO
.property("type", &ship_gettype)
.property("weight", &ship_getweight)
@ -155,11 +156,11 @@ tolua_ship_open(lua_State* tolua_S)
.def_readwrite("size", &ship::size)
.def_readwrite("coast", &ship::coast)
#endif
tolua_variable(tolua_S, "objects", tolua_ship_get_objects, 0);
tolua_variable(L, "objects", tolua_ship_get_objects, 0);
tolua_function(tolua_S, "create", tolua_ship_create);
tolua_function(L, "create", tolua_ship_create);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -15,8 +15,8 @@ extern "C" {
#endif
struct lua_State;
int tolua_shiplist_next(struct lua_State *tolua_S);
void tolua_ship_open(struct lua_State *tolua_S);
int tolua_shiplist_next(struct lua_State *L);
void tolua_ship_open(struct lua_State *L);
#ifdef __cplusplus
}

View file

@ -25,10 +25,10 @@ without prior permission by the authors of Eressea.
static int
tolua_storage_create(lua_State* tolua_S)
tolua_storage_create(lua_State* L)
{
const char * filename = tolua_tostring(tolua_S, 1, 0);
const char * type = tolua_tostring(tolua_S, 2, "rb");
const char * filename = tolua_tostring(L, 1, 0);
const char * type = tolua_tostring(L, 2, "rb");
storage * store = 0;
int mode = IO_READ;
if (strchr(type, 't')) {
@ -41,53 +41,53 @@ tolua_storage_create(lua_State* tolua_S)
if (strchr(type, 'r')) mode = IO_READ;
if (strchr(type, 'w')) mode = IO_WRITE;
store->open(store, filename, mode);
tolua_pushusertype(tolua_S, (void*)store, "storage");
tolua_pushusertype(L, (void*)store, "storage");
return 1;
}
static int
tolua_storage_read_unit(lua_State *tolua_S)
tolua_storage_read_unit(lua_State *L)
{
storage * self = (storage *)tolua_tousertype(tolua_S, 1, 0);
storage * self = (storage *)tolua_tousertype(L, 1, 0);
struct unit * u = read_unit(self);
tolua_pushusertype(tolua_S, (void*)u, "unit");
tolua_pushusertype(L, (void*)u, "unit");
return 1;
}
static int
tolua_storage_write_unit(lua_State *tolua_S)
tolua_storage_write_unit(lua_State *L)
{
storage * self = (storage *)tolua_tousertype(tolua_S, 1, 0);
struct unit * u = (struct unit *)tolua_tousertype(tolua_S, 2, 0);
storage * self = (storage *)tolua_tousertype(L, 1, 0);
struct unit * u = (struct unit *)tolua_tousertype(L, 2, 0);
write_unit(self, u);
return 0;
}
static int
tolua_storage_read_float(lua_State *tolua_S)
tolua_storage_read_float(lua_State *L)
{
storage * self = (storage *)tolua_tousertype(tolua_S, 1, 0);
storage * self = (storage *)tolua_tousertype(L, 1, 0);
float num = self->r_flt(self);
tolua_pushnumber(tolua_S, (lua_Number)num);
tolua_pushnumber(L, (lua_Number)num);
return 1;
}
static int
tolua_storage_read_int(lua_State *tolua_S)
tolua_storage_read_int(lua_State *L)
{
storage * self = (storage *)tolua_tousertype(tolua_S, 1, 0);
storage * self = (storage *)tolua_tousertype(L, 1, 0);
int num = self->r_int(self);
tolua_pushnumber(tolua_S, (lua_Number)num);
tolua_pushnumber(L, (lua_Number)num);
return 1;
}
static int
tolua_storage_write(lua_State *tolua_S)
tolua_storage_write(lua_State *L)
{
storage * self = (storage *)tolua_tousertype(tolua_S, 1, 0);
if (tolua_isnumber(tolua_S, 2, 0, 0)) {
lua_Number num = tolua_tonumber(tolua_S, 2, 0);
storage * self = (storage *)tolua_tousertype(L, 1, 0);
if (tolua_isnumber(L, 2, 0, 0)) {
lua_Number num = tolua_tonumber(L, 2, 0);
double n;
if (modf(num, &n)==0.0) {
self->w_int(self, (int)num);
@ -99,45 +99,45 @@ tolua_storage_write(lua_State *tolua_S)
}
static int
tolua_storage_tostring(lua_State *tolua_S)
tolua_storage_tostring(lua_State *L)
{
storage * self = (storage *)tolua_tousertype(tolua_S, 1, 0);
storage * self = (storage *)tolua_tousertype(L, 1, 0);
char name[64];
snprintf(name, sizeof(name), "<storage enc=%d ver=%d>", self->encoding, self->version);
lua_pushstring(tolua_S, name);
lua_pushstring(L, name);
return 1;
}
static int
tolua_storage_close(lua_State *tolua_S)
tolua_storage_close(lua_State *L)
{
storage * self = (storage *)tolua_tousertype(tolua_S, 1, 0);
storage * self = (storage *)tolua_tousertype(L, 1, 0);
self->close(self);
return 0;
}
void
tolua_storage_open(lua_State* tolua_S)
tolua_storage_open(lua_State* L)
{
/* register user types */
tolua_usertype(tolua_S, "storage");
tolua_usertype(L, "storage");
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);
{
tolua_cclass(tolua_S, "storage", "storage", "", NULL);
tolua_beginmodule(tolua_S, "storage");
tolua_cclass(L, "storage", "storage", "", NULL);
tolua_beginmodule(L, "storage");
{
tolua_function(tolua_S, "__tostring", tolua_storage_tostring);
tolua_function(tolua_S, "write", tolua_storage_write);
tolua_function(tolua_S, "read_int", tolua_storage_read_int);
tolua_function(tolua_S, "read_float", tolua_storage_read_float);
tolua_function(tolua_S, "write_unit", tolua_storage_write_unit);
tolua_function(tolua_S, "read_unit", tolua_storage_read_unit);
tolua_function(tolua_S, "close", tolua_storage_close);
tolua_function(tolua_S, "create", tolua_storage_create);
tolua_function(L, "__tostring", tolua_storage_tostring);
tolua_function(L, "write", tolua_storage_write);
tolua_function(L, "read_int", tolua_storage_read_int);
tolua_function(L, "read_float", tolua_storage_read_float);
tolua_function(L, "write_unit", tolua_storage_write_unit);
tolua_function(L, "read_unit", tolua_storage_read_unit);
tolua_function(L, "close", tolua_storage_close);
tolua_function(L, "create", tolua_storage_create);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}
tolua_endmodule(tolua_S);
tolua_endmodule(L);
}

View file

@ -15,7 +15,7 @@ extern "C" {
#endif
struct lua_State;
void tolua_storage_open(struct lua_State *tolua_S);
void tolua_storage_open(struct lua_State *L);
#ifdef __cplusplus
}

File diff suppressed because it is too large Load diff

View file

@ -15,11 +15,11 @@ extern "C" {
#endif
struct lua_State;
int tolua_unitlist_nextb(struct lua_State *tolua_S);
int tolua_unitlist_nexts(struct lua_State *tolua_S);
int tolua_unitlist_nextf(struct lua_State *tolua_S);
int tolua_unitlist_next(struct lua_State *tolua_S);
void tolua_unit_open(struct lua_State *tolua_S);
int tolua_unitlist_nextb(struct lua_State *L);
int tolua_unitlist_nexts(struct lua_State *L);
int tolua_unitlist_nextf(struct lua_State *L);
int tolua_unitlist_next(struct lua_State *L);
void tolua_unit_open(struct lua_State *L);
#ifdef __cplusplus
}

File diff suppressed because it is too large Load diff

View file

@ -15,10 +15,10 @@ extern "C" {
#endif
struct lua_State;
int tolua_eressea_open(struct lua_State* tolua_S);
int tolua_spelllist_next(struct lua_State *tolua_S);
int tolua_itemlist_next(struct lua_State *tolua_S);
int tolua_orderlist_next(struct lua_State *tolua_S);
int tolua_eressea_open(struct lua_State* L);
int tolua_spelllist_next(struct lua_State *L);
int tolua_itemlist_next(struct lua_State *L);
int tolua_orderlist_next(struct lua_State *L);
#ifdef __cplusplus
}

View file

@ -530,14 +530,14 @@ lua_recruit(struct unit * u, const struct archetype * arch, int amount)
}
int
tolua_toid(lua_State* tolua_S, int idx, int def)
tolua_toid(lua_State* L, int idx, int def)
{
int no = 0;
int type = lua_type(tolua_S, idx);
int type = lua_type(L, idx);
if (type==LUA_TNUMBER) {
no = (int)tolua_tonumber(tolua_S, idx, def);
no = (int)tolua_tonumber(L, idx, def);
} else {
const char * str = tolua_tostring(tolua_S, idx, NULL);
const char * str = tolua_tostring(L, idx, NULL);
no = str?atoi36(str):def;
}
return no;

View file

@ -15,7 +15,7 @@ extern "C" {
#endif
void register_tolua_helpers(void);
int tolua_toid(struct lua_State* tolua_S, int idx, int def);
int tolua_toid(struct lua_State* L, int idx, int def);
#ifdef __cplusplus
}