34 SL_SYMBOL
Runtime(
const std::string& filename);
47 template<
typename... Libraries>
59 const std::string& table_name,
60 const std::string& func_name,
61 SL::Function function);
96 template<
typename... Return,
typename... Args>
97 inline Result<std::tuple<Return...>>
99 const std::string& name,
102 SL_SYMBOL
bool good()
const;
103 SL_SYMBOL
operator bool()
const;
106 const auto& filename()
const {
return _filename; }
109 SL_SYMBOL
void _pop(std::size_t n = 1)
const;
110 SL_SYMBOL
int _call_func(uint32_t args, uint32_t ret)
const;
114 std::string _filename;
116# ifdef LUA_HOT_RELOAD
117 std::filesystem::file_time_type _last_modified;
121 template<
typename... Libraries>
124 using namespace Util::CompileTime;
128 static_for<
sizeof...(Libraries)>([&](
auto n)
130 const std::size_t i = n;
131 using Library = NthType<i, Libraries...>;
132 static_assert(std::is_base_of_v<SL::Lib::Base, Library>);
133 Library().registerFunctions(runtime);
139 template<
typename... Return,
typename... Args>
142 const std::string& name,
149 if (glob_res.error().code() == Runtime::ErrorCode::TypeMismatch)
return { Runtime::ErrorCode::NotFunction };
150 else return { glob_res.error() };
153 auto args_set = std::tuple(std::forward<Args>(args)...);
154 Util::CompileTime::static_for<
sizeof...(args)>([&](
auto n){
155 constexpr std::size_t I = n;
156 using Type = std::remove_reference_t<Util::CompileTime::NthType<I, Args...>>;
163 auto left =
sizeof...(Return);
164 auto return_vals = std::tuple<Return...>();
165 Util::CompileTime::static_for<
sizeof...(Return)>([&](
auto n) {
166 constexpr std::size_t I = n;
167 using Type = Util::CompileTime::NthType<I, Return...>;
174 std::get<I>(return_vals) = Map::construct(L);
181 SL_ASSERT(!left,
"Still arguments left.");
185 return { ErrorCode::TypeMismatch };
188 return { std::move(return_vals) };
Definition TypeMap.hpp:19
Represents a single Lua runtime.
Definition Runtime.hpp:17
Result< std::tuple< Return... > > runFunction(const std::string &name, Args &&... args)
Invokes a Lua function from this environment.
Definition Runtime.hpp:141
static Runtime create(const std::string &filename)
Creates a runtime with the given Libraries loaded into it.
Definition Runtime.hpp:122
SL_SYMBOL Runtime(const std::string &filename)
Construct a Lua runtime from a script.
SL_SYMBOL Result< void > registerFunction(const std::string &table_name, const std::string &func_name, SL::Function function)
Registers a C++ function for use in the Lua runtime.
SL_SYMBOL Result< void > setGlobal(const std::string &name, const T &value)
Set a global variable from a value to a name.
SL_SYMBOL Result< T > getGlobal(const std::string &name)
Get a global variable by name from runtime.
Basic way to return a value or an error.
Definition Result.hpp:37