summaryrefslogtreecommitdiff
path: root/src/luacxx.hpp
blob: fb7c1b9d6c7fc71442b0caa3a53bbbbc1bbe1af8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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) noexcept;
    LuaContext& operator=(const LuaContext&) = delete;
    LuaContext& operator=(LuaContext&& rhs) noexcept;

    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