33 #include <boost/variant/static_visitor.hpp>
45 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
46 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
56 #pragma warning (push)
57 #pragma warning (disable: 4706)
60 ,
int nArgs,
int nRets,
bool allow_wml_error)
69 int error_handler_index =
lua_gettop(L) - nArgs - 1;
83 if (allow_wml_error && strncmp(m,
"~wml:", 5) == 0) {
85 char const *
e = strstr(m,
"stack traceback");
87 }
else if (allow_wml_error && strncmp(m,
"~lua:", 5) == 0) {
89 char const *
e =
nullptr, *em =
m;
90 while (em[0] && ((em = strstr(em + 1,
"stack traceback"))))
119 if (
ptr)
return ptr.get();
125 if (!ui.
valid())
return nullptr;
146 ptr->set_location(loc);
151 uid = res.first->underlying_id();
153 ERR_LUA <<
"Could not move unit " <<
ptr->underlying_id() <<
" onto map location " << loc <<
'\n';
157 unit_ptr it = (*resources::teams)[
side - 1].recall_list().extract_if_matches_underlying_id(
uid);
163 ERR_LUA <<
"Could not find unit " <<
uid <<
" on recall list of side " <<
side <<
'\n';
176 ERR_LUA <<
"Could not find unit " <<
uid <<
" on the map" << std::endl;
187 if (only_on_map && !lu->
on_map())
return nullptr;
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
bool luaW_pcall(lua_State *L, int nArgs, int nRets, bool allow_wml_error)
Calls a Lua function stored below its nArgs arguments at the top of the stack.
LUA_API int lua_gettop(lua_State *L)
static lg::log_domain log_scripting_lua("scripting/lua")
unit_ptr luaW_checkunit_ptr(lua_State *L, int index, bool only_on_map)
luatypekey const getunitKey
Definitions for the interface to Wesnoth Markup Language (WML).
LUA_API void * lua_newuserdata(lua_State *L, size_t size)
unit * luaW_tounit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
lua_unit * luaW_pushlocalunit(lua_State *L, unit &u)
#define lua_pcall(L, n, r, f)
std::vector< team > * teams
pointer get_shared_ptr() const
std::pair< unit_iterator, bool > insert(unit_ptr p)
Adds the unit to the map.
unit & luaW_checkunit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
LUA_API int lua_setmetatable(lua_State *L, int objindex)
LUA_API void lua_remove(lua_State *L, int idx)
std::pair< unit_iterator, bool > replace(const map_location &l, const unit &u)
Works like unit_map::add; but l is emptied first, if needed.
Encapsulates the map of the game.
Storage for a unit, either owned by the Lua code (ptr != 0), a local variable unit (c_ptr != 0)...
luatypekey const executeKey
LUA_API void * lua_touserdata(lua_State *L, int idx)
bool luaW_hasmetatable(lua_State *L, int index, luatypekey key)
Returns true if the metatable of the object is the one found in the registry.
static void rethrow()
Rethrows the stored exception.
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
#define lua_tostring(L, i)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
unit_ptr luaW_tounit_ptr(lua_State *L, int index, bool only_on_map)
Similar to luaW_checkunit/luaW_tounit but returns a unit_ptr, use this instead of luaW_checkunit/luaW...
LUA_API void lua_insert(lua_State *L, int idx)
std::pair< unit_iterator, bool > move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
size_t erase(const map_location &l)
Erases the unit at location l, if any.
display_chat_manager & get_chat_manager()
#define LUA_REGISTRYINDEX
boost::intrusive_ptr< unit > unit_ptr
bool put_map(const map_location &loc)
Standard logging facilities (interface).
unit_iterator find(size_t id)
void chat_message(std::string const &caption, std::string const &msg)
Displays a message in the chat window.
void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *tname)
LUA_API void lua_rawget(lua_State *L, int idx)
GLsizei const GLcharARB ** string