5#include <aegis2d/script/export.hpp>
55 static constexpr std::uint32_t default_instruction_limit = 10'000'000;
57 static constexpr std::size_t default_memory_limit = std::size_t{64} * 1024 * 1024;
75 bool run(std::string_view code, std::string_view chunk =
"script");
80 bool run_file(
const std::filesystem::path& file);
85 bool call(std::string_view function);
91 bool call(std::string_view function,
double argument);
96 [[nodiscard]]
bool has(std::string_view name)
const;
101 [[nodiscard]] std::optional<double>
number(std::string_view name)
const;
106 [[nodiscard]] std::optional<std::string>
text(std::string_view name)
const;
111 [[nodiscard]] std::optional<bool>
boolean(std::string_view name)
const;
126 void set_memory_limit(
std::
size_t bytes) noexcept;
130 [[nodiscard]]
std::
size_t memory_limit() const noexcept;
137 void clear_error() noexcept;
140 friend struct ScriptAccess;
142 std::unique_ptr<Impl> impl_;
A Lua state for the game's scripts, sandboxed.
Definition state.hpp:52
bool call(std::string_view function)
Calls a global function without arguments.
~ScriptState()
Closes the state.
ScriptState(const ScriptState &)=delete
void set_instruction_limit(std::uint32_t instructions) noexcept
Sets the instructions a run or a call may take.
std::optional< double > number(std::string_view name) const
A global number.
ScriptState & operator=(ScriptState &&other) noexcept
Takes over the state of other, left without one.
bool run_file(const std::filesystem::path &file)
Runs a Lua file.
std::optional< bool > boolean(std::string_view name) const
A global boolean.
ScriptState()
Opens a sandboxed state.
std::optional< std::string > text(std::string_view name) const
A global string.
std::uint32_t instruction_limit() const noexcept
Instructions a run or a call may take.
bool run(std::string_view code, std::string_view chunk="script")
Runs Lua code.
ScriptState(ScriptState &&other) noexcept
Takes over the state of other, left without one.
bool call(std::string_view function, double argument)
Calls a global function with a number, such as the seconds of a tick.
ScriptState & operator=(const ScriptState &)=delete
bool has(std::string_view name) const
Tells whether a global is set (not nil).
Entity behaviors in Lua, so that new enemies and patterns need no recompilation.
Definition components.hpp:19
AEGIS2D_SCRIPT_EXPORT std::string to_string(const ScriptError &error)
Formats an error as a log line shows it.
Definition endpoint.hpp:85
Where and why a script failed.
Definition state.hpp:18
std::string message
What went wrong, without the chunk and the line.
Definition state.hpp:24
int line
Line of the error in the chunk, or 0 when Lua does not tell it.
Definition state.hpp:22
std::string chunk
Name of the chunk: the file, or the name given to ScriptState::run().
Definition state.hpp:20