forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.h
More file actions
51 lines (43 loc) · 1.28 KB
/
Script.h
File metadata and controls
51 lines (43 loc) · 1.28 KB
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
48
49
50
51
#pragma once
#include "FunctionTrait.h"
#ifdef _WIN32
#include "lua.hpp"
#else
#include "lua5.3/lua.hpp"
#endif
#include <string>
#include <array>
#include <type_traits>
class Script
{
public:
Script();
~Script();
lua_State* lua_state_ = nullptr;
static Script* getInstance()
{
static Script s;
return &s;
}
int runScript(const std::string& filename);
int registerEventFunctions();
template <typename F, typename C, std::size_t... I, std::size_t N>
static auto runner_impl(F f, C* c, const std::array<int, N>& e, std::index_sequence<I...>)
{
return (c->*f)(e[I]...);
}
template <typename F, typename C, std::size_t N>
static typename std::enable_if<check_return_type<F, C, void>::value, int>::type
runner(F f, C* c, const std::array<int, N>& e, lua_State* L)
{
runner_impl(f, c, e, std::make_index_sequence<arg_counter<F, C>::value> {});
return 0;
}
template <typename F, typename C, std::size_t N>
static typename std::enable_if<check_return_type<F, C, bool>::value, int>::type
runner(F f, C* c, const std::array<int, N>& e, lua_State* L)
{
lua_pushboolean(L, runner_impl(f, c, e, std::make_index_sequence<arg_counter<F, C>::value> {}));
return 1;
}
};