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 <<
"\".";