diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-09-30 00:36:19 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-09-30 00:36:19 -0500 |
commit | 6f2b61b676a16482fdac70a58a8e875c4d68e713 (patch) | |
tree | e2f8b2376847b5b13b278572c0fae8a6bc4d0e82 /src/luacxx.hpp | |
parent | dacd752bbf46f2afb08b4b8d730ba3619528dda4 (diff) |
Add configuration handling.
Diffstat (limited to 'src/luacxx.hpp')
-rw-r--r-- | src/luacxx.hpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/luacxx.hpp b/src/luacxx.hpp new file mode 100644 index 0000000..388f640 --- /dev/null +++ b/src/luacxx.hpp @@ -0,0 +1,47 @@ +#ifndef LUA_CXX_HPP +#define LUA_CXX_HPP + +extern "C" { +#include <lua.h> +} +#include <fud_status.hpp> +#include <fud_result.hpp> + +#include <cstdint> +#include <string> +#include <vector> + +namespace getsuyomi { + +template<typename T> +using LuaResult = fud::Result<T, fud::FudStatus>; + +static_assert(std::is_convertible_v<lua_Integer, int64_t>); + +class LuaContext { +public: + LuaContext(); + ~LuaContext(); + LuaContext(const LuaContext&) = delete; + LuaContext(LuaContext&& rhs); + LuaContext& operator=(const LuaContext&) = delete; + LuaContext& operator=(LuaContext&& rhs); + + fud::FudStatus loadFile(const char* filename); + + LuaResult<int64_t> getGlobalInteger(const char* name); + LuaResult<const char*> getGlobalString(const char* name); + LuaResult<std::vector<std::string>> getGlobalStringArray(const char* name); + + [[nodiscard]] constexpr bool valid() const { + return m_state != nullptr; + } + +private: + lua_State *m_state{nullptr}; +}; + +} // namespace getsuyomi + + +#endif |