forked from github/server
passing order object into lua use-functions, so we can use them in error messages.
This commit is contained in:
parent
14afee6093
commit
e1f3b3cdcf
5 changed files with 34 additions and 2 deletions
|
@ -6,7 +6,7 @@ local function get_direction(locale, token)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function use_snowglobe(u, amount, token)
|
function use_snowglobe(u, amount, token, ord)
|
||||||
local transform = {
|
local transform = {
|
||||||
ocean = "glacier",
|
ocean = "glacier",
|
||||||
firewall = "volcano",
|
firewall = "volcano",
|
||||||
|
|
|
@ -139,6 +139,7 @@ set(SERVER_SRC
|
||||||
bind_eressea.c
|
bind_eressea.c
|
||||||
bind_faction.c
|
bind_faction.c
|
||||||
bind_dict.c
|
bind_dict.c
|
||||||
|
bind_order.c
|
||||||
bindings.c
|
bindings.c
|
||||||
bind_message.c
|
bind_message.c
|
||||||
bind_monsters.c
|
bind_monsters.c
|
||||||
|
|
|
@ -81,6 +81,23 @@ static int msg_set_resource(lua_message * msg, const char *param, const char *re
|
||||||
return E_INVALID_MESSAGE;
|
return E_INVALID_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int msg_set_order(lua_message * msg, const char *param, struct order *ord)
|
||||||
|
{
|
||||||
|
if (msg->mtype) {
|
||||||
|
int i = mtype_get_param(msg->mtype, param);
|
||||||
|
if (i == msg->mtype->nparameters) {
|
||||||
|
return E_INVALID_PARAMETER_NAME;
|
||||||
|
}
|
||||||
|
if (strcmp(msg->mtype->types[i]->name, "order") != 0) {
|
||||||
|
return E_INVALID_PARAMETER_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg->args[i].v = (void *)ord;
|
||||||
|
return E_OK;
|
||||||
|
}
|
||||||
|
return E_INVALID_MESSAGE;
|
||||||
|
}
|
||||||
|
|
||||||
static int msg_set_unit(lua_message * msg, const char *param, const unit * u)
|
static int msg_set_unit(lua_message * msg, const char *param, const unit * u)
|
||||||
{
|
{
|
||||||
if (msg->mtype) {
|
if (msg->mtype) {
|
||||||
|
@ -223,6 +240,16 @@ static int tolua_msg_set_resource(lua_State * L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int tolua_msg_set_order(lua_State * L)
|
||||||
|
{
|
||||||
|
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||||
|
const char *param = tolua_tostring(L, 2, 0);
|
||||||
|
struct order *value = (struct order *)tolua_tousertype(L, 3, 0);
|
||||||
|
int result = msg_set_order(lmsg, param, value);
|
||||||
|
lua_pushinteger(L, result);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int tolua_msg_set_unit(lua_State * L)
|
static int tolua_msg_set_unit(lua_State * L)
|
||||||
{
|
{
|
||||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||||
|
@ -326,6 +353,7 @@ void tolua_message_open(lua_State * L)
|
||||||
tolua_function(L, TOLUA_CAST "render", tolua_msg_render);
|
tolua_function(L, TOLUA_CAST "render", tolua_msg_render);
|
||||||
tolua_function(L, TOLUA_CAST "set", tolua_msg_set);
|
tolua_function(L, TOLUA_CAST "set", tolua_msg_set);
|
||||||
tolua_function(L, TOLUA_CAST "set_unit", tolua_msg_set_unit);
|
tolua_function(L, TOLUA_CAST "set_unit", tolua_msg_set_unit);
|
||||||
|
tolua_function(L, TOLUA_CAST "set_order", tolua_msg_set_order);
|
||||||
tolua_function(L, TOLUA_CAST "set_region", tolua_msg_set_region);
|
tolua_function(L, TOLUA_CAST "set_region", tolua_msg_set_region);
|
||||||
tolua_function(L, TOLUA_CAST "set_resource", tolua_msg_set_resource);
|
tolua_function(L, TOLUA_CAST "set_resource", tolua_msg_set_resource);
|
||||||
tolua_function(L, TOLUA_CAST "set_int", tolua_msg_set_int);
|
tolua_function(L, TOLUA_CAST "set_int", tolua_msg_set_int);
|
||||||
|
|
|
@ -19,6 +19,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include "bind_message.h"
|
#include "bind_message.h"
|
||||||
#include "bind_building.h"
|
#include "bind_building.h"
|
||||||
#include "bind_faction.h"
|
#include "bind_faction.h"
|
||||||
|
#include "bind_order.h"
|
||||||
#include "bind_ship.h"
|
#include "bind_ship.h"
|
||||||
#include "bind_gmtool.h"
|
#include "bind_gmtool.h"
|
||||||
#include "bind_region.h"
|
#include "bind_region.h"
|
||||||
|
@ -1157,6 +1158,7 @@ lua_State *lua_init(void) {
|
||||||
tolua_faction_open(L);
|
tolua_faction_open(L);
|
||||||
tolua_unit_open(L);
|
tolua_unit_open(L);
|
||||||
tolua_message_open(L);
|
tolua_message_open(L);
|
||||||
|
tolua_order_open(L);
|
||||||
tolua_dict_open(L);
|
tolua_dict_open(L);
|
||||||
#ifdef USE_CURSES
|
#ifdef USE_CURSES
|
||||||
tolua_gmtool_open(L);
|
tolua_gmtool_open(L);
|
||||||
|
|
|
@ -511,7 +511,8 @@ struct order *ord)
|
||||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||||
lua_pushinteger(L, amount);
|
lua_pushinteger(L, amount);
|
||||||
lua_pushstring(L, getstrtoken());
|
lua_pushstring(L, getstrtoken());
|
||||||
if (lua_pcall(L, 3, 1, 0) != 0) {
|
tolua_pushusertype(L, (void *)ord, TOLUA_CAST "order");
|
||||||
|
if (lua_pcall(L, 4, 1, 0) != 0) {
|
||||||
const char *error = lua_tostring(L, -1);
|
const char *error = lua_tostring(L, -1);
|
||||||
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
Loading…
Reference in a new issue