38 #define ERR_OBJ_LUA LOG_STREAM(err, log_scripting_lua)
48 virtual void store(lua_State* L,
int n) = 0;
69 std::shared_ptr<T>
get()
87 std::shared_ptr<T>
to_type(lua_State *,
int)
89 return std::shared_ptr<T>();
95 lua_pushliteral(L,
"Unsupported AI aspect type for Lua!");
105 return std::make_shared<double>(lua_tonumber(L,
n));
111 if(value) lua_pushnumber(L, *value);
118 return std::make_shared<std::string>(lua_tostring(L,
n));
129 lua_pushboolean(L, v);
131 lua_createtable(L, v.size(), 0);
132 for(
const std::string& str : v) {
133 lua_pushlstring(L, str.c_str(), str.size());
134 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
139 }
else lua_pushnil(L);
145 if (lua_isboolean(L,
n)) {
146 return std::make_shared<utils::variant<bool, std::vector<std::string>>>(
luaW_toboolean(L,
n));
148 auto v = std::make_shared<std::vector<std::string>>();
149 int l = lua_rawlen(L,
n);
150 for (
int i = 1;
i < l + 1; ++
i)
152 lua_pushinteger(L,
i);
154 std::string
s = lua_tostring(L, -1);
159 return std::make_shared<utils::variant<bool, std::vector<std::string>>>(*v);
166 if(value) lua_pushlstring(L, value->c_str(), value->size());
179 if(value) lua_pushboolean(L, *value);
186 return std::make_shared<int>(
static_cast<int>(lua_tointeger(L,
n)));
192 if(value) lua_pushnumber(L, *value);
199 auto v = std::make_shared<std::vector<std::string>>();
200 int l = lua_rawlen(L,
n);
201 for (
int i = 1;
i < l + 1; ++
i)
203 lua_pushinteger(L,
i);
205 std::string
s = lua_tostring(L, -1);
217 lua_createtable(L, value->size(), 0);
218 for(
const std::string& str : *value) {
219 lua_pushlstring(L, str.c_str(), str.size());
220 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
222 }
else lua_pushnil(L);
228 auto cfg = std::make_shared<config>();
243 auto cfg = std::make_shared<config>();
244 auto vcfg = std::make_shared<vconfig>(*cfg);
246 cfg->add_child(
"not");
256 std::set<map_location> locs;
257 value->get_locations(locs);
258 lua_createtable(L, locs.size(), 0);
261 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
263 }
else lua_pushnil(L);
269 auto targets = std::make_shared<std::vector<target>>();
270 int l = lua_rawlen(L,
n);
272 for (
int i = 1;
i <= l; ++
i)
274 lua_rawgeti(L,
n,
i);
276 lua_pushstring(L,
"loc");
279 lua_pushstring(L,
"x");
281 int x =
static_cast<int>(lua_tointeger(L, -1));
284 lua_pushstring(L,
"y");
286 int y =
static_cast<int>(lua_tointeger(L, -1));
290 lua_pushstring(L,
"type");
292 utils::optional<ai_target::type>
type = ai_target::type::xplicit;
293 if(lua_isnumber(L, -1)) {
294 int target =
static_cast<int>(lua_tointeger(L, -1));
297 ERR_OBJ_LUA <<
"Failed to convert ai target type of " <<
target <<
", skipping.";
300 }
else if(lua_isstring(L, -1)) {
301 std::string
target = lua_tostring(L, -1);
304 ERR_OBJ_LUA <<
"Failed to convert ai target type of " <<
target <<
", skipping.";
310 lua_pushstring(L,
"value");
312 int value =
static_cast<int>(lua_tointeger(L, -1));
316 targets->emplace_back(ml, value, *
type);
326 return std::make_shared<unit_advancements_aspect>(L,
n);
virtual void store(lua_State *L, int n)=0
virtual ~lua_object_base()
void store(lua_State *L, int n)
void from_type(lua_State *L, std::shared_ptr< T >)
lua_object(const T &init)
std::shared_ptr< T > to_type(lua_State *, int)
std::shared_ptr< T > get()
std::shared_ptr< T > value_
Definitions for the interface to Wesnoth Markup Language (WML).
Standard logging facilities (interface).
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
void luaW_pushlocation(lua_State *L, const map_location &ml)
Converts a map location object to a Lua table pushed at the top of the stack.
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.
bool luaW_toboolean(lua_State *L, int n)
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
static lg::log_domain log_scripting_lua("scripting/lua")
A small explanation about what's going on here: Each action has access to two game_info objects First...
filter_context * filter_con
struct utils::detail::formula_initer init
constexpr bool decayed_is_same
Equivalent to as std::is_same_v except both types are passed through std::decay first.
Encapsulates the map of the game.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
static map_location::direction n
static map_location::direction s