Lua initializer.
More...
#include <luainterface.h>
|
| | LuaInterface () |
| | Create Lua instance. More...
|
| |
| | ~LuaInterface () |
| |
| void | initLua () |
| | Read and execute Lua files. More...
|
| |
| bool | luaConnect (QObject *sender, std::string signalName, LuaIntf::LuaRef slot) |
| | Connect Qt signal with Lua function. More...
|
| |
| bool | qtConnect (QObject *sender, std::string signalName, QObject *receiver, std::string slotName) |
| | Connect Qt signal with Qt slot. More...
|
| |
| void | cleanInvalidQObject () |
| | Remove all connections that aren't valid anymore. More...
|
| |
| std::vector< std::string > | pluginList (const char *path) |
| | Return a list of plugins. More...
|
| |
| void | hideUI (bool hidden) |
| | Hide the window. It needs to be used before initLua(), this is used in unit tests. More...
|
| |
| LuaIntf::LuaState | luaState () |
| | Returns current Lua state. This is used for unit tests. More...
|
| |
| LuaIntf::LuaRef | operation (unsigned int windowID) |
| |
| void | setOperation (unsigned int windowID, LuaIntf::LuaRef) |
| |
| void | registerEvent (const std::string &event, LuaIntf::LuaRef callback) |
| |
| void | deleteEvent (const std::string &event, LuaIntf::LuaRef callback) |
| |
| void | triggerEvent (const std::string &event, LuaIntf::LuaRef args) |
| |
|
| static std::shared_ptr< QWidget > | loadUiFile (const char *fileName) |
| | Load Qt widget from .ui file. More...
|
| |
| static FILE * | openFileDialog (bool isOpening, const char *description, const char *mode) |
| |
Lua initializer.
Definition at line 29 of file luainterface.h.
| LuaInterface::LuaInterface |
( |
| ) |
|
Create Lua instance.
Definition at line 5 of file luainterface.cpp.
6 _L(LuaIntf::LuaState::newState()),
lc::PluginManager _pluginManager
| LuaInterface::~LuaInterface |
( |
| ) |
|
Definition at line 10 of file luainterface.cpp.
15 lc::LuaCustomEntityManager::getInstance().removePlugins();
std::vector< LuaQObject_SPtr > _luaQObjects
std::map< unsigned int, LuaIntf::LuaRef > _operations
std::map< std::string, std::vector< LuaIntf::LuaRef > > _events
| void LuaInterface::cleanInvalidQObject |
( |
| ) |
|
Remove all connections that aren't valid anymore.
Definition at line 77 of file luainterface.cpp.
80 [](LuaQObject_SPtr lqo){
std::vector< LuaQObject_SPtr > _luaQObjects
| void LuaInterface::deleteEvent |
( |
const std::string & |
event, |
|
|
LuaIntf::LuaRef |
callback |
|
) |
| |
Definition at line 157 of file luainterface.cpp.
158 auto it = std::find(
_events[event].begin(),
_events[event].end(), callback);
160 if(it !=
_events[event].end()) {
std::map< std::string, std::vector< LuaIntf::LuaRef > > _events
| void LuaInterface::hideUI |
( |
bool |
hidden | ) |
|
Hide the window. It needs to be used before initLua(), this is used in unit tests.
Definition at line 100 of file luainterface.cpp.
101 LuaIntf::Lua::setGlobal(
_L,
"hideUI", hidden);
| void LuaInterface::initLua |
( |
| ) |
|
Read and execute Lua files.
Definition at line 20 of file luainterface.cpp.
21 auto lcLua = lc::LCLua(
_L);
24 lcLua.importLCKernel();
28 LuaIntf::Lua::setGlobal(
_L,
"luaInterface",
this);
30 QString luaFile = QCoreApplication::applicationDirPath() +
"/path.lua";
31 int s =
_L.doFile(luaFile.toStdString().c_str());
34 std::cout << lua_tostring(
_L, -1) << std::endl;
lc::PluginManager _pluginManager
static FILE * openFileDialog(bool isOpening, const char *description, const char *mode)
void luaOpenQtBridge(lua_State *L)
| std::shared_ptr< QWidget > LuaInterface::loadUiFile |
( |
const char * |
fileName | ) |
|
|
static |
Load Qt widget from .ui file.
- Parameters
-
| fileName | full path to .ui file |
Definition at line 65 of file luainterface.cpp.
68 file.open(QFile::ReadOnly);
70 std::shared_ptr<QWidget> widget(uiLoader.load(&file));
| bool LuaInterface::luaConnect |
( |
QObject * |
sender, |
|
|
std::string |
signalName, |
|
|
LuaIntf::LuaRef |
slot |
|
) |
| |
Connect Qt signal with Lua function.
- Parameters
-
| sender | Pointer to sender object |
| signalName | Name of the signal with parameters |
| slot | Lua function |
- Returns
- true if connected, false if an error happened
Definition at line 41 of file luainterface.cpp.
46 int signalId = sender->metaObject()->indexOfSignal(signalName.c_str());
49 std::cout <<
"No such signal " << signalName << std::endl;
52 auto lqo = std::make_shared<LuaQObject>(sender);
55 auto connected = lqo->connect(signalId, slot);
void cleanInvalidQObject()
Remove all connections that aren't valid anymore.
std::vector< LuaQObject_SPtr > _luaQObjects
| LuaIntf::LuaState LuaInterface::luaState |
( |
| ) |
|
Returns current Lua state. This is used for unit tests.
Definition at line 104 of file luainterface.cpp.
| FILE * LuaInterface::openFileDialog |
( |
bool |
isOpening, |
|
|
const char * |
description, |
|
|
const char * |
mode |
|
) |
| |
|
static |
Definition at line 120 of file luainterface.cpp.
124 path = QFileDialog::getOpenFileName(
nullptr, (std::string(
"Open ") + description).c_str());
127 path = QFileDialog::getSaveFileName(
nullptr, (std::string(
"Save ") + description).c_str());
134 return fopen(path.toStdString().c_str(), mode);
| LuaIntf::LuaRef LuaInterface::operation |
( |
unsigned int |
windowID | ) |
|
Definition at line 137 of file luainterface.cpp.
142 return LuaIntf::LuaRef();
std::map< unsigned int, LuaIntf::LuaRef > _operations
| std::vector< std::string > LuaInterface::pluginList |
( |
const char * |
path | ) |
|
Return a list of plugins.
- Parameters
-
- Returns
- List of strings containing the name of plugins
Definition at line 108 of file luainterface.cpp.
109 std::vector<std::string> plugins;
112 auto list = dir.entryList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot);
113 for(
auto dir : list) {
114 plugins.push_back(dir.toStdString());
| bool LuaInterface::qtConnect |
( |
QObject * |
sender, |
|
|
std::string |
signalName, |
|
|
QObject * |
receiver, |
|
|
std::string |
slotName |
|
) |
| |
Connect Qt signal with Qt slot.
- Parameters
-
| sender | Pointer to sender object |
| signalName | Name of the signal with parameters |
| receiver | Pointer to receiver object |
| slotName | Name of the slot with parameters |
Definition at line 86 of file luainterface.cpp.
87 int signalId = sender->metaObject()->indexOfSignal(signalName.c_str());
89 std::cout <<
"No such signal " << signalName << std::endl;
92 int slotId = receiver->metaObject()->indexOfSlot(slotName.c_str());
94 std::cout <<
"No such slot " << slotName << std::endl;
97 return QMetaObject::connect(sender, signalId, receiver, slotId);
| void LuaInterface::registerEvent |
( |
const std::string & |
event, |
|
|
LuaIntf::LuaRef |
callback |
|
) |
| |
Definition at line 149 of file luainterface.cpp.
150 if(callback.isTable() && !callback.has(
"onEvent")) {
154 _events[event].push_back(callback);
std::map< std::string, std::vector< LuaIntf::LuaRef > > _events
| void LuaInterface::setOperation |
( |
unsigned int |
windowID, |
|
|
LuaIntf::LuaRef |
operation |
|
) |
| |
Definition at line 145 of file luainterface.cpp.
LuaIntf::LuaRef operation(unsigned int windowID)
std::map< unsigned int, LuaIntf::LuaRef > _operations
| void LuaInterface::triggerEvent |
( |
const std::string & |
event, |
|
|
LuaIntf::LuaRef |
args |
|
) |
| |
Definition at line 165 of file luainterface.cpp.
167 for(
auto eventCallback : events) {
168 if(eventCallback.isFunction()) {
169 eventCallback(event, args);
171 else if(eventCallback.isTable()) {
172 eventCallback.get(
"onEvent").call(eventCallback, event, args);
std::map< std::string, std::vector< LuaIntf::LuaRef > > _events
| std::map<std::string, std::vector<LuaIntf::LuaRef> > LuaInterface::_events |
|
private |
| LuaIntf::LuaState LuaInterface::_L |
|
private |
| std::vector<LuaQObject_SPtr> LuaInterface::_luaQObjects |
|
private |
| std::map<unsigned int, LuaIntf::LuaRef> LuaInterface::_operations |
|
private |
| lc::PluginManager LuaInterface::_pluginManager |
|
private |
The documentation for this class was generated from the following files: