Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/LuaContext.h
3185 views
1
#pragma once
2
3
#include <string_view>
4
#include <string>
5
#include <memory>
6
7
#include "ext/sol/forward.hpp"
8
9
struct lua_State;
10
11
enum class LogLineType {
12
Cmd,
13
String,
14
Integer,
15
Error,
16
External,
17
Url,
18
};
19
20
// A bit richer than regular log lines, so we can display them in color, and allow various UI tricks.
21
// All have a string, but some may also have a number or other value.
22
struct LuaLogLine {
23
LogLineType type;
24
std::string line;
25
int number;
26
};
27
28
class LuaContext {
29
public:
30
void Init();
31
void Shutdown();
32
33
const std::vector<LuaLogLine> GetLines() const {
34
return lines_;
35
}
36
void Clear() { lines_.clear(); }
37
38
void Print(LogLineType type, std::string_view text);
39
void Print(std::string_view text) {
40
Print(LogLineType::External, text);
41
}
42
43
// For the console.
44
void ExecuteConsoleCommand(std::string_view cmd);
45
46
private:
47
std::unique_ptr<sol::state> lua_;
48
std::vector<LuaLogLine> lines_;
49
};
50
51
extern LuaContext g_lua;
52
53