39 #define ERR_OBJ_LUA LOG_STREAM(err, log_scripting_lua)
49 virtual void store(lua_State* L,
int n) = 0;
70 std::shared_ptr<T>
get()
88 std::shared_ptr<T>
to_type(lua_State *,
int)
90 return std::shared_ptr<T>();
96 lua_pushliteral(L,
"Unsupported AI aspect type for Lua!");
106 return std::make_shared<double>(lua_tonumber(L,
n));
112 if(value) lua_pushnumber(L, *value);
119 return std::make_shared<std::string>(lua_tostring(L,
n));
130 lua_pushboolean(L, v);
132 lua_createtable(L, v.size(), 0);
133 for(
const std::string& str : v) {
134 lua_pushlstring(L, str.c_str(), str.size());
135 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
140 }
else lua_pushnil(L);
146 if (lua_isboolean(L,
n)) {
147 return std::make_shared<utils::variant<bool, std::vector<std::string>>>(
luaW_toboolean(L,
n));
149 auto v = std::make_shared<std::vector<std::string>>();
150 int l = lua_rawlen(L,
n);
151 for (
int i = 1;
i < l + 1; ++
i)
153 lua_pushinteger(L,
i);
155 std::string
s = lua_tostring(L, -1);
160 return std::make_shared<utils::variant<bool, std::vector<std::string>>>(*v);
167 if(value) lua_pushlstring(L, value->c_str(), value->size());
180 if(value) lua_pushboolean(L, *value);
187 return std::make_shared<int>(
static_cast<int>(lua_tointeger(L,
n)));
193 if(value) lua_pushnumber(L, *value);
200 auto v = std::make_shared<std::vector<std::string>>();
201 int l = lua_rawlen(L,
n);
202 for (
int i = 1;
i < l + 1; ++
i)
204 lua_pushinteger(L,
i);
206 std::string
s = lua_tostring(L, -1);
218 lua_createtable(L, value->size(), 0);
219 for(
const std::string& str : *value) {
220 lua_pushlstring(L, str.c_str(), str.size());
221 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
223 }
else lua_pushnil(L);
229 auto cfg = std::make_shared<config>();
244 auto cfg = std::make_shared<config>();
245 auto vcfg = std::make_shared<vconfig>(*cfg);
247 cfg->add_child(
"not");
257 std::set<map_location> locs;
258 value->get_locations(locs);
259 lua_createtable(L, locs.size(), 0);
262 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
264 }
else lua_pushnil(L);
270 auto targets = std::make_shared<std::vector<target>>();
271 int l = lua_rawlen(L,
n);
273 for (
int i = 1;
i <= l; ++
i)
275 lua_rawgeti(L,
n,
i);
277 lua_pushstring(L,
"loc");
280 lua_pushstring(L,
"x");
282 int x =
static_cast<int>(lua_tointeger(L, -1));
285 lua_pushstring(L,
"y");
287 int y =
static_cast<int>(lua_tointeger(L, -1));
291 lua_pushstring(L,
"type");
293 std::optional<ai_target::type>
type = ai_target::type::xplicit;
294 if(lua_isnumber(L, -1)) {
295 int target =
static_cast<int>(lua_tointeger(L, -1));
298 ERR_OBJ_LUA <<
"Failed to convert ai target type of " <<
target <<
", skipping.";
301 }
else if(lua_isstring(L, -1)) {
302 std::string
target = lua_tostring(L, -1);
305 ERR_OBJ_LUA <<
"Failed to convert ai target type of " <<
target <<
", skipping.";
311 lua_pushstring(L,
"value");
313 int value =
static_cast<int>(lua_tointeger(L, -1));
317 targets->emplace_back(ml, value, *
type);
327 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_
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 std::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