4#include "tz/core/error.hpp"
123 std::expected<bool, tz::error_code>
lua_get_bool(std::string_view varname);
130 std::expected<std::int64_t, tz::error_code>
lua_get_int(std::string_view varname);
144 std::expected<std::string, tz::error_code>
lua_get_string(std::string_view varname);
222 template<
int F,
int L>
225 template<
typename Functor>
226 static inline constexpr void apply(
const Functor& f)
230 f(std::integral_constant<int, F>{});
231 static_for_t<F + 1, L>::apply(f);
235 template<
typename Functor>
236 inline constexpr void operator()(
const Functor& f)
const
243 struct static_for_t<N, N>
245 template<
typename Functor>
246 static inline constexpr void apply([[maybe_unused]]
const Functor& f){}
249 template<
int F,
int L>
250 inline constexpr static_for_t<F, L> static_for = {};
258 template<
typename... Ts>
261 std::tuple<Ts...> ret;
262 static_for<0,
sizeof...(Ts)>([&ret]([[maybe_unused]]
auto i)
constexpr
264 using T = std::decay_t<
decltype(std::get<i.value>(std::declval<std::tuple<Ts...>>()))>;
265 auto& v = std::get<i.value>(ret);
266 if constexpr(std::is_same_v<T, bool>)
270 else if constexpr(std::is_same_v<T, float> || std::is_same_v<T, double>)
274 else if constexpr(std::is_same_v<T, std::int64_t> || std::is_same_v<T, int>)
278 else if constexpr(std::is_same_v<T, std::string>)
282 else if constexpr(std::is_same_v<T, lua_nil>)
288 static_assert(std::is_void_v<T>,
"Unrecognised lua argument type. Is it a supported type?");
std::expected< std::string, tz::error_code > lua_stack_get_string(std::size_t id)
Retrieve a string from the stack at the given index.
int(*)() lua_fn
Represents the signature for a function that can be called from lua.
Definition lua.hpp:43
void lua_push_number(double v)
Push a number value onto the stack.
void lua_push_nil()
Push a nil value onto the stack.
std::string lua_debug_stack()
Retreieve a string describing the entire lua stack right now.
std::expected< bool, tz::error_code > lua_stack_get_bool(std::size_t id)
Retrieve a bool from the stack at the given index.
std::expected< std::string, tz::error_code > lua_get_string(std::string_view varname)
Retrieve the value of a string variable.
std::expected< std::int64_t, tz::error_code > lua_stack_get_int(std::size_t id)
Retrieve a int from the stack at the given index.
tz::error_code lua_execute_file(std::filesystem::path path)
Attempt to execute a local lua file on the current thread.
void lua_push_string(std::string v)
Push a string value onto the stack.
tz::error_code lua_set_emptytable(std::string_view varname)
Set a variable in lua to be the empty table "{}".
void lua_push_bool(bool v)
Push a bool value onto the stack.
tz::error_code lua_define_function(std::string_view varname, lua_fn fn)
Define a new function in lua.
tz::error_code lua_set_number(std::string_view varname, double v)
Set a variable in lua to a new number value.
std::expected< double, tz::error_code > lua_stack_get_number(std::size_t id)
Retrieve a number from the stack at the given index.
std::expected< bool, tz::error_code > lua_get_bool(std::string_view varname)
Retrieve the value of a bool variable.
tz::error_code lua_set_string(std::string_view varname, std::string str)
Set a variable in lua to a new string value.
std::expected< double, tz::error_code > lua_get_number(std::string_view varname)
Retrieve the value of a number variable.
std::size_t lua_stack_size()
Retrieve the number of values on the stack currently.
std::tuple< Ts... > lua_parse_args()
Retreve a set of arguments from the stack.
Definition lua.hpp:259
tz::error_code lua_execute(std::string_view lua_src)
Attempt to execute some lua code on the current thread.
std::expected< std::int64_t, tz::error_code > lua_get_int(std::string_view varname)
Retrieve the value of a int variable.
tz::error_code lua_set_bool(std::string_view varname, bool v)
Set a variable in lua to a new bool value.
tz::error_code lua_set_int(std::string_view varname, std::int64_t v)
Set a variable in lua to a new int value.
std::string lua_debug_callstack()
Retreieve a string describing the lua callstack right now.
tz::error_code lua_set_nil(std::string_view varname)
Set a variable in lua to be nil.
void lua_push_int(std::int64_t v)
Push an int value onto the stack.
error_code
Error codes for Topaz.
Definition error.hpp:14
#define tz_must(fnret)
Cause a runtime error if the expected value is erroneous. If not, the unwrapped expected value is ret...
Definition debug.hpp:66