summaryrefslogtreecommitdiff
path: root/src/luacxx.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/luacxx.hpp')
-rw-r--r--src/luacxx.hpp47
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