2 #include <managers/luacustomentitymanager.h>
6 _L(
LuaIntf::LuaState::newState()),
7 _pluginManager(_L,
"gui") {
15 lc::LuaCustomEntityManager::getInstance().removePlugins();
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;
43 std::string signalName,
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);
68 file.open(QFile::ReadOnly);
70 std::shared_ptr<QWidget> widget(uiLoader.load(&file));
80 [](LuaQObject_SPtr lqo){
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);
101 LuaIntf::Lua::setGlobal(
_L,
"hideUI", hidden);
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());
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);
142 return LuaIntf::LuaRef();
150 if(callback.isTable() && !callback.has(
"onEvent")) {
154 _events[event].push_back(callback);
158 auto it = std::find(
_events[event].begin(),
_events[event].end(), callback);
160 if(it !=
_events[event].end()) {
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);
lc::PluginManager _pluginManager
static FILE * openFileDialog(bool isOpening, const char *description, const char *mode)
void luaOpenQtBridge(lua_State *L)
static std::shared_ptr< QWidget > loadUiFile(const char *fileName)
Load Qt widget from .ui file.
LuaIntf::LuaRef operation(unsigned int windowID)
void cleanInvalidQObject()
Remove all connections that aren't valid anymore.
LuaIntf::LuaState luaState()
Returns current Lua state. This is used for unit tests.
bool luaConnect(QObject *sender, std::string signalName, LuaIntf::LuaRef slot)
Connect Qt signal with Lua function.
LuaInterface()
Create Lua instance.
std::vector< LuaQObject_SPtr > _luaQObjects
void triggerEvent(const std::string &event, LuaIntf::LuaRef args)
bool qtConnect(QObject *sender, std::string signalName, QObject *receiver, std::string slotName)
Connect Qt signal with Qt slot.
void setOperation(unsigned int windowID, LuaIntf::LuaRef)
void initLua()
Read and execute Lua files.
void registerEvent(const std::string &event, LuaIntf::LuaRef callback)
std::map< unsigned int, LuaIntf::LuaRef > _operations
void deleteEvent(const std::string &event, LuaIntf::LuaRef callback)
std::map< std::string, std::vector< LuaIntf::LuaRef > > _events
std::vector< std::string > pluginList(const char *path)
Return a list of plugins.
void hideUI(bool hidden)
Hide the window. It needs to be used before initLua(), this is used in unit tests.