-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathluaengine.h
More file actions
82 lines (69 loc) · 2.1 KB
/
Copy pathluaengine.h
File metadata and controls
82 lines (69 loc) · 2.1 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef LUAENGINE_H
#define LUAENGINE_H
#include "Lua/lua.hpp"
#include "luaevent.h"
#include "luathread.h"
#include <QList>
#include <QMediaPlayer>
#include <QObject>
#include <QThread>
#define gL (LuaEngine::Instance())
class LuaKVModel;
class LuaEngine : public QObject
{
Q_OBJECT
public:
explicit LuaEngine(QObject *parent = 0);
static LuaEngine *Instance();
QThread *runLuaThread(QString filename);
int hasEvent() { return this->m_events.isEmpty() ? 0 : 1; }
int isRunning() { return this->m_lua_thread != NULL && this->m_lua_thread->isRunning(); }
LuaEvent popEvent()
{
LuaEvent res(this->m_events.first());
this->m_events.pop_front();
return res;
}
void putEvent(LuaEvent &event) { this->m_events.push_back(event); }
void triggerEvent(LuaEvent &event);
void triggerPushMsg(int type, const char *msg);
void triggerAddMsgType(const char *name);
void triggerLuaScriptError(const char *msg);
void triggerSetKV(const char *key, const char *value, const char *color);
void triggerToClipboard(const char *text);
void triggerPlayMedia(const char *file);
void triggerStopMedia();
void stopScript();
void pauseScript();
void resumeScript();
int getNextMsgTypeCount();
signals:
void GetLuaEvent(LuaEvent event);
void LuaStateChange(QString scriptname, bool isRunning);
void PushMsg(int type, QString msg);
void AddMsgType(QString name);
void LuaScriptError(QString msg);
void SetKVEvent(QString key, QString value, QString color);
void ToClipboradEvent(QString text);
void PlayMediaEvent(QString file);
void StopMediaEvent();
private:
QList<LuaEvent> m_events;
lua_State *newLuaThread();
void closeLuaThread()
{
lua_close(this->m_L);
this->m_L = NULL;
}
int m_msg_type_count;
QMediaPlayer m_player;
lua_State *m_L;
LuaThread *m_lua_thread;
QString m_script_name;
public slots:
void onLuaThreadFinished();
void onToClipborad(QString text);
void onPlayMedia(QString file);
void onStopMedia();
};
#endif // LUAENGINE_H