31 #define LOG_LUA LOG_STREAM(info, log_ai_engine_lua)
32 #define ERR_LUA LOG_STREAM(err, log_ai_engine_lua)
42 : val_(
"Lua Function")
49 ref_ = luaL_ref(L, LUA_REGISTRYINDEX);
61 luaL_unref(
L_, LUA_REGISTRYINDEX,
ref_);
70 return std::vector<std::string>();
73 const std::string& unit_id = (*unit).id();
74 const int unit_x = (*unit).get_location().wml_x();
75 const int unit_y = (*unit).get_location().wml_y();
77 LOG_LUA <<
"Entering unit_advancements_aspect::get_advancements() in instance " <<
this <<
" with unit " << unit_id <<
" on (x,y) = (" << unit_x <<
", " << unit_y <<
")";
79 if(
L_ ==
nullptr ||
ref_ == LUA_REFNIL)
83 if (
val_ ==
"Lua Function")
85 return std::vector<std::string>();
91 lua_rawgeti(
L_, LUA_REGISTRYINDEX,
ref_);
93 if(lua_isstring(
L_, -1))
98 if(!lua_isfunction(
L_, -1))
100 ERR_LUA <<
"Can't evaluate advancement aspect: Value is neither a string nor a function.";
101 return std::vector<std::string>();
105 lua_pushinteger(
L_, unit_x);
106 lua_pushinteger(
L_, unit_y);
112 if(lua_pcall(
L_, 2, 1, 0) != 0)
114 ERR_LUA <<
"LUA Error while evaluating advancements_aspect: " << lua_tostring(
L_, -1);
115 return std::vector<std::string>();
117 if (!lua_isstring(
L_, -1))
119 ERR_LUA <<
"LUA Error while evaluating advancements_aspect: Function must return String ";
120 return std::vector<std::string>();
124 const std::string
retval = std::string(lua_tostring(
L_, -1));
127 LOG_LUA <<
"Called Lua advancement function. Result was: \"" <<
retval <<
"\".";
static lg::log_domain log_ai_engine_lua("ai/engine/lua")
const std::vector< std::string > get_advancements(const unit_map::const_iterator &unit) const
const std::string get_value() const
virtual ~unit_advancements_aspect()
unit_advancements_aspect()
This class represents a single unit of a specific type.
Standard logging facilities (interface).
A small explanation about what's going on here: Each action has access to two game_info objects First...
retval
Default window/dialog return values.
std::vector< std::string > split(const config_attribute_value &val)
static map_location::direction n