├── modules ├── mocreader │ ├── build │ │ ├── msvc2012 │ │ │ └── mocreader │ │ │ │ ├── .gitignore │ │ │ │ ├── GeneratedFiles │ │ │ │ └── .gitignore │ │ │ │ ├── mocreader.sln │ │ │ │ └── mocreader.vcxproj.filters │ │ └── mocreader │ │ │ └── mocreader.pro │ ├── src │ │ ├── mocparser.cpp │ │ ├── mocparser.h │ │ ├── mocreader.h │ │ ├── mocreader_global.h │ │ ├── parser.cpp │ │ ├── preprocessor.h │ │ ├── utils.h │ │ ├── parser.h │ │ ├── token.h │ │ ├── symbols.h │ │ └── qmetaobject_moc_p.h │ ├── COPYRIGHT.md │ └── LGPL_EXCEPTION.txt ├── uic │ ├── COPYRIGHT.md │ ├── LGPL_EXCEPTION.txt │ ├── build │ │ └── uic │ │ │ └── uic.pro │ └── src │ │ ├── lua │ │ ├── luawritedeclaration.h │ │ ├── luawriteincludes.h │ │ ├── luawritedeclaration.cpp │ │ └── luawriteincludes.cpp │ │ ├── main.cpp │ │ ├── globaldefs.h │ │ ├── validator.h │ │ ├── databaseinfo.h │ │ ├── validator.cpp │ │ ├── customwidgetsinfo.h │ │ ├── databaseinfo.cpp │ │ ├── option.h │ │ ├── customwidgetsinfo.cpp │ │ ├── uic.h │ │ ├── driver.h │ │ ├── treewalker.h │ │ └── utils.h ├── path │ ├── path │ │ ├── impl_posix.lua │ │ └── impl_win.lua │ └── path.lua └── luaqtml │ └── luaqtml.lua ├── .gitignore ├── tools ├── codegen │ └── template │ │ ├── constructorext_noext.cpp │ │ ├── method.cpp │ │ ├── constructor.cpp │ │ ├── staticmethod.cpp │ │ ├── constructorext.cpp │ │ ├── package.pri │ │ ├── caster.cpp │ │ ├── extendedimplol.cpp │ │ ├── constructorol.cpp │ │ ├── constructorextol.cpp │ │ ├── staticmethodol.cpp │ │ ├── methodol.cpp │ │ ├── signalimpl.cpp │ │ ├── extendedimpl.cpp │ │ ├── package.cpp │ │ └── class.cpp └── mocparser │ └── main.lua ├── test └── testwidget │ ├── loginwindow │ ├── main.lua │ ├── LoginWindow.lua │ └── ui_LoginWindow.lua │ ├── loginwindow1 │ ├── main.lua │ ├── LoginWindow.lua │ └── loginwindow.ui │ ├── loginwindow-ml │ ├── main.lua │ ├── LoginWindow.lua │ └── loginwindow.ui │ └── simple │ └── main.lua ├── msvcbuild.cmd ├── README.md ├── src ├── LuaQt │ ├── globalstate.cpp │ ├── argrefframe.cpp │ ├── metafunctions.cpp │ ├── weakref.cpp │ ├── objectlifecycle.cpp │ └── luaqt.cpp └── QtCore │ └── signal.cpp ├── COPYRIGHT.md └── include └── LuaQT ├── callback.hpp ├── luaqt.hpp ├── globals.hpp └── fix.hpp /modules/mocreader/build/msvc2012/mocreader/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug 2 | /Release 3 | /Win32 4 | -------------------------------------------------------------------------------- /modules/mocreader/build/msvc2012/mocreader/GeneratedFiles/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug 2 | /Release 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.opensdf 2 | *.sdf 3 | *.suo 4 | *.user 5 | Debug 6 | Release 7 | 8 | /gen 9 | 10 | /bin 11 | /make 12 | /tmp 13 | -------------------------------------------------------------------------------- /tools/codegen/template/constructorext_noext.cpp: -------------------------------------------------------------------------------- 1 | static int /*%return name%*/(lua_State *L) 2 | { 3 | return luaL_error(L, "Cannot extend this class."); 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tools/codegen/template/method.cpp: -------------------------------------------------------------------------------- 1 | static int /*%return name%*/(lua_State *L) 2 | { 3 | /*% return overloads()%*/ 4 | 5 | return luaL_error(L, "No valid overload found."); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tools/codegen/template/constructor.cpp: -------------------------------------------------------------------------------- 1 | static int /*%return name%*/(lua_State *L) 2 | { 3 | /*% return overloads()%*/ 4 | 5 | return luaL_error(L, "No valid overload found."); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tools/codegen/template/staticmethod.cpp: -------------------------------------------------------------------------------- 1 | static int /*%return name%*/(lua_State *L) 2 | { 3 | /*% return overloads()%*/ 4 | 5 | return luaL_error(L, "No valid overload found."); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tools/codegen/template/constructorext.cpp: -------------------------------------------------------------------------------- 1 | static int /*%return name%*/(lua_State *L) 2 | { 3 | /*% return overloads()%*/ 4 | 5 | return luaL_error(L, "No valid overload found."); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow/main.lua: -------------------------------------------------------------------------------- 1 | require 'QtWidgets' 2 | 3 | local LoginWindow = require("LoginWindow") 4 | 5 | local app = QApplication.new(select('#',...) + 1, {'lua', ...}) 6 | 7 | local wnd = LoginWindow.new() 8 | wnd:show() 9 | 10 | QApplication.exec() 11 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow1/main.lua: -------------------------------------------------------------------------------- 1 | require 'QtWidgets' 2 | 3 | local LoginWindow = require("LoginWindow") 4 | 5 | local app = QApplication.new(select('#',...) + 1, {'lua', ...}) 6 | 7 | local wnd = LoginWindow.new() 8 | wnd:show() 9 | 10 | QApplication.exec() 11 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow-ml/main.lua: -------------------------------------------------------------------------------- 1 | require 'QtWidgets' 2 | require 'luaqtml' 3 | 4 | local LoginWindow = requireQtModule("LoginWindow").LoginWindow 5 | 6 | local app = QApplication.new(select('#',...) + 1, {'lua', ...}) 7 | 8 | local wnd = LoginWindow.new() 9 | wnd:show() 10 | 11 | QApplication.exec() 12 | -------------------------------------------------------------------------------- /tools/codegen/template/package.pri: -------------------------------------------------------------------------------- 1 | 2 | SOURCES += ../../../gen//*%return packageName%*///*%return packageName%*/.cpp 3 | /*% 4 | local ret = {} 5 | for i,v in ipairs(classes) do 6 | table.insert(ret, string.format("SOURCES += ../../../gen/%s/def%s.cpp\n", packageName, v)) 7 | end 8 | return table.concat(ret) 9 | %*/ 10 | -------------------------------------------------------------------------------- /test/testwidget/simple/main.lua: -------------------------------------------------------------------------------- 1 | require 'QtWidgets' 2 | 3 | local app = QApplication.new(select('#',...) + 1, {'lua', ...}) 4 | 5 | local wnd = QWidget.new() 6 | 7 | local btn = QPushButton.new("Click me", wnd) 8 | 9 | btn:connect("2clicked()", function () 10 | print("Oow..") 11 | end) 12 | 13 | wnd:show() 14 | 15 | QApplication.exec() 16 | -------------------------------------------------------------------------------- /tools/codegen/template/caster.cpp: -------------------------------------------------------------------------------- 1 | int /*%return table.concat(route, '_')%*/(lua_State *L) 2 | { 3 | CLASS* obj1 = (CLASS*)LuaQt::checkObject(L, 1, CLASS_NAME); 4 | /*% 5 | local ret = {} 6 | for i = 2, #route do 7 | table.insert(ret, string.format("\t%s* obj%d=obj%d;\n", route[i], i, i-1)) 8 | end 9 | return table.concat(ret) 10 | %*/ 11 | lua_pushlightuserdata(L, obj/*%return #route%*/); 12 | return 1; 13 | } -------------------------------------------------------------------------------- /tools/codegen/template/extendedimplol.cpp: -------------------------------------------------------------------------------- 1 | explicit /*%return class.classname%*/_Extended_Impl(const QMetaObject * _mo 2 | /*% 3 | local ret = {} 4 | for i,v in ipairs(func.arguments) do 5 | table.insert(ret, ",") 6 | table.insert(ret, v.type.rawName) 7 | table.insert(ret, "arg"..i) 8 | end 9 | return table.concat(ret, " ") 10 | %*/) 11 | : mo(_mo), /*%return class.classname%*/(/*% 12 | local ret = {} 13 | for i = 1, #func.arguments do 14 | table.insert(ret, "arg"..i) 15 | end 16 | return table.concat(ret, ", ") 17 | %*/) 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /tools/codegen/template/constructorol.cpp: -------------------------------------------------------------------------------- 1 | for (;;) 2 | { 3 | CHECK_ARG_COUNT(/*%return #arguments%*/); 4 | 5 | /*% 6 | local ret = "" 7 | for i,v in ipairs(arguments) do 8 | ret = ret .. string.format(" CHECK_ARG((%s), %d);\n", v.normalizedType, i) 9 | end 10 | return ret 11 | %*/ 12 | START_ARGREF_FRAME(); 13 | /*% 14 | local ret = "" 15 | for i,v in ipairs(arguments) do 16 | ret = ret .. string.format(" GET_ARG((%s), %d, arg%d);\n", v.normalizedType, i, i) 17 | end 18 | return ret 19 | %*/ 20 | CLASS* obj = new CLASS(/*% 21 | local ret = "" 22 | for i,v in ipairs(arguments) do 23 | ret = ret .. string.format("arg%d, ", i) 24 | end 25 | return ret:sub(1, -3) 26 | %*/); 27 | 28 | LuaQt::InitAndPushObject(L, obj, obj, CLASS_NAME); 29 | 30 | END_ARGREF_FRAME(); 31 | 32 | return 1; 33 | } -------------------------------------------------------------------------------- /test/testwidget/loginwindow/LoginWindow.lua: -------------------------------------------------------------------------------- 1 | local LuaQtHelper = require("LuaQtHelper") 2 | require("QtWidgets") 3 | local ui_LoginWindow = require("ui_LoginWindow") 4 | 5 | local LoginWindow = { 6 | className = "LoginWindow", 7 | superClass = QWidget, 8 | } 9 | 10 | local function newLoginWindow(mo, parent) 11 | local self = QWidget.newExtended(mo, parent) 12 | self.ui = ui_LoginWindow.setupUi(self) 13 | self:connect(self.ui.btn_Login, "2clicked()", "1doLogin()") 14 | return self 15 | end 16 | 17 | LuaQtHelper.addConstructor(LoginWindow, {"QWidget*"}, newLoginWindow) 18 | 19 | LuaQtHelper.addSignal(LoginWindow, "void", "logined", {}) 20 | 21 | LuaQtHelper.addSlot(LoginWindow, "void", "doLogin", {}, function(self) 22 | self:logined() 23 | self:close() 24 | end) 25 | 26 | LoginWindow = LuaQtHelper.defineQtClass(LoginWindow) 27 | return LoginWindow -------------------------------------------------------------------------------- /tools/codegen/template/constructorextol.cpp: -------------------------------------------------------------------------------- 1 | for (;;) 2 | { 3 | CHECK_ARG_COUNT(/*%return 1+#arguments%*/); 4 | CHECK_USERDATA_ARG(1); 5 | 6 | /*% 7 | local ret = "" 8 | for i,v in ipairs(arguments) do 9 | ret = ret .. string.format(" CHECK_ARG((%s), %d);\n", v.normalizedType, i+1) 10 | end 11 | return ret 12 | %*/ 13 | START_ARGREF_FRAME(); 14 | GET_USERDATA((const QMetaObject*), 1, mo); 15 | /*% 16 | local ret = "" 17 | for i,v in ipairs(arguments) do 18 | ret = ret .. string.format(" GET_ARG((%s), %d, arg%d);\n", v.normalizedType, i+1, i) 19 | end 20 | return ret 21 | %*/ 22 | CLASS* obj = new CLASS_EXTENDED(mo/*% 23 | local ret = "" 24 | for i,v in ipairs(arguments) do 25 | ret = ret .. string.format(", arg%d", i) 26 | end 27 | return ret 28 | %*/); 29 | 30 | LuaQt::InitAndPushObject(L, obj, obj, CLASS_NAME); 31 | 32 | END_ARGREF_FRAME(); 33 | 34 | return 1; 35 | } 36 | -------------------------------------------------------------------------------- /modules/mocreader/src/mocparser.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #include "mocparser.h" 23 | -------------------------------------------------------------------------------- /modules/mocreader/src/mocparser.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #ifndef MOCPARSER_H 23 | #define MOCPARSER_H 24 | 25 | #include "mocreader_global.h" 26 | 27 | 28 | #endif // MOCPARSER_H 29 | -------------------------------------------------------------------------------- /modules/mocreader/src/mocreader.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #ifndef MOCREADER_H 23 | #define MOCREADER_H 24 | 25 | #include "mocreader_global.h" 26 | 27 | 28 | #endif // MOCREADER_H 29 | -------------------------------------------------------------------------------- /modules/mocreader/build/mocreader/mocreader.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2014-08-30T21:39:50 4 | # 5 | #------------------------------------------------- 6 | 7 | QT -= gui 8 | 9 | TARGET = mocreader 10 | TEMPLATE = lib 11 | 12 | DEFINES += MOCREADER_LIB 13 | 14 | SOURCES += \ 15 | ../../src/keywords.cpp \ 16 | ../../src/moc.cpp \ 17 | ../../src/mocparser.cpp \ 18 | ../../src/mocreader.cpp \ 19 | ../../src/parser.cpp \ 20 | ../../src/ppkeywords.cpp \ 21 | ../../src/preprocessor.cpp \ 22 | ../../src/token.cpp 23 | 24 | HEADERS += \ 25 | ../../src/moc.h \ 26 | ../../src/mocparser.h \ 27 | ../../src/mocreader.h \ 28 | ../../src/mocreader_global.h\ 29 | ../../src/parser.h \ 30 | ../../src/preprocessor.h \ 31 | ../../src/qmetaobject_moc_p.h \ 32 | ../../src/symbols.h \ 33 | ../../src/token.h \ 34 | ../../src/utils.h 35 | 36 | LIBS += -llua51 37 | 38 | unix { 39 | target.path = /usr/lib 40 | INSTALLS += target 41 | } 42 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow-ml/LoginWindow.lua: -------------------------------------------------------------------------------- 1 | require 'QtWidgets' 2 | require 'luaqtml' 3 | 4 | local ui_LoginWindow = requireUI("./loginwindow.ui") 5 | 6 | -- @luaqt 7 | -- @class LoginWindow 8 | -- @ extends QWidget 9 | local LoginWindow = {} 10 | 11 | -- @constructor __init__ 12 | -- @ argument QWidget* 13 | -- @end constructor 14 | function LoginWindow:__init__(parent) 15 | self = super(parent) 16 | self.ui = ui_LoginWindow.setupUi(self) 17 | self:connect(self.ui.btn_Login, "2clicked(bool)", "1doLogin(bool)") 18 | self:connect(self.ui.edit_ID, "2cursorPositionChanged(int, int)", "1testPosition(int, int)") 19 | end 20 | 21 | -- @signal logined 22 | -- @ return void 23 | -- @end signal 24 | function LoginWindow:logined() 25 | end 26 | 27 | -- @slot doLogin 28 | -- @ argument bool 29 | -- @ return void 30 | -- @end slot 31 | function LoginWindow:doLogin(arg) 32 | self:logined() 33 | end 34 | 35 | -- @slot testPosition 36 | -- @ argument int 37 | -- @ argument int 38 | -- @ return void 39 | -- @end slot 40 | function LoginWindow:testPosition(f, t) 41 | print(f, t) 42 | end 43 | 44 | 45 | 46 | -- @end class 47 | 48 | return { 49 | LoginWindow = LoginWindow 50 | } 51 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow1/LoginWindow.lua: -------------------------------------------------------------------------------- 1 | local LuaQtHelper = require("LuaQtHelper") 2 | require("QtWidgets") 3 | -- local ui_LoginWindow = require("ui_LoginWindow") 4 | local ui_LoginWindow = loadstring(require("uic").run("loginwindow.ui"))() 5 | 6 | local LoginWindow = { 7 | className = "LoginWindow", 8 | superClass = QWidget, 9 | } 10 | 11 | local function newLoginWindow(mo, parent) 12 | local self = QWidget.newExtended(mo, parent) 13 | self.ui = ui_LoginWindow.setupUi(self) 14 | self:connect(self.ui.btn_Login, "2clicked(bool)", "1doLogin(bool)") 15 | self:connect(self.ui.edit_ID, "2cursorPositionChanged(int,int)", "1testPosition(int,int)") 16 | return self 17 | end 18 | 19 | LuaQtHelper.addConstructor(LoginWindow, {"QWidget*"}, newLoginWindow) 20 | 21 | LuaQtHelper.addSignal(LoginWindow, "void", "logined", {}) 22 | 23 | LuaQtHelper.addSlot(LoginWindow, "void", "doLogin", {"bool"}, function(self, ...) 24 | print(...) 25 | self:logined() 26 | end) 27 | 28 | LuaQtHelper.addSlot(LoginWindow, "void", "testPosition", {"int", "int"}, function(self, ...) 29 | print(...) 30 | self:logined() 31 | end) 32 | 33 | LoginWindow = LuaQtHelper.defineQtClass(LoginWindow) 34 | return LoginWindow -------------------------------------------------------------------------------- /modules/mocreader/src/mocreader_global.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #ifndef MOCREADER_GLOBAL_H 23 | #define MOCREADER_GLOBAL_H 24 | 25 | #include 26 | 27 | #ifdef MOCREADER_LIB 28 | # define MOCREADER_EXPORT Q_DECL_EXPORT 29 | #else 30 | # define MOCREADER_EXPORT Q_DECL_IMPORT 31 | #endif 32 | 33 | #endif // MOCREADER_GLOBAL_H 34 | -------------------------------------------------------------------------------- /modules/mocreader/COPYRIGHT.md: -------------------------------------------------------------------------------- 1 | mocreader's License 2 | -------------- 3 | 4 | "mocreader" is licenced at LGPL license. 5 | 6 | =============================================================================== 7 | 8 | Copyright (c) 2013, DengYun 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | 24 | =============================================================================== 25 | 26 | Some source file have different author. They are copied from source of "Qt". See the source file for more information. 27 | 28 | (end of COPYRIGHT) -------------------------------------------------------------------------------- /modules/uic/COPYRIGHT.md: -------------------------------------------------------------------------------- 1 | module lua-uic's License 2 | -------------- 3 | 4 | module "lua-uic" is licenced at LGPL license. 5 | 6 | =============================================================================== 7 | 8 | Copyright (c) 2013, tdzl2003 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | 24 | =============================================================================== 25 | 26 | Some source file have different author. They are copied from source of "Qt". See the source file for more information. 27 | 28 | (end of COPYRIGHT) -------------------------------------------------------------------------------- /modules/uic/LGPL_EXCEPTION.txt: -------------------------------------------------------------------------------- 1 | Digia Qt LGPL Exception version 1.1 2 | 3 | As an additional permission to the GNU Lesser General Public License version 4 | 2.1, the object code form of a "work that uses the Library" may incorporate 5 | material from a header file that is part of the Library. You may distribute 6 | such object code under terms of your choice, provided that: 7 | (i) the header files of the Library have not been modified; and 8 | (ii) the incorporated material is limited to numerical parameters, data 9 | structure layouts, accessors, macros, inline functions and 10 | templates; and 11 | (iii) you comply with the terms of Section 6 of the GNU Lesser General 12 | Public License version 2.1. 13 | 14 | Moreover, you may apply this exception to a modified version of the Library, 15 | provided that such modification does not involve copying material from the 16 | Library into the modified Library's header files unless such material is 17 | limited to (i) numerical parameters; (ii) data structure layouts; 18 | (iii) accessors; and (iv) small macros, templates and inline functions of 19 | five lines or less in length. 20 | 21 | Furthermore, you are not required to apply this additional permission to a 22 | modified version of the Library. 23 | -------------------------------------------------------------------------------- /tools/codegen/template/staticmethodol.cpp: -------------------------------------------------------------------------------- 1 | for (;;) 2 | { 3 | CHECK_ARG_COUNT(/*%return #arguments%*/); 4 | 5 | /*% 6 | local ret = "" 7 | for i,v in ipairs(arguments) do 8 | ret = ret .. string.format(" CHECK_ARG((%s), %d);\n", v.normalizedType, i) 9 | end 10 | return ret 11 | %*/ 12 | START_ARGREF_FRAME(); 13 | /*% 14 | local ret = "" 15 | for i,v in ipairs(arguments) do 16 | ret = ret .. string.format(" GET_ARG((%s), %d, arg%d);\n", v.normalizedType, i, i) 17 | end 18 | return ret 19 | %*/ 20 | 21 | /*% 22 | if (normalizedType ~= "void") then 23 | return "\t\tPUSH_RET_VAL((" .. normalizedType ..")," 24 | end 25 | return "" 26 | %*/ 27 | CLASS::/*%return name%*/( 28 | /*% 29 | local ret = {"\t\t\t"} 30 | for i,v in ipairs(arguments) do 31 | table.insert(ret, string.format("arg%d", i)) 32 | table.insert(ret, ", ") 33 | end 34 | table.remove(ret) 35 | return (#ret>0) and table.concat(ret) or "" 36 | %*/ 37 | ) 38 | /*% 39 | if (normalizedType ~= "void") then 40 | return "\t\t);" 41 | else 42 | return ";" 43 | end 44 | %*/ 45 | 46 | END_ARGREF_FRAME(); 47 | 48 | /*% 49 | if (normalizedType ~= "void") then 50 | return "\t\treturn 1;" 51 | else 52 | return "\t\treturn 0;" 53 | end 54 | %*/ 55 | } -------------------------------------------------------------------------------- /modules/mocreader/LGPL_EXCEPTION.txt: -------------------------------------------------------------------------------- 1 | Digia Qt LGPL Exception version 1.1 2 | 3 | As an additional permission to the GNU Lesser General Public License version 4 | 2.1, the object code form of a "work that uses the Library" may incorporate 5 | material from a header file that is part of the Library. You may distribute 6 | such object code under terms of your choice, provided that: 7 | (i) the header files of the Library have not been modified; and 8 | (ii) the incorporated material is limited to numerical parameters, data 9 | structure layouts, accessors, macros, inline functions and 10 | templates; and 11 | (iii) you comply with the terms of Section 6 of the GNU Lesser General 12 | Public License version 2.1. 13 | 14 | Moreover, you may apply this exception to a modified version of the Library, 15 | provided that such modification does not involve copying material from the 16 | Library into the modified Library's header files unless such material is 17 | limited to (i) numerical parameters; (ii) data structure layouts; 18 | (iii) accessors; and (iv) small macros, templates and inline functions of 19 | five lines or less in length. 20 | 21 | Furthermore, you are not required to apply this additional permission to a 22 | modified version of the Library. 23 | -------------------------------------------------------------------------------- /msvcbuild.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Create temp directory and build two modules. 4 | if not exist make mkdir make 5 | cd make 6 | 7 | 8 | echo Build module "mocreader". 9 | if not exist mocreader mkdir mocreader 10 | cd mocreader 11 | 12 | qmake.exe ..\..\modules\mocreader\build\mocreader\mocreader.pro -r 13 | jom 14 | 15 | cd .. 16 | 17 | echo Build module "uic". 18 | if not exist uic mkdir uic 19 | cd uic 20 | 21 | qmake.exe ..\..\modules\uic\build\uic\uic.pro -r 22 | jom 23 | 24 | cd .. 25 | 26 | cd .. 27 | 28 | if not exist bin mkdir bin 29 | copy make\mocreader\release\mocreader.dll bin\ 30 | copy make\uic\release\uic.dll bin\ 31 | 32 | set LUA_CPATH=./bin/?.dll 33 | set LUA_PATH=./?.lua;./modules/path/?.lua;./third_party/json/?.lua 34 | 35 | REM Parse header files. 36 | 37 | luajit ./tools/mocparser/main.lua 38 | 39 | REM Generate code. 40 | 41 | luajit ./tools/codegen/main.lua ./tools/codegen/config.json 42 | 43 | cd make 44 | if not exist Root mkdir Root 45 | cd Root 46 | 47 | qmake ..\..\build\qtpro\Root.pro -r 48 | jom 49 | 50 | cd .. 51 | cd .. 52 | REM Copying code 53 | copy make\Root\LuaQt\release\LuaQt.dll bin\ 54 | copy make\Root\QtCore\release\QtCore.dll bin\ 55 | copy make\Root\QtGui\release\QtGui.dll bin\ 56 | copy make\Root\QtWidgets\release\QtWidgets.dll bin\ 57 | 58 | echo Done. 59 | -------------------------------------------------------------------------------- /tools/codegen/template/methodol.cpp: -------------------------------------------------------------------------------- 1 | for (;;) 2 | { 3 | CHECK_ARG_COUNT(/*%return #arguments+1%*/); 4 | 5 | CHECK_ARG((CLASS*), 1); 6 | /*% 7 | local ret = "" 8 | for i,v in ipairs(arguments) do 9 | ret = ret .. string.format(" CHECK_ARG((%s), %d);\n", v.normalizedType, i+1) 10 | end 11 | return ret 12 | %*/ 13 | START_ARGREF_FRAME(); 14 | GET_ARG((CLASS*), 1, self); 15 | /*% 16 | local ret = "" 17 | for i,v in ipairs(arguments) do 18 | ret = ret .. string.format(" GET_ARG((%s), %d, arg%d);\n", v.normalizedType, i+1, i) 19 | end 20 | return ret 21 | %*/ 22 | 23 | /*% 24 | if (normalizedType ~= "void") then 25 | return "\t\tPUSH_RET_VAL((" .. normalizedType ..")," 26 | end 27 | return "" 28 | %*/ 29 | self->/*%return name%*/( 30 | /*% 31 | local ret = {"\t\t\t"} 32 | for i,v in ipairs(arguments) do 33 | table.insert(ret, string.format("arg%d", i)) 34 | table.insert(ret, ", ") 35 | end 36 | table.remove(ret) 37 | return (#ret>0) and table.concat(ret) or "" 38 | %*/ 39 | ) 40 | /*% 41 | if (normalizedType ~= "void") then 42 | return "\t\t);" 43 | else 44 | return ";" 45 | end 46 | %*/ 47 | 48 | END_ARGREF_FRAME(); 49 | 50 | /*% 51 | if (normalizedType ~= "void") then 52 | return "\t\treturn 1;" 53 | else 54 | return "\t\treturn 0;" 55 | end 56 | %*/ 57 | } -------------------------------------------------------------------------------- /modules/mocreader/build/msvc2012/mocreader/mocreader.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mocreader", "mocreader.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|Win32.Build.0 = Debug|Win32 16 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.ActiveCfg = Debug|x64 17 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.Build.0 = Debug|x64 18 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|Win32.ActiveCfg = Release|Win32 19 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|Win32.Build.0 = Release|Win32 20 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.ActiveCfg = Release|x64 21 | {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /modules/path/path/impl_posix.lua: -------------------------------------------------------------------------------- 1 | -- NOTICE: 2 | -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 3 | -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4 | -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5 | -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 6 | -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 7 | -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 8 | -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 9 | -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 10 | -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 11 | -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 12 | -- POSSIBILITY OF SUCH DAMAGE. 13 | -- 14 | -- read COPYRIGHT.md for more informations. 15 | 16 | local impl = {} 17 | local ffi = require("ffi") 18 | local C = ffi.C 19 | 20 | ffi.cdef[[ 21 | void* malloc(size_t size); 22 | void free(void* data); 23 | char* getcwd(char* buffer, int maxlen); 24 | ]] 25 | 26 | function impl.current() 27 | local buff = C.malloc(256) 28 | local ret = ffi.string(C.getcwd(buff, 256)) 29 | C.free(buff) 30 | return ret 31 | end 32 | 33 | return impl 34 | 35 | 36 | -------------------------------------------------------------------------------- /modules/uic/build/uic/uic.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2014-07-18T01:32:15 4 | # 5 | #------------------------------------------------- 6 | 7 | QT -= gui 8 | 9 | TARGET = uic 10 | TEMPLATE = lib 11 | 12 | DEFINES += QT_UIC_LUA_GENERATOR 13 | 14 | SOURCES += \ 15 | ../../src/customwidgetsinfo.cpp \ 16 | ../../src/databaseinfo.cpp \ 17 | ../../src/driver.cpp \ 18 | ../../src/main.cpp \ 19 | ../../src/treewalker.cpp \ 20 | ../../src/ui4.cpp \ 21 | ../../src/uic.cpp \ 22 | ../../src/validator.cpp \ 23 | ../../src/lua/luawritedeclaration.cpp \ 24 | ../../src/lua/luawriteincludes.cpp \ 25 | ../../src/lua/luawriteinitialization.cpp 26 | 27 | HEADERS += \ 28 | ../../src/customwidgetsinfo.h \ 29 | ../../src/databaseinfo.h \ 30 | ../../src/driver.h \ 31 | ../../src/globaldefs.h \ 32 | ../../src/option.h \ 33 | ../../src/qclass_lib_map.h \ 34 | ../../src/treewalker.h \ 35 | ../../src/ui4.h \ 36 | ../../src/uic.h \ 37 | ../../src/utils.h \ 38 | ../../src/validator.h \ 39 | ../../src/lua/luawritedeclaration.h \ 40 | ../../src/lua/luawriteincludes.h \ 41 | ../../src/lua/luawriteinitialization.h 42 | 43 | LIBS += -llua51 44 | 45 | unix { 46 | target.path = /usr/lib 47 | INSTALLS += target 48 | } 49 | -------------------------------------------------------------------------------- /tools/codegen/template/signalimpl.cpp: -------------------------------------------------------------------------------- 1 | class signal_/*%return class.classname%*/_/*%return id%*/_callback 2 | : public LuaQt::generic_callback 3 | { 4 | public: 5 | signal_/*%return class.classname%*/_/*%return id%*/_callback(lua_State *L) 6 | : LuaQt::generic_callback(L) 7 | { 8 | } 9 | ~signal_/*%return class.classname%*/_/*%return id%*/_callback() 10 | { 11 | } 12 | void operator() (/*% 13 | local ret = {} 14 | for i,v in ipairs(arguments) do 15 | table.insert(ret, string.format("%s arg%d", 16 | v.type.rawName, 17 | i 18 | )) 19 | end 20 | return table.concat(ret, ', ') 21 | %*/) 22 | { 23 | this->push(); 24 | /*% 25 | local ret = {} 26 | for i,v in ipairs(arguments) do 27 | table.insert(ret, string.format("\t\tPUSH_RET_VAL((%s), arg%d);", 28 | v.type.rawName, 29 | i 30 | )) 31 | end 32 | return table.concat(ret, '\n'); 33 | %*/ 34 | lua_call(L, /*%return #arguments%*/, 0); 35 | } 36 | }; 37 | 38 | int signal_/*%return class.classname%*/_/*%return id%*/(lua_State *L) 39 | { 40 | for (;;){ 41 | CHECK_ARG_COUNT(2); 42 | CHECK_ARG((CLASS*), 1); 43 | CHECK_LUAFUNCTION_ARG(2); 44 | 45 | START_ARGREF_FRAME(); 46 | GET_ARG((CLASS*), 1, self); 47 | 48 | QObject::connect(self, static_cast(&CLASS::/*%return name%*/), signal_/*%return class.classname%*/_/*%return id%*/_callback(L)); 57 | 58 | END_ARGREF_FRAME(); 59 | return 0; 60 | } 61 | 62 | return luaL_error(L, "No valid overload found."); 63 | } 64 | -------------------------------------------------------------------------------- /tools/codegen/template/extendedimpl.cpp: -------------------------------------------------------------------------------- 1 | namespace LuaQt{ 2 | class /*%return class.classname%*/_Extended_Impl 3 | : public /*%return class.classname%*/ 4 | { 5 | public: 6 | /*% 7 | return constructorOverloads() 8 | %*/ 9 | 10 | ~/*%return class.classname%*/_Extended_Impl() 11 | { 12 | mo = NULL; 13 | } 14 | 15 | virtual const QMetaObject *metaObject() const 16 | { 17 | return (mo); 18 | } 19 | 20 | // just use super class's qt_metacast for C++ class wrapping. 21 | /*virtual void *qt_metacast(const char *) 22 | { 23 | 24 | }*/ 25 | 26 | virtual int qt_metacall(QMetaObject::Call _c, int _id, void ** _a) 27 | { 28 | _id = /*%return class.classname%*/::qt_metacall(_c, _id, _a); 29 | if (_id < 0) 30 | return _id; 31 | if (_c == QMetaObject::InvokeMetaMethod) { 32 | int mc = mo->d.data[4]; 33 | if (_id < mc) { 34 | LuaQt::generic_callback* mc = reinterpret_cast(mo->d.extradata); 35 | Q_ASSERT_X(mc, "qt_metacall", "No metacall function provided"); 36 | lua_State *L = mc->getState(); 37 | mc->push(); 38 | lua_pushinteger(L, (int)_c); 39 | lua_pushinteger(L, _id+1); 40 | LuaQt::PushObject(L, this); 41 | lua_pushlightuserdata(L, _a); 42 | lua_call(L, 4, 0); 43 | } 44 | _id -= mc; 45 | } else if (_c == QMetaObject::RegisterMethodArgumentMetaType){ 46 | int mc = mo->d.data[4]; 47 | if (_id < mc) { 48 | Q_ASSERT_X(false, "qt_metacall", "Not Implemented."); 49 | } 50 | _id -= mc; 51 | } 52 | return _id; 53 | } 54 | 55 | private: 56 | const QMetaObject * mo; 57 | }; 58 | } 59 | 60 | #define CLASS_EXTENDED LuaQt::/*%return class.classname%*/_Extended_Impl -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | luaQt 2 | ===== 3 | 4 | Lua(JIT) wrapper for QT 5 | 6 | News 7 | ---- 8 | 9 | Lua-Qt Meta language's sample was at [here](https://github.com/tdzl2003/luaqt/blob/master/test/testwidget/loginwindow-ml/LoginWindow.lua) 10 | 11 | Please let me know what do you think about it. 12 | 13 | Any question/review/suggesting about luaqt will be good for me&luaqt. 14 | 15 | contact me with: 16 | 17 | QQ: 402740419 18 | 19 | E-mail: tdzl2003@gmail.com 20 | 21 | Prerequisites(Windows) 22 | ---------------------- 23 | 24 | 1. Install Visual Studio (2010 or higher). The freely downloadable [Express Edition](http://www.microsoft.com/Express/VC/) works just fine. 25 | 26 | Currently, only 2013 was tested. Other versions should also work. 27 | 28 | 2. Download and install [Qt](http://qt-project.org/downloads). 29 | 30 | Currently, only 5.3.1 was tested. Other versions should also work. 31 | 32 | 3. Download and build [luajit](http://luajit.org/download.html). Follow [this guide](http://luajit.org/install.html#windows). 33 | 34 | Any versions higher than 2.0.0 should work. 35 | 36 | 37 | Install 38 | ------- 39 | 40 | 1. Add luajit src directory(eg C:\LuaJIT-2.0.3\src) to THREE environment variables: `PATH`, `INCLUDE`, `LIB` 41 | 42 | 2. Set environment variable `QT_HOME` as home directory of Qt SDK(Not Qt installation directory)(eg, C:\Qt\Qt5.3.1\5.3\msvc2013_opengl) 43 | 44 | 3. Add both Qt SDK bin directory(eg C:\Qt\Qt5.3.1\5.3\msvc2013_opengl\bin) and Qt Creator bin directory(eg C:\Qt\Qt5.3.1\Tools\QtCreator\bin\) to enviroment variable `PATH` 45 | 46 | 4. Run `Developer Command Prompt` for Visual Studio 47 | 48 | 5. Goto luaqt directory and run `msvcbuild.cmd` 49 | 50 | ``` 51 | cd C:\luaqt 52 | msvcbuild 53 | ``` 54 | 55 | 6. Get your libraries from luaqt\bin, or add it to `PATH` 56 | 57 | -------------------------------------------------------------------------------- /modules/uic/src/lua/luawritedeclaration.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #ifndef CPPWRITEDECLARATION_H 23 | #define CPPWRITEDECLARATION_H 24 | 25 | #include "../treewalker.h" 26 | 27 | QT_BEGIN_NAMESPACE 28 | 29 | class QTextStream; 30 | class Driver; 31 | class Uic; 32 | 33 | struct Option; 34 | 35 | namespace LUA { 36 | 37 | struct WriteDeclaration : public TreeWalker 38 | { 39 | WriteDeclaration(Uic *uic); 40 | 41 | void acceptUI(DomUI *node); 42 | void acceptWidget(DomWidget *node); 43 | void acceptSpacer(DomSpacer *node); 44 | void acceptLayout(DomLayout *node); 45 | void acceptActionGroup(DomActionGroup *node); 46 | void acceptAction(DomAction *node); 47 | void acceptButtonGroup(const DomButtonGroup *buttonGroup); 48 | 49 | private: 50 | Uic *m_uic; 51 | Driver *m_driver; 52 | QTextStream &out; 53 | const Option &m_option; 54 | }; 55 | 56 | } // namespace CPP 57 | 58 | QT_END_NAMESPACE 59 | 60 | #endif // CPPWRITEDECLARATION_H 61 | -------------------------------------------------------------------------------- /src/LuaQt/globalstate.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | 29 | namespace LuaQt{ 30 | static int s_key_global = 0; 31 | 32 | Q_DECL_EXPORT void saveGlobalState(lua_State *L) 33 | { 34 | lua_pushlightuserdata(L, &s_key_global); 35 | lua_pushlightuserdata(L, L); 36 | lua_rawset(L, LUA_REGISTRYINDEX); 37 | } 38 | 39 | Q_DECL_EXPORT lua_State* getGlobalState(lua_State *L) 40 | { 41 | lua_pushlightuserdata(L, &s_key_global); 42 | lua_rawget(L, LUA_REGISTRYINDEX); 43 | lua_State* ret = (lua_State *)lua_touserdata(L, -1); 44 | lua_pop(L, 1); 45 | return ret; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tools/codegen/template/package.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is generated by tools. It's still licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | #include 29 | 30 | /*% 31 | local ret = "" 32 | for i,v in ipairs(classes) do 33 | ret = ret ..string.format("void luadef_%s(lua_State *L);\n", v) 34 | end 35 | return ret 36 | %*/ 37 | extern "C" Q_DECL_EXPORT int luaopen_/*%return packageName%*/(lua_State *L) 38 | { 39 | LuaQt::saveGlobalState(L); 40 | LuaQt::InitGCer(L); 41 | 42 | lua_createtable(L, 0, 0); 43 | /*% 44 | local ret = "" 45 | for i,v in ipairs(classes) do 46 | ret = ret.. string.format(" luadef_%s(L);\n", v) 47 | end 48 | return ret 49 | %*/ 50 | return 1; 51 | } 52 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow/ui_LoginWindow.lua: -------------------------------------------------------------------------------- 1 | local ui_LoginWindow = {} 2 | 3 | function ui_LoginWindow.setupUi(self) 4 | if (self:objectName() == "") then 5 | self:setObjectName("LoginWindow") 6 | end 7 | self:resize(400, 300) 8 | local verticleLayout = QVBoxLayout.new(self) 9 | verticleLayout:setSpacing(6) 10 | verticleLayout:setContentsMargins(11, 11, 11, 11); 11 | verticleLayout:setObjectName("verticleLayout") 12 | local gridLayout = QGridLayout.new() 13 | gridLayout:setSpacing(6) 14 | gridLayout:setObjectName("gridLayout") 15 | gridLayout:setVerticalSpacing(48); 16 | local label_2 = QLabel.new(self) 17 | label_2:setObjectName("label_2") 18 | 19 | gridLayout:addWidget(label_2, 1, 0, 1, 1) 20 | 21 | local edit_Pwd = QLineEdit.new(self) 22 | edit_Pwd:setObjectName("edit_Pwd") 23 | edit_Pwd:setEchoMode(2) 24 | 25 | gridLayout:addWidget(edit_Pwd, 1, 1, 1, 1) 26 | 27 | local edit_ID = QLineEdit.new(self) 28 | edit_ID:setObjectName("edit_ID") 29 | 30 | gridLayout:addWidget(edit_ID, 0, 1, 1, 1) 31 | 32 | local label = QLabel.new(self) 33 | label:setObjectName("label") 34 | 35 | gridLayout:addWidget(label, 0, 0, 1, 1) 36 | 37 | local btn_Login = QPushButton.new(self) 38 | btn_Login:setObjectName("btn_Login") 39 | 40 | gridLayout:addWidget(btn_Login, 2, 0, 1, 2) 41 | 42 | verticleLayout:addLayout(gridLayout) 43 | 44 | QWidget.setTabOrder(edit_ID, edit_Pwd) 45 | QWidget.setTabOrder(edit_Pwd, btn_Login) 46 | 47 | local ui = { 48 | verticleLayout = verticleLayout, 49 | gridLayout = gridLayout, 50 | label_2 = label_2, 51 | edit_Pwd = edit_Pwd, 52 | edit_ID = edit_ID, 53 | label = label, 54 | btn_Login = btn_Login, 55 | } 56 | 57 | ui_LoginWindow.retranslateUi(self, ui) 58 | 59 | return ui 60 | end 61 | 62 | function ui_LoginWindow.retranslateUi(self, ui) 63 | self:setWindowTitle("Login") 64 | ui.label_2:setText("Passwd") 65 | ui.label:setText("ID") 66 | ui.btn_Login:setText("Login") 67 | end 68 | 69 | return ui_LoginWindow 70 | -------------------------------------------------------------------------------- /COPYRIGHT.md: -------------------------------------------------------------------------------- 1 | LuaQT's License 2 | -------------- 3 | 4 | All source and distributes of "LuaQT library" is licenced at BSD New license. 5 | 6 | =============================================================================== 7 | 8 | Copyright (c) 2013, DengYun 9 | 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 13 | 14 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 15 | 16 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 17 | 18 | Neither the name of the LuaQT nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | 22 | =============================================================================== 23 | 24 | Note that some extra tools/modules/plugins are based on different licenses: 25 | 26 | module "mocreader" is based on LGPL license. read modules/mocreader/LICENSE.LGPL for more information. 27 | 28 | (end of COPYRIGHT) -------------------------------------------------------------------------------- /src/LuaQt/argrefframe.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | 29 | #include 30 | 31 | namespace LuaQt 32 | { 33 | static std::vector< 34 | std::vector 35 | > s_frames; 36 | 37 | Q_DECL_EXPORT void StartArgRefFrame(lua_State *L) 38 | { 39 | s_frames.push_back(std::vector()); 40 | } 41 | 42 | Q_DECL_EXPORT void EndArgRefFrame(lua_State *L) 43 | { 44 | std::vector& f = s_frames.back(); 45 | for (size_t i = 0; i < f.size(); ++i) 46 | { 47 | free(f[i]); 48 | } 49 | 50 | s_frames.pop_back(); 51 | } 52 | 53 | Q_DECL_EXPORT void* allocArgRef(lua_State *L, size_t size) 54 | { 55 | void* ret = malloc(size); 56 | s_frames.back().push_back(ret); 57 | return ret; 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow-ml/loginwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoginWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | 15 | 20 16 | 20 17 | 18 | 19 | 20 | Login 21 | 22 | 23 | 24 | 25 | 26 | 48 27 | 28 | 29 | 30 | 31 | Passwd 32 | 33 | 34 | 35 | 36 | 37 | 38 | QLineEdit::Password 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | ID 49 | 50 | 51 | 52 | 53 | 54 | 55 | Login 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | edit_ID 66 | edit_Pwd 67 | btn_Login 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/LuaQt/metafunctions.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | 29 | namespace LuaQt 30 | { 31 | //upvalue 1: method map 32 | //upvalue 2: getter map 33 | Q_DECL_EXPORT int General_index(lua_State *L) 34 | { 35 | //try method map 36 | lua_pushvalue(L, 2); 37 | lua_rawget(L, lua_upvalueindex(1)); 38 | if (!lua_isnil(L, -1)) 39 | { 40 | return 1; 41 | } 42 | lua_pop(L, 1); 43 | 44 | //try getter 45 | lua_pushvalue(L, 2); 46 | lua_rawget(L, lua_upvalueindex(2)); 47 | if (!lua_isnil(L, -1)) 48 | { 49 | lua_pushvalue(L, 1); 50 | lua_call(L, 1, 1); 51 | return 1; 52 | } 53 | 54 | lua_pushnil(L); 55 | return 1; 56 | } 57 | 58 | //upvalue 1: setter map 59 | Q_DECL_EXPORT int General_newindex(lua_State *L) 60 | { 61 | lua_rawset(L, 1); 62 | //luaL_error(L, "Not implemented yet!"); 63 | return 0; 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /modules/uic/src/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #include "uic.h" 23 | #include "option.h" 24 | #include "driver.h" 25 | #include 26 | #include 27 | #include 28 | 29 | static int run(lua_State *L) 30 | { 31 | Driver driver; 32 | 33 | driver.option().generator = Option::LuaGenerator; 34 | 35 | const char* fileName = luaL_checkstring(L, 1); 36 | QString inputFile = QString::fromUtf8(fileName); 37 | 38 | QByteArray data; 39 | QTextStream *out = new QTextStream(&data); 40 | out->setCodec(QTextCodec::codecForName("UTF-8")); 41 | 42 | bool rtn = driver.uic(inputFile, out); 43 | delete out; 44 | 45 | if (!rtn) { 46 | return 0; 47 | } 48 | 49 | lua_pushlstring(L, data.data(), data.size()); 50 | return 1; 51 | } 52 | 53 | static luaL_Reg entries[] = { 54 | //TODO: version number 55 | {"run", run} 56 | }; 57 | 58 | inline void luaL_regfuncs(lua_State*L, luaL_Reg* reg, size_t count) 59 | { 60 | for (size_t i =0; i < count; ++i) 61 | { 62 | lua_pushcfunction(L, reg[i].func); 63 | lua_setfield(L, -2, reg[i].name); 64 | } 65 | } 66 | 67 | #define luaL_newlib(l, m) lua_createtable(l, 0, sizeof(m)/sizeof(m[0])); luaL_regfuncs(l, m, sizeof(m)/sizeof(m[0])) 68 | 69 | extern "C" Q_DECL_EXPORT int luaopen_uic(lua_State *L) 70 | { 71 | luaL_newlib(L, entries); 72 | return 1; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /test/testwidget/loginwindow1/loginwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoginWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Login 15 | 16 | 17 | 18 | 19 | 20 | 48 21 | 22 | 23 | 24 | 25 | Passwd 26 | 27 | 28 | 29 | 30 | 31 | 32 | QLineEdit::Password 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | ID 43 | 44 | 45 | 46 | 47 | 48 | 49 | Login 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | edit_ID 60 | edit_Pwd 61 | btn_Login 62 | 63 | 64 | 65 | 66 | btn_Login 67 | clicked() 68 | LoginWindow 69 | close() 70 | 71 | 72 | 199 73 | 247 74 | 75 | 76 | 199 77 | 149 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /modules/uic/src/globaldefs.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef GLOBALDEFS_H 43 | #define GLOBALDEFS_H 44 | 45 | #include 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | enum { BOXLAYOUT_DEFAULT_MARGIN = 11 }; 50 | enum { BOXLAYOUT_DEFAULT_SPACING = 6 }; 51 | 52 | QT_END_NAMESPACE 53 | 54 | #endif // GLOBALDEFS_H 55 | -------------------------------------------------------------------------------- /src/QtCore/signal.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | 29 | #include 30 | 31 | int QObject_connect(lua_State *L) 32 | { 33 | for (;;) 34 | { 35 | CHECK_ARG_COUNT(4); 36 | 37 | CHECK_ARG((QObject*), 1); 38 | CHECK_ARG((QObject*), 2); 39 | CHECK_ARG((const char*), 3); 40 | CHECK_ARG((const char*), 4); 41 | 42 | START_ARGREF_FRAME(); 43 | GET_ARG((QObject*), 1, self); 44 | GET_ARG((QObject*), 2, sender); 45 | GET_ARG((const char*), 3, signal); 46 | GET_ARG((const char*), 4, slot); 47 | 48 | self->connect(sender, signal, slot); 49 | 50 | END_ARGREF_FRAME(); 51 | 52 | return 0; 53 | } 54 | 55 | for (;;) 56 | { 57 | CHECK_ARG_COUNT(3); 58 | CHECK_ARG((QObject*), 1); 59 | CHECK_ARG((const char*), 2); 60 | CHECK_LUAFUNCTION_ARG(3); 61 | 62 | lua_pushvalue(L, 2); 63 | lua_gettable(L, 1); 64 | if (lua_isnil(L, -1)) 65 | { 66 | GET_ARG((const char*), 2, signal); 67 | luaL_error(L, "Cannot find signal %s", signal); 68 | return 0; 69 | } 70 | lua_pushvalue(L, 1); 71 | lua_pushvalue(L, 3); 72 | lua_call(L, 2, 1); 73 | return 1; 74 | } 75 | 76 | return luaL_error(L, "No valid overload found."); 77 | } -------------------------------------------------------------------------------- /tools/mocparser/main.lua: -------------------------------------------------------------------------------- 1 | -- NOTICE: 2 | -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 3 | -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4 | -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5 | -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 6 | -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 7 | -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 8 | -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 9 | -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 10 | -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 11 | -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 12 | -- POSSIBILITY OF SUCH DAMAGE. 13 | -- 14 | -- read COPYRIGHT.md for more informations. 15 | 16 | local path = require("path") 17 | local mocreader = require("mocreader") 18 | local json = require("json") 19 | 20 | _G.QtPath = os.getenv("QT_HOME") or error("Must set QT_HOME environment variable.") 21 | _G.QtIncludePath = path.normjoin(QtPath, "include") 22 | 23 | local fileList = {} 24 | local packageMap = {} 25 | 26 | local classList = {} 27 | 28 | print("Listing Qt header files...") 29 | do 30 | for i,package in ipairs(path.listSubdirs(_G.QtIncludePath)) do 31 | if (package ~= '.' and package ~= '..') then 32 | local packageBase = path.normjoin(QtIncludePath, package) 33 | classList[package] = {} 34 | 35 | for j,file in ipairs(path.listFiles(packageBase)) do 36 | local srcPath = path.normjoin(packageBase, file) 37 | packageMap[srcPath] = package 38 | table.insert(fileList, srcPath) 39 | end 40 | end 41 | end 42 | end 43 | 44 | print("parsing...") 45 | path.mkdir("tmp") 46 | 47 | for i,fn in ipairs(fileList) do 48 | local package = packageMap[fn] 49 | 50 | local classes = mocreader.parse(fn, { 51 | includePath= {QtIncludePath} 52 | }) 53 | for i,v in ipairs(classes) do 54 | v.fileName = path.relpath(fn, QtIncludePath) 55 | print(v.classname, v.fileName) 56 | table.insert(classList[package], v.classname) 57 | local fd = io.open(path.normalize("tmp/"..v.classname..".json"), "w") 58 | fd:write(json.encode(v)); 59 | fd:close() 60 | end 61 | 62 | end 63 | 64 | local fd = io.open("tmp/classList.json", "w") 65 | fd:write(json.encode(classList)) 66 | fd:close() 67 | 68 | print("done.") 69 | 70 | -------------------------------------------------------------------------------- /include/LuaQT/callback.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | namespace LuaQt 33 | { 34 | class generic_callback 35 | { 36 | public: 37 | generic_callback(lua_State *_L) 38 | { 39 | L = getGlobalState(_L); 40 | ref = lua_ref(L, true); 41 | } 42 | ~generic_callback() 43 | { 44 | if (ref != LUA_REFNIL && ref != LUA_NOREF) { 45 | lua_unref(L, true); 46 | } 47 | } 48 | generic_callback(generic_callback&& other){ 49 | L = other.L; 50 | ref = other.ref; 51 | other.ref = LUA_REFNIL; 52 | } 53 | void operator = (generic_callback&& other){ 54 | L = other.L; 55 | ref = other.ref; 56 | other.ref = LUA_REFNIL; 57 | } 58 | generic_callback(const generic_callback& other) 59 | { 60 | L = other.L; 61 | lua_getref(L, other.ref); 62 | ref = lua_ref(L, true); 63 | } 64 | void operator = (const generic_callback& other) 65 | { 66 | L = other.L; 67 | lua_getref(L, other.ref); 68 | ref = lua_ref(L, true); 69 | } 70 | void push() 71 | { 72 | lua_getref(L, ref); 73 | } 74 | 75 | lua_State *getState() 76 | { 77 | return L; 78 | } 79 | 80 | protected: 81 | lua_State *L; 82 | int ref; 83 | private: 84 | 85 | }; 86 | } -------------------------------------------------------------------------------- /include/LuaQT/luaqt.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #pragma once 28 | 29 | #ifdef LUA_QT_BUILD_CORE_LIB 30 | #define LUA_QT_EXPORT Q_DECL_EXPORT 31 | #else 32 | #define LUA_QT_EXPORT Q_DECL_IMPORT 33 | #endif 34 | 35 | namespace LuaQt{ 36 | LUA_QT_EXPORT void saveGlobalState(lua_State *L); 37 | LUA_QT_EXPORT lua_State* getGlobalState(lua_State *L); 38 | } 39 | 40 | // Weak ref functions 41 | namespace LuaQt{ 42 | LUA_QT_EXPORT int weakref(lua_State *L); 43 | LUA_QT_EXPORT void getweakref(lua_State *L, int id); 44 | LUA_QT_EXPORT void weakunref(lua_State *L, int id); 45 | } 46 | 47 | // Object life-cycle functions 48 | class QObject; 49 | namespace LuaQt{ 50 | LUA_QT_EXPORT bool isObject(lua_State *L, int idx, const char* className); 51 | LUA_QT_EXPORT void* checkObject(lua_State *L, int idx, const char* className); 52 | 53 | LUA_QT_EXPORT void PushObject(lua_State *L, QObject* obj); 54 | LUA_QT_EXPORT void InitAndPushObject(lua_State *L, QObject* obj, void* ptr, const char* className); 55 | 56 | void LUA_QT_EXPORT InitGCer(lua_State *L); 57 | } 58 | 59 | 60 | // Meta functions: 61 | namespace LuaQt{ 62 | LUA_QT_EXPORT int General_index(lua_State *L); 63 | LUA_QT_EXPORT int General_newindex(lua_State *L); 64 | 65 | LUA_QT_EXPORT void StartArgRefFrame(lua_State *L); 66 | LUA_QT_EXPORT void EndArgRefFrame(lua_State *L); 67 | 68 | LUA_QT_EXPORT void* allocArgRef(lua_State *L, size_t size); 69 | } 70 | -------------------------------------------------------------------------------- /modules/uic/src/validator.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef VALIDATOR_H 43 | #define VALIDATOR_H 44 | 45 | #include "treewalker.h" 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | class QTextStream; 50 | class Driver; 51 | class Uic; 52 | 53 | struct Option; 54 | 55 | struct Validator : public TreeWalker 56 | { 57 | Validator(Uic *uic); 58 | 59 | void acceptUI(DomUI *node); 60 | void acceptWidget(DomWidget *node); 61 | 62 | void acceptLayoutItem(DomLayoutItem *node); 63 | void acceptLayout(DomLayout *node); 64 | 65 | void acceptActionGroup(DomActionGroup *node); 66 | void acceptAction(DomAction *node); 67 | 68 | private: 69 | Driver *m_driver; 70 | }; 71 | 72 | QT_END_NAMESPACE 73 | 74 | #endif // VALIDATOR_H 75 | -------------------------------------------------------------------------------- /modules/uic/src/lua/luawriteincludes.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #ifndef CPPWRITEINCLUDES_H 23 | #define CPPWRITEINCLUDES_H 24 | 25 | #include "../treewalker.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | QT_BEGIN_NAMESPACE 33 | 34 | class QTextStream; 35 | class Driver; 36 | class Uic; 37 | 38 | namespace LUA { 39 | 40 | struct WriteIncludes : public TreeWalker 41 | { 42 | WriteIncludes(Uic *uic); 43 | 44 | void acceptUI(DomUI *node); 45 | void acceptWidget(DomWidget *node); 46 | void acceptLayout(DomLayout *node); 47 | void acceptSpacer(DomSpacer *node); 48 | void acceptProperty(DomProperty *node); 49 | void acceptWidgetScripts(const DomScripts &, DomWidget *, const DomWidgets &); 50 | 51 | // 52 | // custom widgets 53 | // 54 | void acceptCustomWidgets(DomCustomWidgets *node); 55 | void acceptCustomWidget(DomCustomWidget *node); 56 | 57 | // 58 | // include hints 59 | // 60 | void acceptIncludes(DomIncludes *node); 61 | void acceptInclude(DomInclude *node); 62 | 63 | bool scriptsActivated() const { return m_scriptsActivated; } 64 | 65 | private: 66 | void add(const QString &className, bool determineHeader = true); 67 | 68 | private: 69 | typedef QMap OrderedSet; 70 | void insertIncludeForClass(const QString &className); 71 | void insertIncludeForPackage(const QString &packageName); 72 | void activateScripts(); 73 | 74 | void writeHeaders(const OrderedSet &headers); 75 | 76 | const Uic *m_uic; 77 | QTextStream &m_output; 78 | 79 | QSet m_knownClasses; 80 | QSet m_knownPackages; 81 | 82 | typedef QMap StringMap; 83 | StringMap m_classModule; 84 | 85 | OrderedSet m_requires; 86 | 87 | 88 | bool m_scriptsActivated; 89 | bool m_laidOut; 90 | }; 91 | 92 | } // namespace CPP 93 | 94 | QT_END_NAMESPACE 95 | 96 | #endif // CPPWRITEINCLUDES_H 97 | -------------------------------------------------------------------------------- /modules/uic/src/lua/luawritedeclaration.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #include "luawritedeclaration.h" 23 | //#include "luawriteicondeclaration.h" 24 | #include "luawriteinitialization.h" 25 | //#include "luawriteiconinitialization.h" 26 | //#include "luaextractimages.h" 27 | #include "../driver.h" 28 | #include "../ui4.h" 29 | #include "../uic.h" 30 | #include "../databaseinfo.h" 31 | #include "../customwidgetsinfo.h" 32 | 33 | #include 34 | #include 35 | 36 | QT_BEGIN_NAMESPACE 37 | 38 | namespace LUA { 39 | 40 | WriteDeclaration::WriteDeclaration(Uic *uic) : 41 | m_uic(uic), 42 | m_driver(uic->driver()), 43 | out(uic->output()), 44 | m_option(uic->option()) 45 | { 46 | } 47 | 48 | void WriteDeclaration::acceptUI(DomUI *node) 49 | { 50 | QString qualifiedClassName = node->elementClass() + m_option.postfix; 51 | QString className = qualifiedClassName; 52 | 53 | QString varName = m_driver->findOrInsertWidget(node->elementWidget()); 54 | QString widgetClassName = node->elementWidget()->attributeClass(); 55 | 56 | out << "local ui_" << className << " = {}\n"; 57 | 58 | TreeWalker::acceptWidget(node->elementWidget()); 59 | 60 | WriteInitialization(m_uic).acceptUI(node); 61 | 62 | out << "return ui_" << className << "\n"; 63 | 64 | } 65 | 66 | void WriteDeclaration::acceptWidget(DomWidget *node) 67 | { 68 | TreeWalker::acceptWidget(node); 69 | } 70 | 71 | void WriteDeclaration::acceptSpacer(DomSpacer *node) 72 | { 73 | TreeWalker::acceptSpacer(node); 74 | } 75 | 76 | void WriteDeclaration::acceptLayout(DomLayout *node) 77 | { 78 | TreeWalker::acceptLayout(node); 79 | } 80 | 81 | void WriteDeclaration::acceptActionGroup(DomActionGroup *node) 82 | { 83 | TreeWalker::acceptActionGroup(node); 84 | } 85 | 86 | void WriteDeclaration::acceptAction(DomAction *node) 87 | { 88 | TreeWalker::acceptAction(node); 89 | } 90 | 91 | void WriteDeclaration::acceptButtonGroup(const DomButtonGroup *buttonGroup) 92 | { 93 | TreeWalker::acceptButtonGroup(buttonGroup); 94 | } 95 | 96 | } // namespace CPP 97 | 98 | QT_END_NAMESPACE 99 | -------------------------------------------------------------------------------- /modules/uic/src/databaseinfo.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef DATABASEINFO_H 43 | #define DATABASEINFO_H 44 | 45 | #include "treewalker.h" 46 | #include 47 | #include 48 | 49 | QT_BEGIN_NAMESPACE 50 | 51 | class Driver; 52 | 53 | class DatabaseInfo : public TreeWalker 54 | { 55 | public: 56 | DatabaseInfo(); 57 | 58 | void acceptUI(DomUI *node); 59 | void acceptWidget(DomWidget *node); 60 | 61 | inline QStringList connections() const 62 | { return m_connections; } 63 | 64 | inline QStringList cursors(const QString &connection) const 65 | { return m_cursors.value(connection); } 66 | 67 | inline QStringList fields(const QString &connection) const 68 | { return m_fields.value(connection); } 69 | 70 | private: 71 | QStringList m_connections; 72 | QMap m_cursors; 73 | QMap m_fields; 74 | }; 75 | 76 | QT_END_NAMESPACE 77 | 78 | #endif // DATABASEINFO_H 79 | -------------------------------------------------------------------------------- /modules/uic/src/validator.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #include "validator.h" 43 | #include "driver.h" 44 | #include "ui4.h" 45 | #include "uic.h" 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | Validator::Validator(Uic *uic) : 50 | m_driver(uic->driver()) 51 | { 52 | } 53 | 54 | void Validator::acceptUI(DomUI *node) 55 | { 56 | TreeWalker::acceptUI(node); 57 | } 58 | 59 | void Validator::acceptWidget(DomWidget *node) 60 | { 61 | (void) m_driver->findOrInsertWidget(node); 62 | 63 | TreeWalker::acceptWidget(node); 64 | } 65 | 66 | void Validator::acceptLayoutItem(DomLayoutItem *node) 67 | { 68 | (void) m_driver->findOrInsertLayoutItem(node); 69 | 70 | TreeWalker::acceptLayoutItem(node); 71 | } 72 | 73 | void Validator::acceptLayout(DomLayout *node) 74 | { 75 | (void) m_driver->findOrInsertLayout(node); 76 | 77 | TreeWalker::acceptLayout(node); 78 | } 79 | 80 | void Validator::acceptActionGroup(DomActionGroup *node) 81 | { 82 | (void) m_driver->findOrInsertActionGroup(node); 83 | 84 | TreeWalker::acceptActionGroup(node); 85 | } 86 | 87 | void Validator::acceptAction(DomAction *node) 88 | { 89 | (void) m_driver->findOrInsertAction(node); 90 | 91 | TreeWalker::acceptAction(node); 92 | } 93 | 94 | QT_END_NAMESPACE 95 | -------------------------------------------------------------------------------- /modules/uic/src/customwidgetsinfo.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef CUSTOMWIDGETSINFO_H 43 | #define CUSTOMWIDGETSINFO_H 44 | 45 | #include "treewalker.h" 46 | #include 47 | #include 48 | 49 | QT_BEGIN_NAMESPACE 50 | 51 | class Driver; 52 | class DomScript; 53 | 54 | class CustomWidgetsInfo : public TreeWalker 55 | { 56 | public: 57 | CustomWidgetsInfo(); 58 | 59 | void acceptUI(DomUI *node); 60 | 61 | void acceptCustomWidgets(DomCustomWidgets *node); 62 | void acceptCustomWidget(DomCustomWidget *node); 63 | 64 | inline QStringList customWidgets() const 65 | { return m_customWidgets.keys(); } 66 | 67 | inline bool hasCustomWidget(const QString &name) const 68 | { return m_customWidgets.contains(name); } 69 | 70 | inline DomCustomWidget *customWidget(const QString &name) const 71 | { return m_customWidgets.value(name); } 72 | 73 | DomScript *customWidgetScript(const QString &name) const; 74 | 75 | QString customWidgetAddPageMethod(const QString &name) const; 76 | 77 | QString realClassName(const QString &className) const; 78 | 79 | bool extends(const QString &className, QLatin1String baseClassName) const; 80 | 81 | bool isCustomWidgetContainer(const QString &className) const; 82 | 83 | private: 84 | typedef QMap NameCustomWidgetMap; 85 | NameCustomWidgetMap m_customWidgets; 86 | }; 87 | 88 | QT_END_NAMESPACE 89 | 90 | #endif // CUSTOMWIDGETSINFO_H 91 | -------------------------------------------------------------------------------- /modules/mocreader/src/parser.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #include "parser.h" 43 | #include "utils.h" 44 | #include 45 | #include 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | #ifdef USE_LEXEM_STORE 50 | Symbol::LexemStore Symbol::lexemStore; 51 | #endif 52 | 53 | static const char *error_msg = 0; 54 | 55 | #ifdef Q_CC_MSVC 56 | #define ErrorFormatString "%s(%d): " 57 | #else 58 | #define ErrorFormatString "%s:%d: " 59 | #endif 60 | 61 | void Parser::error(int rollback) { 62 | index -= rollback; 63 | error(); 64 | } 65 | void Parser::error(const char *msg) { 66 | if (msg || error_msg) 67 | fprintf(stderr, ErrorFormatString "Error: %s\n", 68 | currentFilenames.top().constData(), symbol().lineNum, msg?msg:error_msg); 69 | else 70 | fprintf(stderr, ErrorFormatString "Parse error at \"%s\"\n", 71 | currentFilenames.top().constData(), symbol().lineNum, symbol().lexem().data()); 72 | exit(EXIT_FAILURE); 73 | } 74 | 75 | void Parser::warning(const char *msg) { 76 | if (displayWarnings && msg) 77 | fprintf(stderr, ErrorFormatString "Warning: %s\n", 78 | currentFilenames.top().constData(), qMax(0, index > 0 ? symbol().lineNum : 0), msg); 79 | } 80 | 81 | void Parser::note(const char *msg) { 82 | if (displayNotes && msg) 83 | fprintf(stderr, ErrorFormatString "Note: %s\n", 84 | currentFilenames.top().constData(), qMax(0, index > 0 ? symbol().lineNum : 0), msg); 85 | } 86 | 87 | QT_END_NAMESPACE 88 | -------------------------------------------------------------------------------- /modules/uic/src/databaseinfo.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #include "databaseinfo.h" 43 | #include "driver.h" 44 | #include "ui4.h" 45 | #include "utils.h" 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | DatabaseInfo::DatabaseInfo() 50 | { 51 | } 52 | 53 | void DatabaseInfo::acceptUI(DomUI *node) 54 | { 55 | m_connections.clear(); 56 | m_cursors.clear(); 57 | m_fields.clear(); 58 | 59 | TreeWalker::acceptUI(node); 60 | 61 | m_connections = unique(m_connections); 62 | } 63 | 64 | void DatabaseInfo::acceptWidget(DomWidget *node) 65 | { 66 | QHash properties = propertyMap(node->elementProperty()); 67 | 68 | DomProperty *frameworkCode = properties.value(QLatin1String("frameworkCode"), 0); 69 | if (frameworkCode && toBool(frameworkCode->elementBool()) == false) 70 | return; 71 | 72 | DomProperty *db = properties.value(QLatin1String("database"), 0); 73 | if (db && db->elementStringList()) { 74 | QStringList info = db->elementStringList()->elementString(); 75 | 76 | QString connection = info.size() > 0 ? info.at(0) : QString(); 77 | if (connection.isEmpty()) 78 | return; 79 | m_connections.append(connection); 80 | 81 | QString table = info.size() > 1 ? info.at(1) : QString(); 82 | if (table.isEmpty()) 83 | return; 84 | m_cursors[connection].append(table); 85 | 86 | QString field = info.size() > 2 ? info.at(2) : QString(); 87 | if (field.isEmpty()) 88 | return; 89 | m_fields[connection].append(field); 90 | } 91 | 92 | TreeWalker::acceptWidget(node); 93 | } 94 | 95 | QT_END_NAMESPACE 96 | -------------------------------------------------------------------------------- /include/LuaQT/globals.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | // Utility functions 39 | inline void luaL_regfuncs(lua_State*L, luaL_Reg* reg, size_t count) 40 | { 41 | for (size_t i =0; i < count; ++i) 42 | { 43 | lua_pushcfunction(L, reg[i].func); 44 | lua_setfield(L, -2, reg[i].name); 45 | } 46 | } 47 | 48 | typedef struct luaQt_enumReg 49 | { 50 | const char *name; 51 | int value; 52 | } luaQt_enumReg; 53 | 54 | inline void luaL_regenumValues(lua_State*L, luaQt_enumReg* reg, size_t count) 55 | { 56 | for (size_t i = 0; i < count; ++i) 57 | { 58 | lua_pushinteger(L, reg[i].value); 59 | lua_setfield(L, -2, reg[i].name); 60 | } 61 | } 62 | 63 | #define luaL_newlib(l, m) lua_createtable(l, 0, sizeof(m)/sizeof(m[0]) - 1); luaL_regfuncs(l, m, sizeof(m)/sizeof(m[0]) - 1) 64 | #define STR(x) #x 65 | 66 | #define UNPACK_I(...) __VA_ARGS__ 67 | #define UNPACK__(p) UNPACK_I##p 68 | #define UNPACK(P) UNPACK__(P) 69 | 70 | #define CHECK_ARG_COUNT(c) if (lua_gettop(L) != c) { break; } 71 | #define CHECK_ARG(t, i) if (!LuaQt::ArgHelper::type>::CheckArg(L, i)) { break;} 72 | #define GET_ARG(t, i, n) LuaQt::remove_reference::type n = LuaQt::ArgHelper::type>::GetArg(L, i) 73 | 74 | #define CHECK_LUAFUNCTION_ARG(i) if (lua_iscfunction(L, i) || !lua_isfunction(L, i)) { break;} 75 | #define CHECK_USERDATA_ARG(i) if (!lua_isuserdata(L, i)) {break;} 76 | #define GET_USERDATA(t, i, n) UNPACK(t) n = reinterpret_cast(lua_touserdata(L, i)); 77 | 78 | #define START_ARGREF_FRAME() LuaQt::StartArgRefFrame(L) 79 | #define END_ARGREF_FRAME() LuaQt::EndArgRefFrame(L) 80 | #define PUSH_RET_VAL(t, v) LuaQt::ArgHelper::type>::type>::pushRetVal(L, v) 81 | 82 | 83 | namespace LuaQt{ 84 | template 85 | struct QObject_pointerTranser{ 86 | static int transer(lua_State *L) 87 | { 88 | void** a = (void**)lua_touserdata(L, 1); 89 | if (!a){ 90 | return luaL_error(L, "Invalid argument."); 91 | } 92 | int i = luaL_checkint(L, 2); 93 | LuaQt::PushObject(L, *(reinterpret_cast(a[i]))); 94 | return 1; 95 | } 96 | }; 97 | 98 | } 99 | -------------------------------------------------------------------------------- /modules/mocreader/build/msvc2012/mocreader/mocreader.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;cxx;c;def 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h 11 | 12 | 13 | {99349809-55BA-4b9d-BF79-8FDBB0286EB3} 14 | ui 15 | 16 | 17 | {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} 18 | qrc;* 19 | false 20 | 21 | 22 | {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} 23 | moc;h;cpp 24 | False 25 | 26 | 27 | {adb66571-1d8c-4df2-ac9a-77fa8d080764} 28 | cpp;moc 29 | False 30 | 31 | 32 | {6a57dad0-1482-4fa5-b6bb-4c0e0544ac93} 33 | cpp;moc 34 | False 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | 64 | 65 | Source Files 66 | 67 | 68 | Source Files 69 | 70 | 71 | Source Files 72 | 73 | 74 | Source Files 75 | 76 | 77 | Source Files 78 | 79 | 80 | Source Files 81 | 82 | 83 | Header Files 84 | 85 | 86 | 87 | 88 | Generated Files\Debug 89 | 90 | 91 | Generated Files\Release 92 | 93 | 94 | -------------------------------------------------------------------------------- /modules/uic/src/option.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef OPTION_H 43 | #define OPTION_H 44 | 45 | #include 46 | #include 47 | 48 | QT_BEGIN_NAMESPACE 49 | 50 | struct Option 51 | { 52 | enum Generator 53 | { 54 | CppGenerator, 55 | JavaGenerator, 56 | LuaGenerator 57 | }; 58 | 59 | unsigned int headerProtection : 1; 60 | unsigned int copyrightHeader : 1; 61 | unsigned int generateImplemetation : 1; 62 | unsigned int generateNamespace : 1; 63 | unsigned int autoConnection : 1; 64 | unsigned int dependencies : 1; 65 | unsigned int extractImages : 1; 66 | unsigned int limitXPM_LineLength : 1; 67 | unsigned int implicitIncludes: 1; 68 | Generator generator; 69 | 70 | QString inputFile; 71 | QString outputFile; 72 | QString qrcOutputFile; 73 | QString indent; 74 | QString prefix; 75 | QString postfix; 76 | QString translateFunction; 77 | QString uic3; 78 | #ifdef QT_UIC_JAVA_GENERATOR 79 | QString javaPackage; 80 | QString javaOutputDirectory; 81 | #endif 82 | 83 | Option() 84 | : headerProtection(1), 85 | copyrightHeader(1), 86 | generateImplemetation(0), 87 | generateNamespace(1), 88 | autoConnection(1), 89 | dependencies(0), 90 | extractImages(0), 91 | limitXPM_LineLength(0), 92 | implicitIncludes(1), 93 | generator(CppGenerator), 94 | prefix(QLatin1String("Ui_")) 95 | { indent.fill(QLatin1Char(' '), 4); } 96 | 97 | QString messagePrefix() const 98 | { 99 | return inputFile.isEmpty() ? 100 | QString(QLatin1String("stdin")) : 101 | QDir::toNativeSeparators(inputFile); 102 | } 103 | }; 104 | 105 | QT_END_NAMESPACE 106 | 107 | #endif // OPTION_H 108 | -------------------------------------------------------------------------------- /modules/mocreader/src/preprocessor.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef PREPROCESSOR_H 43 | #define PREPROCESSOR_H 44 | 45 | #include "parser.h" 46 | #include 47 | #include 48 | #include 49 | 50 | QT_BEGIN_NAMESPACE 51 | 52 | struct Macro 53 | { 54 | Macro() : isFunction(false), isVariadic(false) {} 55 | bool isFunction; 56 | bool isVariadic; 57 | Symbols arguments; 58 | Symbols symbols; 59 | }; 60 | 61 | #ifdef USE_LEXEM_STORE 62 | typedef QByteArray MacroName; 63 | #else 64 | typedef SubArray MacroName; 65 | #endif 66 | typedef QHash Macros; 67 | 68 | class QIODevice; 69 | 70 | class Preprocessor : public Parser 71 | { 72 | public: 73 | Preprocessor(){} 74 | static bool preprocessOnly; 75 | QList frameworks; 76 | QSet preprocessedIncludes; 77 | Macros macros; 78 | Symbols preprocessed(const QByteArray &filename, FILE *file); 79 | Symbols preprocessed(const QByteArray &filename, QIODevice *device); 80 | Symbols preprocessed(const QByteArray &filename, const QByteArray& data); 81 | 82 | void parseDefineArguments(Macro *m); 83 | 84 | void skipUntilEndif(); 85 | bool skipBranch(); 86 | 87 | void substituteUntilNewline(Symbols &substituted); 88 | static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName); 89 | static Symbols macroExpand(Preprocessor *that, Symbols &toExpand, int &index, int lineNum, bool one, 90 | const QSet &excludeSymbols = QSet()); 91 | 92 | int evaluateCondition(); 93 | 94 | 95 | private: 96 | void until(Token); 97 | 98 | void preprocess(const QByteArray &filename, Symbols &preprocessed); 99 | }; 100 | 101 | QT_END_NAMESPACE 102 | 103 | #endif // PREPROCESSOR_H 104 | -------------------------------------------------------------------------------- /modules/mocreader/src/utils.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef UTILS_H 43 | #define UTILS_H 44 | 45 | #include 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | inline bool is_whitespace(char s) 50 | { 51 | return (s == ' ' || s == '\t' || s == '\n'); 52 | } 53 | 54 | inline bool is_space(char s) 55 | { 56 | return (s == ' ' || s == '\t'); 57 | } 58 | 59 | inline bool is_ident_start(char s) 60 | { 61 | return ((s >= 'a' && s <= 'z') 62 | || (s >= 'A' && s <= 'Z') 63 | || s == '_' || s == '$' 64 | ); 65 | } 66 | 67 | inline bool is_ident_char(char s) 68 | { 69 | return ((s >= 'a' && s <= 'z') 70 | || (s >= 'A' && s <= 'Z') 71 | || (s >= '0' && s <= '9') 72 | || s == '_' || s == '$' 73 | ); 74 | } 75 | 76 | inline bool is_identifier(const char *s, int len) 77 | { 78 | if (len < 1) 79 | return false; 80 | if (!is_ident_start(*s)) 81 | return false; 82 | for (int i = 1; i < len; ++i) 83 | if (!is_ident_char(s[i])) 84 | return false; 85 | return true; 86 | } 87 | 88 | inline bool is_digit_char(char s) 89 | { 90 | return (s >= '0' && s <= '9'); 91 | } 92 | 93 | inline bool is_octal_char(char s) 94 | { 95 | return (s >= '0' && s <= '7'); 96 | } 97 | 98 | inline bool is_hex_char(char s) 99 | { 100 | return ((s >= 'a' && s <= 'f') 101 | || (s >= 'A' && s <= 'F') 102 | || (s >= '0' && s <= '9') 103 | ); 104 | } 105 | 106 | inline const char *skipQuote(const char *data) 107 | { 108 | while (*data && (*data != '\"')) { 109 | if (*data == '\\') { 110 | ++data; 111 | if (!*data) break; 112 | } 113 | ++data; 114 | } 115 | 116 | if (*data) //Skip last quote 117 | ++data; 118 | return data; 119 | } 120 | 121 | QT_END_NAMESPACE 122 | 123 | #endif // UTILS_H 124 | -------------------------------------------------------------------------------- /include/LuaQT/fix.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // fix of some special class 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | namespace LuaQt{ 47 | template <> 48 | struct is_qobject_ptr 49 | : public std::tr1::false_type 50 | { 51 | }; 52 | 53 | template <> 54 | struct is_qobject_ptr 55 | : public std::tr1::false_type 56 | { 57 | }; 58 | template <> 59 | struct is_qobject_ptr 60 | : public std::tr1::false_type 61 | { 62 | }; 63 | template <> 64 | struct is_qobject_ptr 65 | : public std::tr1::false_type 66 | { 67 | }; 68 | template <> 69 | struct is_qobject_ptr 70 | : public std::tr1::false_type 71 | { 72 | }; 73 | 74 | 75 | template <> 76 | struct is_qobject_ptr 77 | : public std::tr1::false_type 78 | { 79 | }; 80 | 81 | template <> 82 | struct is_qobject_ptr<_PROCESS_INFORMATION*> 83 | : public std::tr1::false_type 84 | { 85 | }; 86 | template <> 87 | struct is_qobject_ptr 88 | : public std::tr1::false_type 89 | { 90 | }; 91 | template <> 92 | struct is_qobject_ptr 93 | : public std::tr1::false_type 94 | { 95 | }; 96 | 97 | template <> 98 | struct is_qobject_ptr 99 | : public std::tr1::false_type 100 | { 101 | }; 102 | template <> 103 | struct is_qobject_ptr 104 | : public std::tr1::false_type 105 | { 106 | }; 107 | 108 | template <> 109 | struct is_qobject_ptr 110 | : public std::tr1::false_type 111 | { 112 | }; 113 | template <> 114 | struct is_qobject_ptr 115 | : public std::tr1::false_type 116 | { 117 | }; 118 | 119 | template <> 120 | struct is_qobject_ptr 121 | : public std::tr1::false_type 122 | { 123 | }; 124 | template <> 125 | struct is_qobject_ptr 126 | : public std::tr1::false_type 127 | { 128 | }; 129 | 130 | template <> 131 | struct is_qobject_ptr 132 | : public std::tr1::false_type 133 | { 134 | }; 135 | 136 | template <> 137 | struct is_qobject_ptr 138 | : public std::tr1::false_type 139 | { 140 | }; 141 | 142 | template <> 143 | struct is_qobject_ptr 144 | : public std::tr1::false_type 145 | { 146 | }; 147 | } 148 | -------------------------------------------------------------------------------- /src/LuaQt/weakref.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | 29 | namespace LuaQt{ 30 | static int s_key_weaktable = 0; 31 | 32 | static void push_weaktable(lua_State *L) 33 | { 34 | lua_pushlightuserdata(L, &s_key_weaktable); 35 | lua_rawget(L, LUA_REGISTRYINDEX); 36 | if (lua_isnil(L, -1)) { 37 | lua_pop(L, 1); 38 | 39 | lua_createtable(L, 0, 0); 40 | 41 | lua_createtable(L, 0, 1); 42 | lua_pushliteral(L, "v"); 43 | lua_setfield(L, -2, "__mode"); 44 | 45 | lua_setmetatable(L, -2); 46 | 47 | lua_pushinteger(L, 3); 48 | lua_rawseti(L, -2, 1); 49 | 50 | lua_pushinteger(L, 0); 51 | lua_rawseti(L, -2, 2); 52 | 53 | lua_pushlightuserdata(L, &s_key_weaktable); 54 | lua_pushvalue(L, -2); 55 | lua_rawset(L, LUA_REGISTRYINDEX); 56 | } 57 | } 58 | 59 | #define length 1 60 | #define freelist 2 61 | 62 | static int wref(lua_State *L, int t) 63 | { 64 | int ref; 65 | if (lua_isnil(L, -1)) { 66 | lua_pop(L, 1); /* remove from stack */ 67 | return LUA_REFNIL; /* `nil' has a unique fixed reference */ 68 | } 69 | lua_rawgeti(L, t, freelist); /* get first free element */ 70 | ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ 71 | lua_pop(L, 1); /* remove it from stack */ 72 | if (ref != 0) { /* any free element? */ 73 | lua_rawgeti(L, t, ref); /* remove it from list */ 74 | lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */ 75 | } 76 | else /* no free elements */ 77 | { 78 | lua_rawgeti(L, t, length); 79 | ref = (int)lua_tointeger(L, -1); 80 | lua_pop(L, 1); 81 | lua_pushinteger(L, ref+1); 82 | lua_rawseti(L, t, 1); 83 | } 84 | lua_rawseti(L, t, ref); 85 | return ref; 86 | } 87 | 88 | static void wunref (lua_State *L, int t, int ref) { 89 | if (ref >= 0) { 90 | lua_rawgeti(L, t, freelist); 91 | lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ 92 | lua_pushinteger(L, ref); 93 | lua_rawseti(L, t, freelist); /* t[freelist] = ref */ 94 | } 95 | } 96 | 97 | int Q_DECL_EXPORT weakref(lua_State *L) 98 | { 99 | push_weaktable(L); 100 | lua_insert(L, -2); 101 | int ret = wref(L, lua_gettop(L)-1); 102 | lua_pop(L, 1); 103 | return ret; 104 | } 105 | 106 | void Q_DECL_EXPORT getweakref(lua_State *L, int ref) 107 | { 108 | push_weaktable(L); 109 | lua_rawgeti(L, -1, ref); 110 | lua_remove(L, -2); 111 | 112 | //if (lua_isnil(L, -1)) 113 | //{ 114 | // luaL_error(L, "Weak!"); 115 | //} 116 | } 117 | 118 | void Q_DECL_EXPORT weakunref(lua_State *L, int ref) 119 | { 120 | if (ref > 0) 121 | { 122 | push_weaktable(L); 123 | wunref(L, lua_gettop(L), ref); 124 | lua_pop(L, 1); 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /modules/mocreader/src/parser.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef PARSER_H 43 | #define PARSER_H 44 | 45 | #include 46 | #include "symbols.h" 47 | 48 | QT_BEGIN_NAMESPACE 49 | 50 | class Parser 51 | { 52 | public: 53 | Parser():index(0), displayWarnings(true), displayNotes(true) {} 54 | Symbols symbols; 55 | int index; 56 | bool displayWarnings; 57 | bool displayNotes; 58 | 59 | struct IncludePath 60 | { 61 | inline explicit IncludePath(const QByteArray &_path) 62 | : path(_path), isFrameworkPath(false) {} 63 | QByteArray path; 64 | bool isFrameworkPath; 65 | }; 66 | QList includes; 67 | 68 | QStack currentFilenames; 69 | 70 | inline bool hasNext() const { return (index < symbols.size()); } 71 | inline Token next() { if (index >= symbols.size()) return NOTOKEN; return symbols.at(index++).token; } 72 | bool test(Token); 73 | void next(Token); 74 | void next(Token, const char *msg); 75 | inline void prev() {--index;} 76 | inline Token lookup(int k = 1); 77 | inline const Symbol &symbol_lookup(int k = 1) { return symbols.at(index-1+k);} 78 | inline Token token() { return symbols.at(index-1).token;} 79 | inline QByteArray lexem() { return symbols.at(index-1).lexem();} 80 | inline QByteArray unquotedLexem() { return symbols.at(index-1).unquotedLexem();} 81 | inline const Symbol &symbol() { return symbols.at(index-1);} 82 | 83 | void error(int rollback); 84 | void error(const char *msg = 0); 85 | void warning(const char * = 0); 86 | void note(const char * = 0); 87 | 88 | }; 89 | 90 | inline bool Parser::test(Token token) 91 | { 92 | if (index < symbols.size() && symbols.at(index).token == token) { 93 | ++index; 94 | return true; 95 | } 96 | return false; 97 | } 98 | 99 | inline Token Parser::lookup(int k) 100 | { 101 | const int l = index - 1 + k; 102 | return l < symbols.size() ? symbols.at(l).token : NOTOKEN; 103 | } 104 | 105 | inline void Parser::next(Token token) 106 | { 107 | if (!test(token)) 108 | error(); 109 | } 110 | 111 | inline void Parser::next(Token token, const char *msg) 112 | { 113 | if (!test(token)) 114 | error(msg); 115 | } 116 | 117 | QT_END_NAMESPACE 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /modules/path/path/impl_win.lua: -------------------------------------------------------------------------------- 1 | -- NOTICE: 2 | -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 3 | -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4 | -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5 | -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 6 | -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 7 | -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 8 | -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 9 | -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 10 | -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 11 | -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 12 | -- POSSIBILITY OF SUCH DAMAGE. 13 | -- 14 | -- read COPYRIGHT.md for more informations. 15 | 16 | local impl = {} 17 | local ffi = require("ffi") 18 | local C = ffi.C 19 | 20 | if (jit.arch=="x64") then 21 | ffi.cdef[[ 22 | typedef __int64 intptr_t; 23 | ]] 24 | elseif (jit.arch=="x86") then 25 | ffi.cdef[[ 26 | typedef int intptr_t; 27 | ]] 28 | else 29 | error("Unsupported architecture"..jit.arch) 30 | end 31 | 32 | ffi.cdef[[ 33 | void* malloc(size_t size); 34 | void free(void* data); 35 | char* _getcwd(char* buffer, int maxlen); 36 | 37 | 38 | typedef unsigned int _dev_t; /* device code */ 39 | typedef unsigned short _ino_t; /* i-node number (not used on DOS) */ 40 | typedef __int64 __time64_t; /* 64-bit time value */ 41 | 42 | typedef struct { 43 | _dev_t st_dev; 44 | _ino_t st_ino; 45 | unsigned short st_mode; 46 | short st_nlink; 47 | short st_uid; 48 | short st_gid; 49 | _dev_t st_rdev; 50 | __int64 st_size; 51 | __time64_t st_atime; 52 | __time64_t st_mtime; 53 | __time64_t st_ctime; 54 | } _stat64info; 55 | 56 | int __cdecl _stat64(const char * _Name, _stat64info * _Stat); 57 | 58 | extern int * __cdecl _errno(void); 59 | 60 | typedef struct { 61 | unsigned attrib; 62 | __time64_t time_create; /* -1 for FAT file systems */ 63 | __time64_t time_access; /* -1 for FAT file systems */ 64 | __time64_t time_write; 65 | __int64 size; 66 | char name[260]; 67 | } __finddata64_t; 68 | 69 | intptr_t __cdecl _findfirst64(const char * _Filename, __finddata64_t * _FindData); 70 | int __cdecl _findnext64(intptr_t _FindHandle, __finddata64_t * _FindData); 71 | 72 | int __cdecl _mkdir(const char * _Path); 73 | ]] 74 | 75 | function impl.current() 76 | local buff = C.malloc(256) 77 | local ret = ffi.string(C._getcwd(buff, 256)) 78 | C.free(buff) 79 | return ret 80 | end 81 | 82 | local function errno() 83 | return C._errno()[0] 84 | end 85 | 86 | function impl.stat(fn) 87 | local ret = ffi.new("_stat64info[1]") 88 | local iret = C._stat64(fn, ret); 89 | if (iret == 0) then 90 | return ret[0] 91 | end 92 | 93 | return nil, errno() 94 | end 95 | local stat = impl.stat 96 | 97 | function impl.isdir(fn) 98 | local st = stat(fn) 99 | return st and (bit.band(st.st_mode, 0x4000) ~= 0) 100 | end 101 | 102 | function impl.exists(fn) 103 | return stat(fn) and true or false 104 | end 105 | 106 | local function listFile(dir, filter) 107 | local pattern = require("path").normjoin(dir, "*") 108 | local ret = {} 109 | 110 | local c_file = ffi.new("__finddata64_t[1]") 111 | 112 | local handle = C._findfirst64(pattern, c_file); 113 | if (handle == -1) then 114 | return ret; 115 | end 116 | 117 | while true do 118 | if (filter(c_file)) then 119 | table.insert(ret, ffi.string(c_file[0].name)) 120 | end 121 | 122 | if (C._findnext64(handle, c_file) ~= 0) then 123 | return ret 124 | end 125 | end 126 | end 127 | 128 | function impl.listAll(dir) 129 | return listFile(dir, function() 130 | return true 131 | end) 132 | end 133 | 134 | function impl.listFiles(dir) 135 | return listFile(dir, function(cf) 136 | return bit.band(cf[0].attrib, 0x10) == 0 137 | end) 138 | end 139 | 140 | function impl.listSubdirs(dir) 141 | return listFile(dir, function(cf) 142 | return bit.band(cf[0].attrib, 0x10) ~= 0 143 | end) 144 | end 145 | 146 | function impl.mkdir(path) 147 | return C._mkdir(path) == 0 148 | end 149 | 150 | return impl -------------------------------------------------------------------------------- /modules/uic/src/customwidgetsinfo.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #include "customwidgetsinfo.h" 43 | #include "driver.h" 44 | #include "ui4.h" 45 | #include "utils.h" 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | CustomWidgetsInfo::CustomWidgetsInfo() 50 | { 51 | } 52 | 53 | void CustomWidgetsInfo::acceptUI(DomUI *node) 54 | { 55 | m_customWidgets.clear(); 56 | 57 | if (node->elementCustomWidgets()) 58 | acceptCustomWidgets(node->elementCustomWidgets()); 59 | } 60 | 61 | void CustomWidgetsInfo::acceptCustomWidgets(DomCustomWidgets *node) 62 | { 63 | TreeWalker::acceptCustomWidgets(node); 64 | } 65 | 66 | void CustomWidgetsInfo::acceptCustomWidget(DomCustomWidget *node) 67 | { 68 | if (node->elementClass().isEmpty()) 69 | return; 70 | 71 | m_customWidgets.insert(node->elementClass(), node); 72 | } 73 | 74 | bool CustomWidgetsInfo::extends(const QString &classNameIn, QLatin1String baseClassName) const 75 | { 76 | if (classNameIn == baseClassName) 77 | return true; 78 | 79 | QString className = classNameIn; 80 | while (const DomCustomWidget *c = customWidget(className)) { 81 | const QString extends = c->elementExtends(); 82 | if (className == extends) // Faulty legacy custom widget entries exist. 83 | return false; 84 | if (extends == baseClassName) 85 | return true; 86 | className = extends; 87 | } 88 | return false; 89 | } 90 | 91 | bool CustomWidgetsInfo::isCustomWidgetContainer(const QString &className) const 92 | { 93 | if (const DomCustomWidget *dcw = m_customWidgets.value(className, 0)) 94 | if (dcw->hasElementContainer()) 95 | return dcw->elementContainer() != 0; 96 | return false; 97 | } 98 | 99 | QString CustomWidgetsInfo::realClassName(const QString &className) const 100 | { 101 | if (className == QLatin1String("Line")) 102 | return QLatin1String("QFrame"); 103 | 104 | return className; 105 | } 106 | 107 | DomScript *CustomWidgetsInfo::customWidgetScript(const QString &name) const 108 | { 109 | if (m_customWidgets.empty()) 110 | return 0; 111 | 112 | const NameCustomWidgetMap::const_iterator it = m_customWidgets.constFind(name); 113 | if (it == m_customWidgets.constEnd()) 114 | return 0; 115 | 116 | return it.value()->elementScript(); 117 | } 118 | 119 | QString CustomWidgetsInfo::customWidgetAddPageMethod(const QString &name) const 120 | { 121 | if (DomCustomWidget *dcw = m_customWidgets.value(name, 0)) 122 | return dcw->elementAddPageMethod(); 123 | return QString(); 124 | } 125 | 126 | 127 | QT_END_NAMESPACE 128 | -------------------------------------------------------------------------------- /tools/codegen/template/class.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is generated by tools. It's still licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | /*% 32 | return depHeaders() 33 | %*/ 34 | 35 | #define CLASS_NAME STR(/*%return classname%*/) 36 | #define CLASS /*%return classname%*/ 37 | 38 | /*% 39 | if (not isAbstract) then 40 | return constructors() 41 | else 42 | return "" 43 | end 44 | %*/ 45 | 46 | /*% 47 | if (not isAbstract) then 48 | return extendedImpl() 49 | else 50 | return "" 51 | end 52 | %*/ 53 | 54 | /*% 55 | if (not isAbstract) then 56 | return extendedConstructor() 57 | else 58 | return "" 59 | end 60 | %*/ 61 | 62 | /*% 63 | return methodImpls() 64 | %*/ 65 | 66 | /*% 67 | return signalImpls() 68 | %*/ 69 | 70 | /*% 71 | return casters() 72 | %*/ 73 | 74 | /*% 75 | return declareExtraMethods() 76 | %*/ 77 | 78 | /*% 79 | return staticMethodsImpls() 80 | %*/ 81 | 82 | static luaL_Reg methods[] = { 83 | /*% 84 | return methodTable() 85 | %*/ 86 | /*% 87 | return signalTable() 88 | %*/ 89 | {NULL, NULL} 90 | }; 91 | 92 | /*% 93 | return declareInitSuperMethods() 94 | %*/ 95 | Q_DECL_EXPORT void /*%return classname%*/_initMethods(lua_State *L) 96 | { 97 | /*% 98 | return initSuperMethods() 99 | %*/ 100 | luaL_regfuncs(L, methods, sizeof(methods)/sizeof(luaL_Reg) - 1); 101 | } 102 | 103 | static luaQt_enumReg enumValues[] = { 104 | /*% 105 | return enumValues() 106 | %*/ 107 | {NULL, 0} 108 | }; 109 | 110 | static void init_enumValues(lua_State *L) 111 | { 112 | luaL_regenumValues(L, enumValues, sizeof(enumValues)/sizeof(enumValues[0]) - 1); 113 | } 114 | 115 | 116 | static luaL_Reg getters[] = { 117 | /*% 118 | return casterList() 119 | %*/ 120 | {NULL, NULL} 121 | }; 122 | 123 | static luaL_Reg setters[] = { 124 | {NULL, NULL} 125 | }; 126 | 127 | static luaL_Reg statics[] = { 128 | /*% 129 | if (not isAbstract) then 130 | return '\t{"new", ' .. classname .. '_constructor},' 131 | else 132 | return "" 133 | end 134 | %*/ 135 | /*% 136 | if (not isAbstract) then 137 | return '\t{"newExtended", ' .. classname .. '_constructorWithExtend},' 138 | else 139 | return "" 140 | end 141 | %*/ 142 | /*% 143 | return staticMethodsTable() 144 | %*/ 145 | {NULL, NULL} 146 | }; 147 | 148 | //static int __gc(lua_State *L) 149 | //{ 150 | // CLASS* p = (CLASS*)LuaQt::checkObject(L, 1, CLASS_NAME); 151 | // delete p; 152 | // return 0; 153 | //} 154 | 155 | void luadef_/*%return classname%*/(lua_State *L) 156 | { 157 | luaL_newlib(L, statics); 158 | 159 | init_enumValues(L); 160 | 161 | lua_pushlightuserdata(L, const_cast(reinterpret_cast(&CLASS::staticMetaObject))); 162 | lua_setfield(L, -2, "_metaObject"); 163 | 164 | // register meta table. 165 | if (!luaL_newmetatable(L, CLASS_NAME)) 166 | { 167 | // luaL_error(L, "Metatable "CLASS_NAME" has been registered."); 168 | return; 169 | } 170 | 171 | //luaL_newlib(L, methods); 172 | lua_createtable(L, 0, 0); 173 | /*%return classname%*/_initMethods(L); 174 | 175 | lua_pushvalue(L, -1); 176 | lua_setfield(L, -4, "methods"); 177 | 178 | luaL_newlib(L, getters); 179 | lua_pushvalue(L, -1); 180 | lua_setfield(L, -5, "getters"); 181 | 182 | lua_pushcclosure(L, LuaQt::General_index, 2); 183 | lua_setfield(L, -2, "__index"); 184 | 185 | luaL_newlib(L, setters); 186 | lua_pushcclosure(L, LuaQt::General_newindex, 1); 187 | lua_setfield(L, -2, "__newindex"); 188 | 189 | //lua_pushcfunction(L, __gc); 190 | //lua_setfield(L, -2, "__gc"); 191 | 192 | lua_pop(L, 1); 193 | 194 | lua_pushcfunction(L, LuaQt::QObject_pointerTranser::transer); 195 | lua_setfield(L, -2, "transPointerArg"); 196 | 197 | 198 | // register static table. 199 | lua_setglobal(L, CLASS_NAME); 200 | } 201 | -------------------------------------------------------------------------------- /modules/uic/src/uic.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef UIC_H 43 | #define UIC_H 44 | 45 | #include "databaseinfo.h" 46 | #include "customwidgetsinfo.h" 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | QT_BEGIN_NAMESPACE 54 | 55 | class QTextStream; 56 | class QIODevice; 57 | 58 | class Driver; 59 | class DomUI; 60 | class DomWidget; 61 | class DomSpacer; 62 | class DomLayout; 63 | class DomLayoutItem; 64 | class DomItem; 65 | 66 | struct Option; 67 | 68 | class Uic 69 | { 70 | public: 71 | Uic(Driver *driver); 72 | ~Uic(); 73 | 74 | bool printDependencies(); 75 | 76 | inline Driver *driver() const 77 | { return drv; } 78 | 79 | inline QTextStream &output() 80 | { return out; } 81 | 82 | // inline QTextStream &cl_output() 83 | // { return m_output_uitolua; } 84 | 85 | 86 | inline const Option &option() const 87 | { return opt; } 88 | 89 | inline QString pixmapFunction() const 90 | { return pixFunction; } 91 | 92 | inline void setPixmapFunction(const QString &f) 93 | { pixFunction = f; } 94 | 95 | inline bool hasExternalPixmap() const 96 | { return externalPix; } 97 | 98 | inline void setExternalPixmap(bool b) 99 | { externalPix = b; } 100 | 101 | inline const DatabaseInfo *databaseInfo() const 102 | { return &info; } 103 | 104 | inline const CustomWidgetsInfo *customWidgetsInfo() const 105 | { return &cWidgetsInfo; } 106 | 107 | //inline QTextStream &outputuitolua() 108 | // { return m_output_uitolua; } 109 | bool write(QIODevice *in); 110 | 111 | #ifdef QT_UIC_JAVA_GENERATOR 112 | bool jwrite(DomUI *ui); 113 | #endif 114 | 115 | #ifdef QT_UIC_CPP_GENERATOR 116 | bool write(DomUI *ui); 117 | #endif 118 | 119 | #ifdef QT_UIC_LUA_GENERATOR 120 | bool luawrite(DomUI *ui); 121 | #endif 122 | 123 | bool isMainWindow(const QString &className) const; 124 | bool isToolBar(const QString &className) const; 125 | bool isStatusBar(const QString &className) const; 126 | bool isButton(const QString &className) const; 127 | bool isContainer(const QString &className) const; 128 | bool isCustomWidgetContainer(const QString &className) const; 129 | bool isMenuBar(const QString &className) const; 130 | bool isMenu(const QString &className) const; 131 | 132 | private: 133 | // copyright header 134 | void writeCopyrightHeader(DomUI *ui); 135 | DomUI *parseUiFile(QXmlStreamReader &reader); 136 | 137 | #ifdef QT_UIC_CPP_GENERATOR 138 | // header protection 139 | void writeHeaderProtectionStart(); 140 | void writeHeaderProtectionEnd(); 141 | #endif 142 | 143 | private: 144 | Driver *drv; 145 | QTextStream &out; 146 | Option &opt; 147 | DatabaseInfo info; 148 | CustomWidgetsInfo cWidgetsInfo; 149 | QString pixFunction; 150 | bool externalPix; 151 | 152 | // QTextStream &m_output_uitolua; 153 | }; 154 | 155 | QT_END_NAMESPACE 156 | 157 | #endif // UIC_H 158 | -------------------------------------------------------------------------------- /src/LuaQt/objectlifecycle.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | // Currently, LuaJIT 2.0 has no __gc support for "table" type. 34 | // So do something ugly. 35 | // LuaJIT 2.1 will solve this problem. Do something then. 36 | namespace LuaQt{ 37 | 38 | Q_DECL_EXPORT bool isObject(lua_State *L, int idx, const char* className) 39 | { 40 | if (lua_isnil(L, idx)){ 41 | return true; 42 | } 43 | if (!lua_istable(L, idx)){ 44 | return false; 45 | } 46 | lua_getfield(L, idx, className); 47 | bool ret = lua_islightuserdata(L, -1); 48 | lua_pop(L, 1); 49 | return ret; 50 | } 51 | 52 | Q_DECL_EXPORT void* checkObject(lua_State *L, int idx, const char* className) 53 | { 54 | if (lua_isnil(L, idx)){ 55 | return NULL; 56 | } 57 | if (!lua_istable(L, idx)){ 58 | luaL_error(L, "Argument %d is not a `%s` object.", idx, className); 59 | } 60 | lua_getfield(L, idx, className); 61 | if (!lua_islightuserdata(L, -1)){ 62 | luaL_error(L, "Argument %d is not a `%s` object.", idx, className); 63 | } 64 | void* ret = lua_touserdata(L, -1); 65 | lua_pop(L, 1); 66 | return ret; 67 | } 68 | 69 | class QLuaQtUserData 70 | : public QObjectUserData 71 | { 72 | public: 73 | lua_State *L; 74 | int lua_ref; 75 | }; 76 | 77 | Q_DECL_EXPORT void PushObject(lua_State *L, QObject* obj) 78 | { 79 | QLuaQtUserData* userData = (QLuaQtUserData*) obj->userData(0); 80 | if (!userData){ 81 | InitAndPushObject(L, obj, obj, obj->metaObject()->className()); 82 | return; 83 | } 84 | getweakref(L, userData->lua_ref); 85 | } 86 | 87 | static void onDestroyed(QObject* obj) 88 | { 89 | QLuaQtUserData* userData = (QLuaQtUserData*) obj->userData(0); 90 | obj->setUserData(0, NULL); 91 | 92 | assert(userData); 93 | lua_State *L = userData->L; 94 | int ref = userData->lua_ref; 95 | getweakref(L, ref); 96 | delete userData; 97 | 98 | if (lua_istable(L, -1)){ 99 | weakunref(L, ref); 100 | //TODO: clean lightuserdata pointer in table. 101 | 102 | //remove gcer. 103 | lua_pushliteral(L, "__gcer"); 104 | lua_rawget(L, -2); 105 | QObject** ppobj = (QObject**)lua_touserdata(L, 1); 106 | if (ppobj) { 107 | *ppobj = NULL; 108 | } 109 | lua_pop(L, 1); 110 | 111 | lua_pop(L, 1); 112 | } else { 113 | lua_pop(L, 1); 114 | } 115 | } 116 | 117 | static int gcer(lua_State *L) 118 | { 119 | QObject** ppobj = (QObject**)lua_touserdata(L, 1); 120 | QObject* obj = *ppobj; 121 | *ppobj = NULL; 122 | delete obj; 123 | return 0; 124 | } 125 | 126 | #define GCer "LuaQtGCer" 127 | 128 | void Q_DECL_EXPORT InitGCer(lua_State *L) 129 | { 130 | luaL_newmetatable(L, GCer); 131 | lua_pushcfunction(L, gcer); 132 | lua_setfield(L, -2, "__gc"); 133 | lua_pop(L, 1); 134 | } 135 | 136 | Q_DECL_EXPORT void InitAndPushObject(lua_State *L, QObject* obj, void* ptr, const char* className) 137 | { 138 | // create object. 139 | lua_createtable(L, 0, 1); 140 | lua_pushstring(L, className); 141 | lua_pushlightuserdata(L, ptr); 142 | lua_rawset(L, -3); 143 | 144 | lua_pushliteral(L, "__gcer"); 145 | QObject** ppobj = (QObject**)lua_newuserdata(L, sizeof(QObject*)); 146 | (*ppobj) = obj; 147 | luaL_getmetatable(L, GCer); 148 | lua_setmetatable(L, -2); 149 | lua_rawset(L, -3); 150 | 151 | luaL_getmetatable(L, className); 152 | if (lua_isnil(L, -1)){ 153 | luaL_error(L, "Cannot find class %s. ", className); 154 | } 155 | lua_setmetatable(L, -2); 156 | 157 | // listen "destroyed" signal 158 | obj->connect(obj, &QObject::destroyed, onDestroyed); 159 | 160 | // get weak reference id. 161 | // There's no LUA_RIDX_MAINTHREAD in luajit now, 162 | // so DONOT require any module in coroutine thread! 163 | QLuaQtUserData* userData = new QLuaQtUserData(); 164 | userData->L = getGlobalState(L); 165 | lua_pushvalue(L, -1); 166 | userData->lua_ref = weakref(L); 167 | obj->setUserData(0, userData); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /modules/uic/src/driver.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef DRIVER_H 43 | #define DRIVER_H 44 | 45 | #include "option.h" 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | QT_BEGIN_NAMESPACE 52 | 53 | class QTextStream; 54 | class DomUI; 55 | class DomWidget; 56 | class DomSpacer; 57 | class DomLayout; 58 | class DomLayoutItem; 59 | class DomActionGroup; 60 | class DomAction; 61 | class DomButtonGroup; 62 | 63 | class Driver 64 | { 65 | public: 66 | Driver(); 67 | virtual ~Driver(); 68 | 69 | // tools 70 | bool printDependencies(const QString &fileName); 71 | bool uic(const QString &fileName, QTextStream *output = 0); 72 | bool uic(const QString &fileName, DomUI *ui, QTextStream *output = 0); 73 | 74 | // configuration 75 | inline QTextStream &output() const { return *m_output; } 76 | inline Option &option() { return m_option; } 77 | 78 | // initialization 79 | void reset(); 80 | 81 | // error 82 | inline QStringList problems() { return m_problems; } 83 | inline void addProblem(const QString &problem) { m_problems.append(problem); } 84 | 85 | // utils 86 | static QString headerFileName(const QString &fileName); 87 | QString headerFileName() const; 88 | 89 | static QString normalizedName(const QString &name); 90 | static QString qtify(const QString &name); 91 | QString unique(const QString &instanceName=QString(), 92 | const QString &className=QString()); 93 | 94 | // symbol table 95 | QString findOrInsertWidget(DomWidget *ui_widget); 96 | QString findOrInsertSpacer(DomSpacer *ui_spacer); 97 | QString findOrInsertLayout(DomLayout *ui_layout); 98 | QString findOrInsertLayoutItem(DomLayoutItem *ui_layoutItem); 99 | QString findOrInsertName(const QString &name); 100 | QString findOrInsertActionGroup(DomActionGroup *ui_group); 101 | QString findOrInsertAction(DomAction *ui_action); 102 | QString findOrInsertButtonGroup(const DomButtonGroup *ui_group); 103 | // Find a group by its non-uniqified name 104 | const DomButtonGroup *findButtonGroup(const QString &attributeName) const; 105 | 106 | inline bool hasName(const QString &name) const 107 | { return m_nameRepository.contains(name); } 108 | 109 | DomWidget *widgetByName(const QString &name) const; 110 | DomSpacer *spacerByName(const QString &name) const; 111 | DomLayout *layoutByName(const QString &name) const; 112 | DomActionGroup *actionGroupByName(const QString &name) const; 113 | DomAction *actionByName(const QString &name) const; 114 | 115 | // pixmap 116 | void insertPixmap(const QString &pixmap); 117 | bool containsPixmap(const QString &pixmap) const; 118 | 119 | private: 120 | Option m_option; 121 | QTextStream m_stdout; 122 | QTextStream *m_output; 123 | 124 | QStringList m_problems; 125 | 126 | // symbol tables 127 | QHash m_widgets; 128 | QHash m_spacers; 129 | QHash m_layouts; 130 | QHash m_actionGroups; 131 | typedef QHash ButtonGroupNameHash; 132 | ButtonGroupNameHash m_buttonGroups; 133 | QHash m_actions; 134 | QHash m_nameRepository; 135 | QHash m_pixmaps; 136 | }; 137 | 138 | QT_END_NAMESPACE 139 | 140 | #endif // DRIVER_H 141 | -------------------------------------------------------------------------------- /src/LuaQt/luaqt.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: https://github.com/tdzl2003/luaqt 5 | ** 6 | ** This file is part of the LuaQt Toolkit source. 7 | ** 8 | ** This file is licensed at BSD New license. 9 | ** 10 | ** NOTICE: 11 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15 | ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16 | ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 17 | ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 18 | ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 19 | ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 21 | ** POSSIBILITY OF SUCH DAMAGE.** 22 | ** 23 | ** read COPYRIGHT.md for more informations. 24 | ** 25 | ****************************************************************************/ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | static int luaqt_getTypeId(lua_State *L) 39 | { 40 | const char* tn = luaL_checkstring(L, 1); 41 | int ret = QMetaType::type(tn); 42 | if (ret >= QMetaType::FirstCoreType && ret <= QMetaType::HighestInternalId){ 43 | lua_pushinteger(L, ret); 44 | return 1; 45 | } 46 | return 0; 47 | } 48 | 49 | static void null_qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 50 | { 51 | 52 | } 53 | 54 | static int luaqt_defineMetaObject(lua_State *L) 55 | { 56 | size_t strcount = 0; 57 | size_t totallen = 0; 58 | 59 | strcount = lua_objlen(L, 1); 60 | for (size_t i = 0; i < strcount; i++){ 61 | lua_rawgeti(L, 1, i+1); 62 | totallen += lua_objlen(L, -1) +1; 63 | lua_pop(L, 1); 64 | } 65 | LuaQt::generic_callback* metaCall = new LuaQt::generic_callback(L); 66 | 67 | size_t datalen = lua_objlen(L, 2); 68 | char* data = (char*)lua_newuserdata(L, sizeof(QMetaObject) + sizeof(uint)*datalen + sizeof(QByteArrayData)*strcount + totallen ); 69 | 70 | QMetaObject* obj = reinterpret_cast(data); 71 | uint* metadata = reinterpret_cast(data + sizeof(QMetaObject)); 72 | QByteArrayData* stringdata = reinterpret_cast(data + sizeof(QMetaObject) + sizeof(uint)*datalen); 73 | char* strings = reinterpret_cast(data + sizeof(QMetaObject) + sizeof(uint)*datalen + sizeof(QByteArrayData)*strcount); 74 | 75 | { 76 | QMetaObject defineobj = { 77 | { 78 | reinterpret_cast(lua_touserdata(L, 3)), 79 | stringdata, 80 | metadata, 81 | NULL, 82 | 0, 83 | metaCall 84 | } 85 | }; 86 | *obj = defineobj; 87 | } 88 | 89 | for (size_t i = 0; i < datalen; i++){ 90 | lua_rawgeti(L, 2, i+1); 91 | metadata[i] = lua_tointeger(L, -1); 92 | lua_pop(L, 1); 93 | } 94 | 95 | { 96 | char* ptr = strings; 97 | for (size_t i = 0; i < strcount; i++){ 98 | lua_rawgeti(L, 1, i+1); 99 | size_t len; 100 | const char* str = luaL_checklstring(L, -1, &len); 101 | memcpy(ptr, str, len); 102 | QByteArrayData tmp = { 103 | Q_REFCOUNT_INITIALIZE_STATIC, len, 0, 0, reinterpret_cast(ptr) - reinterpret_cast(stringdata+i) 104 | }; 105 | stringdata[i] = tmp; 106 | ptr += len; 107 | *(ptr++) = 0; 108 | lua_pop(L, 1); 109 | } 110 | } 111 | 112 | 113 | return 1; 114 | } 115 | 116 | static int luaqt_activateSignal(lua_State *L) 117 | { 118 | for (;;) 119 | { 120 | CHECK_ARG_COUNT(4); 121 | CHECK_ARG((QObject*), 1); 122 | CHECK_USERDATA_ARG(2); 123 | CHECK_ARG((int), 3); 124 | 125 | START_ARGREF_FRAME(); 126 | GET_ARG((QObject*), 1, arg1); 127 | GET_USERDATA((const QMetaObject*), 2, arg2); 128 | GET_ARG((int), 3, arg3); 129 | 130 | void *_a[] = { 0 }; 131 | QMetaObject::activate(arg1, arg2, arg3, _a); 132 | 133 | END_ARGREF_FRAME(); 134 | return 0; 135 | } 136 | 137 | return luaL_error(L, "No valid overloads found"); 138 | } 139 | 140 | static luaL_Reg luaqt_lib[] = { 141 | {"getTypeId", luaqt_getTypeId}, 142 | {"defineMetaObject", luaqt_defineMetaObject}, 143 | {"activate", luaqt_activateSignal}, 144 | {NULL, NULL} 145 | }; 146 | 147 | template 148 | struct General_argTranser{ 149 | static int transer(lua_State *L) 150 | { 151 | void** a = (void**)lua_touserdata(L, 1); 152 | if (!a){ 153 | return luaL_error(L, "Invalid argument."); 154 | } 155 | int i = luaL_checkint(L, 2); 156 | LuaQt::ArgHelper::pushRetVal(L, *(reinterpret_cast(a[i]))); 157 | return 1; 158 | } 159 | }; 160 | 161 | #define GEN_TRANSTYPE(type) {#type, General_argTranser::transer} 162 | 163 | static luaL_Reg luaqt_argTranser[] = { 164 | GEN_TRANSTYPE(bool), 165 | GEN_TRANSTYPE(int), 166 | GEN_TRANSTYPE(QString), 167 | {NULL, NULL} 168 | }; 169 | 170 | extern "C" Q_DECL_EXPORT int luaopen_LuaQt(lua_State*L) 171 | { 172 | LuaQt::saveGlobalState(L); 173 | LuaQt::InitGCer(L); 174 | 175 | luaL_newlib(L, luaqt_lib); 176 | 177 | luaL_newlib(L, luaqt_argTranser); 178 | lua_setfield(L, -2, "transArg"); 179 | return 1; 180 | } 181 | -------------------------------------------------------------------------------- /modules/uic/src/treewalker.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef TREEWALKER_H 43 | #define TREEWALKER_H 44 | 45 | #include 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | class DomUI; 50 | class DomLayoutDefault; 51 | class DomLayoutFunction; 52 | class DomTabStops; 53 | class DomLayout; 54 | class DomLayoutItem; 55 | class DomWidget; 56 | class DomSpacer; 57 | class DomColor; 58 | class DomColorGroup; 59 | class DomPalette; 60 | class DomFont; 61 | class DomPoint; 62 | class DomRect; 63 | class DomSizePolicy; 64 | class DomSize; 65 | class DomDate; 66 | class DomTime; 67 | class DomDateTime; 68 | class DomProperty; 69 | class DomCustomWidgets; 70 | class DomCustomWidget; 71 | class DomAction; 72 | class DomActionGroup; 73 | class DomActionRef; 74 | class DomImages; 75 | class DomImage; 76 | class DomItem; 77 | class DomIncludes; 78 | class DomInclude; 79 | class DomString; 80 | class DomResourcePixmap; 81 | class DomResources; 82 | class DomResource; 83 | class DomConnections; 84 | class DomConnection; 85 | class DomConnectionHints; 86 | class DomConnectionHint; 87 | class DomScript; 88 | class DomButtonGroups; 89 | class DomButtonGroup; 90 | 91 | struct TreeWalker 92 | { 93 | inline virtual ~TreeWalker() {} 94 | 95 | virtual void acceptUI(DomUI *ui); 96 | virtual void acceptLayoutDefault(DomLayoutDefault *layoutDefault); 97 | virtual void acceptLayoutFunction(DomLayoutFunction *layoutFunction); 98 | virtual void acceptTabStops(DomTabStops *tabStops); 99 | virtual void acceptCustomWidgets(DomCustomWidgets *customWidgets); 100 | virtual void acceptCustomWidget(DomCustomWidget *customWidget); 101 | virtual void acceptLayout(DomLayout *layout); 102 | virtual void acceptLayoutItem(DomLayoutItem *layoutItem); 103 | virtual void acceptWidget(DomWidget *widget); 104 | virtual void acceptSpacer(DomSpacer *spacer); 105 | virtual void acceptColor(DomColor *color); 106 | virtual void acceptColorGroup(DomColorGroup *colorGroup); 107 | virtual void acceptPalette(DomPalette *palette); 108 | virtual void acceptFont(DomFont *font); 109 | virtual void acceptPoint(DomPoint *point); 110 | virtual void acceptRect(DomRect *rect); 111 | virtual void acceptSizePolicy(DomSizePolicy *sizePolicy); 112 | virtual void acceptSize(DomSize *size); 113 | virtual void acceptDate(DomDate *date); 114 | virtual void acceptTime(DomTime *time); 115 | virtual void acceptDateTime(DomDateTime *dateTime); 116 | virtual void acceptProperty(DomProperty *property); 117 | typedef QList DomScripts; 118 | typedef QList DomWidgets; 119 | virtual void acceptWidgetScripts(const DomScripts &, DomWidget *node, const DomWidgets &childWidgets); 120 | virtual void acceptImages(DomImages *images); 121 | virtual void acceptImage(DomImage *image); 122 | virtual void acceptIncludes(DomIncludes *includes); 123 | virtual void acceptInclude(DomInclude *incl); 124 | virtual void acceptAction(DomAction *action); 125 | virtual void acceptActionGroup(DomActionGroup *actionGroup); 126 | virtual void acceptActionRef(DomActionRef *actionRef); 127 | virtual void acceptConnections(DomConnections *connections); 128 | virtual void acceptConnection(DomConnection *connection); 129 | virtual void acceptConnectionHints(DomConnectionHints *connectionHints); 130 | virtual void acceptConnectionHint(DomConnectionHint *connectionHint); 131 | virtual void acceptButtonGroups(const DomButtonGroups *buttonGroups); 132 | virtual void acceptButtonGroup(const DomButtonGroup *buttonGroup); 133 | }; 134 | 135 | QT_END_NAMESPACE 136 | 137 | #endif // TREEWALKER_H 138 | -------------------------------------------------------------------------------- /modules/luaqtml/luaqtml.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2013 tdzl2003. 2 | -- Contact: https://github.com/tdzl2003/luaqt 3 | 4 | -- This file is part of the LuaQt Toolkit source. 5 | 6 | -- This file is licensed at BSD New license. 7 | 8 | -- NOTICE: 9 | -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 10 | -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 11 | -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 12 | -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 13 | -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 14 | -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 15 | -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 16 | -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 17 | -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 18 | -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 19 | -- POSSIBILITY OF SUCH DAMAGE. 20 | 21 | -- read COPYRIGHT.md for more informations. 22 | 23 | require("QtCore") 24 | local LuaQtHelper = require("LuaQtHelper") 25 | require("luaqttypes") 26 | 27 | function requireUI(path) 28 | return loadstring(require("uic").run(path))() 29 | end 30 | 31 | local function transArg(f) 32 | return function() 33 | local cmd, args = f() 34 | if (not cmd) then 35 | return 36 | end 37 | local ret = {} 38 | for v in args:gmatch("[^%s]+") do 39 | table.insert(ret, v) 40 | end 41 | if (#ret > 0) then 42 | return cmd, ret 43 | end 44 | return cmd 45 | end 46 | end 47 | 48 | local function parseFunction(match, typename) 49 | local name 50 | local argtypes = {} 51 | local rettype 52 | for cmd, args in match do 53 | if (cmd == "name") then 54 | name = args[1] or error("Missing argument for @name") 55 | elseif (cmd == "argument") then 56 | table.insert(argtypes, args[1] or error("Missing argument for @argument")) 57 | elseif (cmd == "return") then 58 | rettype = args[1] or error("Missing argument for @return") 59 | elseif (cmd == "end") then 60 | assert(not args or args[1] == typename) 61 | break 62 | end 63 | end 64 | return name, argtypes, rettype or "void" 65 | end 66 | 67 | local function parseConstructor(args, Class, match, define) 68 | local name, argtypes = parseFunction(match, "constructor") 69 | name = name or (args and args[1]) or error("Missing argument or @name for @constructor") 70 | local func = define[name] or error("Missing function definition"..name) 71 | 72 | 73 | local env = {} 74 | local super = Class.superClass 75 | local mo, self 76 | function env.super(...) 77 | self = super.newExtended(mo, ...) 78 | 79 | return self 80 | end 81 | 82 | setmetatable(env, {__index=_G}) 83 | 84 | if (_VERSION == "Lua 5.1") then 85 | debug.setfenv(func, env) 86 | else 87 | debug.setupvalue(func, 1, env) 88 | end 89 | LuaQtHelper.addConstructor(Class, argtypes, function(_mo, ...) 90 | mo = _mo 91 | func(...) 92 | return self or error("super() was not called in constructor") 93 | end) 94 | end 95 | 96 | local function parseSlot(args, Class, match, define) 97 | local name, argtypes, rettype = parseFunction(match, "slot") 98 | local slotname = (args and args[1]) or error("Missing argument for @slot. @name for @slot used only for overloads.") 99 | name = name or slotname 100 | LuaQtHelper.addSlot(Class, rettype, slotname, argtypes, define[name] or error("Missing function definition"..name)) 101 | end 102 | 103 | local function parseSignal(args, Class, match, define) 104 | local name, argtypes, rettype = parseFunction(match, "signal") 105 | name = name or (args and args[1]) or error("Missing argument or @name for @signal") 106 | LuaQtHelper.addSignal(Class, rettype, name, argtypes) 107 | end 108 | 109 | local function parseMethod(args, Class, match, define) 110 | local name, argtypes, rettype = parseFunction(match, "method") 111 | local methodname = (args and args[1]) or error("Missing argument for @slot. @name for @method used only for overloads.") 112 | name = name or methodname 113 | LuaQtHelper.addMethod(Class, rettype, methodname, argtypes, define[name] or error("Missing function definition"..name)) 114 | end 115 | 116 | local function parseClass(args, match, define, ret) 117 | local Class = { 118 | className = args[1] or error("Missing argument for @class"), 119 | superClass = QObject 120 | } 121 | define = define[Class.className] 122 | for cmd,args in match do 123 | if (cmd == "extends") then 124 | Class.superClass = _G[args[1]] or error("Cannot find super class "+args[1]) 125 | elseif (cmd == "constructor") then 126 | parseConstructor(args, Class, match, define) 127 | elseif (cmd == "slot") then 128 | parseSlot(args, Class, match, define) 129 | elseif (cmd == "signal") then 130 | parseSignal(args, Class, match, define) 131 | elseif (cmd=="method") then 132 | parseMethod(args, Class, match, define) 133 | elseif (cmd=="end") then 134 | assert(not args or args[1] == "class") 135 | break 136 | end 137 | end 138 | 139 | Class = LuaQtHelper.defineQtClass(Class) 140 | _G[Class.className] = _G[Class.className] or Class 141 | ret[Class.className] = Class 142 | return Class 143 | end 144 | 145 | function requireQtModule(module) 146 | if (package.loaded[module]) then 147 | return package.loaded[module] 148 | end 149 | local path, err = package.searchpath(module, package.path) 150 | if (not path) then 151 | error("Cannot find module "..module..":"..err) 152 | end 153 | 154 | local content 155 | do 156 | -- read the whole file content 157 | local fd = io.open(path) 158 | content = fd:read("*a") 159 | fd:close() 160 | fd = nil 161 | end 162 | 163 | local define = loadstring(content)(module) 164 | 165 | local match = transArg(content:gmatch("%\n%-%-%s-%@%s-(%w+)([^\n]*)")) 166 | 167 | if (match() ~= "luaqt") then 168 | error("Module "..module.." does not looks like a LuaQt Module.") 169 | end 170 | 171 | local ret = {} 172 | for cmd, args in match do 173 | if (cmd == "class") then 174 | parseClass(args, match, define, ret) 175 | end 176 | end 177 | package.loaded[module] = ret 178 | return ret 179 | end 180 | -------------------------------------------------------------------------------- /modules/mocreader/src/token.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef TOKEN_H 43 | #define TOKEN_H 44 | 45 | #include 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | enum Token { 50 | NOTOKEN, 51 | IDENTIFIER, 52 | INTEGER_LITERAL, 53 | CHARACTER_LITERAL, 54 | STRING_LITERAL, 55 | BOOLEAN_LITERAL, 56 | HEADER_NAME, 57 | LANGLE, 58 | RANGLE, 59 | LPAREN, 60 | RPAREN, 61 | ELIPSIS, 62 | LBRACK, 63 | RBRACK, 64 | LBRACE, 65 | RBRACE, 66 | EQ, 67 | SCOPE, 68 | SEMIC, 69 | COLON, 70 | DOTSTAR, 71 | QUESTION, 72 | DOT, 73 | DYNAMIC_CAST, 74 | STATIC_CAST, 75 | REINTERPRET_CAST, 76 | CONST_CAST, 77 | TYPEID, 78 | THIS, 79 | TEMPLATE, 80 | THROW, 81 | TRY, 82 | CATCH, 83 | TYPEDEF, 84 | FRIEND, 85 | CLASS, 86 | NAMESPACE, 87 | ENUM, 88 | STRUCT, 89 | UNION, 90 | VIRTUAL, 91 | PRIVATE, 92 | PROTECTED, 93 | PUBLIC, 94 | EXPORT, 95 | AUTO, 96 | REGISTER, 97 | EXTERN, 98 | MUTABLE, 99 | ASM, 100 | USING, 101 | INLINE, 102 | EXPLICIT, 103 | STATIC, 104 | CONST, 105 | VOLATILE, 106 | OPERATOR, 107 | SIZEOF, 108 | NEW, 109 | DELETE, 110 | PLUS, 111 | MINUS, 112 | STAR, 113 | SLASH, 114 | PERCENT, 115 | HAT, 116 | AND, 117 | OR, 118 | TILDE, 119 | NOT, 120 | PLUS_EQ, 121 | MINUS_EQ, 122 | STAR_EQ, 123 | SLASH_EQ, 124 | PERCENT_EQ, 125 | HAT_EQ, 126 | AND_EQ, 127 | OR_EQ, 128 | LTLT, 129 | GTGT, 130 | GTGT_EQ, 131 | LTLT_EQ, 132 | EQEQ, 133 | NE, 134 | LE, 135 | GE, 136 | ANDAND, 137 | OROR, 138 | INCR, 139 | DECR, 140 | COMMA, 141 | ARROW_STAR, 142 | ARROW, 143 | CHAR, 144 | WCHAR, 145 | BOOL, 146 | SHORT, 147 | INT, 148 | LONG, 149 | SIGNED, 150 | UNSIGNED, 151 | FLOAT, 152 | DOUBLE, 153 | VOID, 154 | CASE, 155 | DEFAULT, 156 | IF, 157 | ELSE, 158 | SWITCH, 159 | WHILE, 160 | DO, 161 | FOR, 162 | BREAK, 163 | CONTINUE, 164 | GOTO, 165 | SIGNALS, 166 | SLOTS, 167 | RETURN, 168 | Q_META_TOKEN_BEGIN, 169 | Q_OBJECT_TOKEN = Q_META_TOKEN_BEGIN, 170 | Q_GADGET_TOKEN, 171 | Q_PROPERTY_TOKEN, 172 | Q_PLUGIN_METADATA_TOKEN, 173 | Q_ENUMS_TOKEN, 174 | Q_FLAGS_TOKEN, 175 | Q_DECLARE_FLAGS_TOKEN, 176 | Q_DECLARE_INTERFACE_TOKEN, 177 | Q_DECLARE_METATYPE_TOKEN, 178 | Q_CLASSINFO_TOKEN, 179 | Q_INTERFACES_TOKEN, 180 | Q_SIGNALS_TOKEN, 181 | Q_SLOTS_TOKEN, 182 | Q_SIGNAL_TOKEN, 183 | Q_SLOT_TOKEN, 184 | Q_PRIVATE_SLOT_TOKEN, 185 | Q_MOC_COMPAT_TOKEN, 186 | Q_INVOKABLE_TOKEN, 187 | Q_SCRIPTABLE_TOKEN, 188 | Q_PRIVATE_PROPERTY_TOKEN, 189 | Q_REVISION_TOKEN, 190 | Q_META_TOKEN_END, 191 | SPECIAL_TREATMENT_MARK = Q_META_TOKEN_END, 192 | MOC_INCLUDE_BEGIN, 193 | MOC_INCLUDE_END, 194 | CPP_COMMENT, 195 | C_COMMENT, 196 | FLOATING_LITERAL, 197 | HASH, 198 | QUOTE, 199 | SINGLEQUOTE, 200 | LANGLE_SCOPE, 201 | DIGIT, 202 | CHARACTER, 203 | NEWLINE, 204 | WHITESPACE, 205 | BACKSLASH, 206 | INCOMPLETE, 207 | 208 | PP_DEFINE, 209 | PP_UNDEF, 210 | PP_IF, 211 | PP_IFDEF, 212 | PP_IFNDEF, 213 | PP_ELIF, 214 | PP_ELSE, 215 | PP_ENDIF, 216 | PP_INCLUDE, 217 | PP_HASHHASH, 218 | PP_HASH, 219 | PP_DEFINED, 220 | PP_INCOMPLETE, 221 | 222 | PP_MOC_TRUE, 223 | PP_MOC_FALSE, 224 | 225 | PP_NOTOKEN = NOTOKEN, 226 | PP_IDENTIFIER = IDENTIFIER, 227 | PP_INTEGER_LITERAL = INTEGER_LITERAL, 228 | PP_CHARACTER_LITERAL = CHARACTER_LITERAL, 229 | PP_STRING_LITERAL = STRING_LITERAL, 230 | PP_LANGLE = LANGLE, 231 | PP_RANGLE = RANGLE, 232 | PP_LPAREN = LPAREN, 233 | PP_RPAREN = RPAREN, 234 | PP_COMMA = COMMA, 235 | PP_PLUS = PLUS, 236 | PP_MINUS = MINUS, 237 | PP_STAR = STAR, 238 | PP_SLASH = SLASH, 239 | PP_PERCENT = PERCENT, 240 | PP_HAT = HAT, 241 | PP_AND = AND, 242 | PP_OR = OR, 243 | PP_TILDE = TILDE, 244 | PP_NOT = NOT, 245 | PP_LTLT = LTLT, 246 | PP_GTGT = GTGT, 247 | PP_EQEQ = EQEQ, 248 | PP_NE = NE, 249 | PP_LE = LE, 250 | PP_GE = GE, 251 | PP_ANDAND = ANDAND, 252 | PP_OROR = OROR, 253 | PP_QUESTION = QUESTION, 254 | PP_COLON = COLON, 255 | PP_FLOATING_LITERAL = FLOATING_LITERAL, 256 | PP_QUOTE = QUOTE, 257 | PP_SINGLEQUOTE = SINGLEQUOTE, 258 | PP_DIGIT = DIGIT, 259 | PP_CHARACTER = CHARACTER, 260 | PP_WHITESPACE = WHITESPACE, 261 | PP_NEWLINE = NEWLINE, 262 | PP_CPP_COMMENT = CPP_COMMENT, 263 | PP_C_COMMENT = C_COMMENT, 264 | PP_BACKSLASH = BACKSLASH 265 | }; 266 | 267 | // for debugging only 268 | #if defined(DEBUG_MOC) 269 | const char *tokenTypeName(Token t); 270 | #endif 271 | 272 | typedef Token PP_Token; 273 | 274 | QT_END_NAMESPACE 275 | 276 | #endif // TOKEN_H 277 | -------------------------------------------------------------------------------- /modules/uic/src/lua/luawriteincludes.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 tdzl2003. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the LuaQt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** 10 | ** GNU Lesser General Public License Usage 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser 12 | ** General Public License version 2.1 as published by the Free Software 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the 14 | ** packaging of this file. Please review the following information to 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** $QT_END_LICENSE$ 19 | ** 20 | ****************************************************************************/ 21 | 22 | #include "luawriteincludes.h" 23 | #include "../driver.h" 24 | #include "../ui4.h" 25 | #include "../uic.h" 26 | #include "../databaseinfo.h" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | QT_BEGIN_NAMESPACE 35 | 36 | enum { debugWriteIncludes = 0 }; 37 | enum { warnHeaderGeneration = 0 }; 38 | 39 | struct ClassInfoEntry 40 | { 41 | const char *klass; 42 | const char *module; 43 | const char *header; 44 | }; 45 | 46 | static const ClassInfoEntry qclass_lib_map[] = { 47 | #define QT_CLASS_LIB(klass, module, header) { #klass, #module, #header }, 48 | #include "../qclass_lib_map.h" 49 | 50 | #undef QT_CLASS_LIB 51 | }; 52 | 53 | namespace LUA { 54 | 55 | WriteIncludes::WriteIncludes(Uic *uic) 56 | : m_uic(uic), m_output(uic->output()), m_scriptsActivated(false), m_laidOut(false) 57 | { 58 | const QString namespaceDelimiter = QLatin1String("::"); 59 | const ClassInfoEntry *classLibEnd = qclass_lib_map + sizeof(qclass_lib_map)/sizeof(ClassInfoEntry); 60 | for (const ClassInfoEntry *it = qclass_lib_map; it < classLibEnd; ++it) { 61 | const QString klass = QLatin1String(it->klass); 62 | const QString module = QLatin1String(it->module); 63 | QLatin1String header = QLatin1String(it->header); 64 | m_classModule.insert(klass, module); 65 | } 66 | } 67 | 68 | void WriteIncludes::acceptUI(DomUI *node) 69 | { 70 | m_scriptsActivated = false; 71 | m_laidOut = false; 72 | m_knownClasses.clear(); 73 | m_knownPackages.clear(); 74 | 75 | if (node->elementIncludes()) 76 | acceptIncludes(node->elementIncludes()); 77 | 78 | if (node->elementCustomWidgets()) 79 | TreeWalker::acceptCustomWidgets(node->elementCustomWidgets()); 80 | 81 | add(QLatin1String("QApplication")); 82 | add(QLatin1String("QVariant")); 83 | add(QLatin1String("QAction")); 84 | 85 | add(QLatin1String("QButtonGroup")); // ### only if it is really necessary 86 | add(QLatin1String("QHeaderView")); 87 | 88 | add(QLatin1String("QFont")); 89 | 90 | TreeWalker::acceptUI(node); 91 | 92 | m_output << "local bit = require(\"bit\");\n"; 93 | 94 | writeHeaders(m_requires); 95 | 96 | m_output << QLatin1Char('\n'); 97 | } 98 | 99 | void WriteIncludes::acceptWidget(DomWidget *node) 100 | { 101 | if (debugWriteIncludes) 102 | fprintf(stderr, "%s '%s'\n", Q_FUNC_INFO, qPrintable(node->attributeClass())); 103 | 104 | add(node->attributeClass()); 105 | TreeWalker::acceptWidget(node); 106 | } 107 | 108 | void WriteIncludes::acceptLayout(DomLayout *node) 109 | { 110 | add(node->attributeClass()); 111 | m_laidOut = true; 112 | TreeWalker::acceptLayout(node); 113 | } 114 | 115 | void WriteIncludes::acceptSpacer(DomSpacer *node) 116 | { 117 | add(QLatin1String("QSpacerItem")); 118 | TreeWalker::acceptSpacer(node); 119 | } 120 | 121 | void WriteIncludes::acceptProperty(DomProperty *node) 122 | { 123 | TreeWalker::acceptProperty(node); 124 | } 125 | 126 | void WriteIncludes::insertIncludeForClass(const QString &className) 127 | { 128 | if (debugWriteIncludes) 129 | fprintf(stderr, "%s %s\n", Q_FUNC_INFO, qPrintable(className)); 130 | 131 | 132 | // Known class 133 | const StringMap::const_iterator it = m_classModule.constFind(className); 134 | if (it != m_classModule.constEnd()) { 135 | insertIncludeForPackage(it.value()); 136 | return; 137 | } 138 | 139 | //TODO: Unknown class 140 | fprintf(stderr, "Unknown class: %s\n", qPrintable(className)); 141 | } 142 | 143 | void WriteIncludes::add(const QString &className, bool determineHeader) 144 | { 145 | if (debugWriteIncludes) 146 | fprintf(stderr, "%s %s \n", Q_FUNC_INFO, qPrintable(className)); 147 | 148 | if (className.isEmpty() || m_knownClasses.contains(className)) 149 | return; 150 | 151 | m_knownClasses.insert(className); 152 | 153 | if (!m_laidOut && m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox"))) 154 | add(QLatin1String("QLayout")); // spacing property of QToolBox) 155 | 156 | if (className == QLatin1String("Line")) { // ### hmm, deprecate me! 157 | add(QLatin1String("QFrame")); 158 | return; 159 | } 160 | 161 | if (determineHeader) 162 | insertIncludeForClass(className); 163 | } 164 | 165 | void WriteIncludes::acceptCustomWidget(DomCustomWidget *node) 166 | { 167 | const QString className = node->elementClass(); 168 | if (className.isEmpty()) 169 | return; 170 | 171 | if (const DomScript *domScript = node->elementScript()) 172 | if (!domScript->text().isEmpty()) 173 | activateScripts(); 174 | 175 | if (!node->elementHeader() || node->elementHeader()->text().isEmpty()) { 176 | add(className, false); // no header specified 177 | } else { 178 | add(className, true); 179 | } 180 | } 181 | 182 | void WriteIncludes::acceptCustomWidgets(DomCustomWidgets *node) 183 | { 184 | Q_UNUSED(node); 185 | } 186 | 187 | void WriteIncludes::acceptIncludes(DomIncludes *node) 188 | { 189 | TreeWalker::acceptIncludes(node); 190 | } 191 | 192 | void WriteIncludes::acceptInclude(DomInclude *node) 193 | { 194 | } 195 | 196 | void WriteIncludes::insertIncludeForPackage(const QString &packageName) 197 | { 198 | if (m_knownPackages.contains(packageName)) { 199 | return; 200 | } 201 | if (debugWriteIncludes) 202 | fprintf(stderr, "%s %s\n", Q_FUNC_INFO, qPrintable(packageName)); 203 | 204 | m_knownPackages.insert(packageName); 205 | 206 | m_requires.insert(packageName, false); 207 | } 208 | 209 | void WriteIncludes::writeHeaders(const OrderedSet &headers) 210 | { 211 | const OrderedSet::const_iterator cend = headers.constEnd(); 212 | for (OrderedSet::const_iterator sit = headers.constBegin(); sit != cend; ++sit) { 213 | const QString header = sit.key(); 214 | if (!header.trimmed().isEmpty()) { 215 | m_output << "require(\"" << header << "\")\n"; 216 | } 217 | } 218 | } 219 | 220 | void WriteIncludes::acceptWidgetScripts(const DomScripts &scripts, DomWidget *, const DomWidgets &) 221 | { 222 | if (!scripts.empty()) { 223 | activateScripts(); 224 | } 225 | } 226 | 227 | void WriteIncludes::activateScripts() 228 | { 229 | if (!m_scriptsActivated) { 230 | add(QLatin1String("QScriptEngine")); 231 | add(QLatin1String("QDebug")); 232 | m_scriptsActivated = true; 233 | } 234 | } 235 | } // namespace LUA 236 | 237 | QT_END_NAMESPACE 238 | -------------------------------------------------------------------------------- /modules/mocreader/src/symbols.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Copyright (C) 2013 Olivier Goffart 5 | ** Contact: http://www.qt-project.org/legal 6 | ** 7 | ** This file is part of the tools applications of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:LGPL$ 10 | ** Commercial License Usage 11 | ** Licensees holding valid commercial Qt licenses may use this file in 12 | ** accordance with the commercial license agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Digia. For licensing terms and 15 | ** conditions see http://qt.digia.com/licensing. For further information 16 | ** use the contact form at http://qt.digia.com/contact-us. 17 | ** 18 | ** GNU Lesser General Public License Usage 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser 20 | ** General Public License version 2.1 as published by the Free Software 21 | ** Foundation and appearing in the file LICENSE.LGPL included in the 22 | ** packaging of this file. Please review the following information to 23 | ** ensure the GNU Lesser General Public License version 2.1 requirements 24 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** In addition, as a special exception, Digia gives you certain additional 27 | ** rights. These rights are described in the Digia Qt LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** GNU General Public License Usage 31 | ** Alternatively, this file may be used under the terms of the GNU 32 | ** General Public License version 3.0 as published by the Free Software 33 | ** Foundation and appearing in the file LICENSE.GPL included in the 34 | ** packaging of this file. Please review the following information to 35 | ** ensure the GNU General Public License version 3.0 requirements will be 36 | ** met: http://www.gnu.org/copyleft/gpl.html. 37 | ** 38 | ** 39 | ** $QT_END_LICENSE$ 40 | ** 41 | ****************************************************************************/ 42 | 43 | #ifndef SYMBOLS_H 44 | #define SYMBOLS_H 45 | 46 | #include "token.h" 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | QT_BEGIN_NAMESPACE 54 | 55 | //#define USE_LEXEM_STORE 56 | 57 | struct SubArray 58 | { 59 | inline SubArray():from(0),len(-1){} 60 | inline SubArray(const QByteArray &a):array(a),from(0), len(a.size()){} 61 | inline SubArray(const char *s):array(s),from(0) { len = array.size(); } 62 | inline SubArray(const QByteArray &a, int from, int len):array(a), from(from), len(len){} 63 | QByteArray array; 64 | int from, len; 65 | inline bool operator==(const SubArray &other) const { 66 | if (len != other.len) 67 | return false; 68 | for (int i = 0; i < len; ++i) 69 | if (array.at(from + i) != other.array.at(other.from + i)) 70 | return false; 71 | return true; 72 | } 73 | }; 74 | 75 | inline uint qHash(const SubArray &key) 76 | { 77 | return qHash(QLatin1String(key.array.constData() + key.from, key.len)); 78 | } 79 | 80 | 81 | struct Symbol 82 | { 83 | 84 | #ifdef USE_LEXEM_STORE 85 | typedef QHash LexemStore; 86 | static LexemStore lexemStore; 87 | 88 | inline Symbol() : lineNum(-1),token(NOTOKEN){} 89 | inline Symbol(int lineNum, Token token): 90 | lineNum(lineNum), token(token){} 91 | inline Symbol(int lineNum, Token token, const QByteArray &lexem): 92 | lineNum(lineNum), token(token),lex(lexem){} 93 | inline Symbol(int lineNum, Token token, const QByteArray &lexem, int from, int len): 94 | lineNum(lineNum), token(token){ 95 | LexemStore::const_iterator it = lexemStore.constFind(SubArray(lexem, from, len)); 96 | 97 | if (it != lexemStore.constEnd()) { 98 | lex = it.key().array; 99 | } else { 100 | lex = lexem.mid(from, len); 101 | lexemStore.insert(lex, QHashDummyValue()); 102 | } 103 | } 104 | int lineNum; 105 | Token token; 106 | inline QByteArray unquotedLexem() const { return lex.mid(1, lex.length()-2); } 107 | inline QByteArray lexem() const { return lex; } 108 | inline operator QByteArray() const { return lex; } 109 | QByteArray lex; 110 | 111 | #else 112 | 113 | inline Symbol() : lineNum(-1),token(NOTOKEN), from(0),len(-1) {} 114 | inline Symbol(int lineNum, Token token): 115 | lineNum(lineNum), token(token), from(0), len(-1) {} 116 | inline Symbol(int lineNum, Token token, const QByteArray &lexem): 117 | lineNum(lineNum), token(token), lex(lexem), from(0) { len = lex.size(); } 118 | inline Symbol(int lineNum, Token token, const QByteArray &lexem, int from, int len): 119 | lineNum(lineNum), token(token),lex(lexem),from(from), len(len){} 120 | int lineNum; 121 | Token token; 122 | inline QByteArray lexem() const { return lex.mid(from, len); } 123 | inline QByteArray unquotedLexem() const { return lex.mid(from+1, len-2); } 124 | inline operator QByteArray() const { return lex.mid(from, len); } 125 | inline operator SubArray() const { return SubArray(lex, from, len); } 126 | QByteArray lex; 127 | int from, len; 128 | 129 | #endif 130 | }; 131 | Q_DECLARE_TYPEINFO(Symbol, Q_MOVABLE_TYPE); 132 | 133 | typedef QVector Symbols; 134 | 135 | struct SafeSymbols { 136 | Symbols symbols; 137 | QByteArray expandedMacro; 138 | QSet excludedSymbols; 139 | int index; 140 | }; 141 | 142 | class SymbolStack : public QStack 143 | { 144 | public: 145 | inline bool hasNext() { 146 | while (!isEmpty() && top().index >= top().symbols.size()) 147 | pop(); 148 | return !isEmpty(); 149 | } 150 | inline Token next() { 151 | while (!isEmpty() && top().index >= top().symbols.size()) 152 | pop(); 153 | if (isEmpty()) 154 | return NOTOKEN; 155 | return top().symbols.at(top().index++).token; 156 | } 157 | bool test(Token); 158 | inline const Symbol &symbol() const { return top().symbols.at(top().index-1); } 159 | inline Token token() { return symbol().token; } 160 | inline QByteArray lexem() const { return symbol().lexem(); } 161 | inline QByteArray unquotedLexem() { return symbol().unquotedLexem(); } 162 | 163 | bool dontReplaceSymbol(const QByteArray &name); 164 | QSet excludeSymbols(); 165 | }; 166 | 167 | inline bool SymbolStack::test(Token token) 168 | { 169 | int stackPos = size() - 1; 170 | while (stackPos >= 0 && at(stackPos).index >= at(stackPos).symbols.size()) 171 | --stackPos; 172 | if (stackPos < 0) 173 | return false; 174 | if (at(stackPos).symbols.at(at(stackPos).index).token == token) { 175 | next(); 176 | return true; 177 | } 178 | return false; 179 | } 180 | 181 | inline bool SymbolStack::dontReplaceSymbol(const QByteArray &name) 182 | { 183 | for (int i = 0; i < size(); ++i) { 184 | if (name == at(i).expandedMacro || at(i).excludedSymbols.contains(name)) 185 | return true; 186 | } 187 | return false; 188 | } 189 | 190 | inline QSet SymbolStack::excludeSymbols() 191 | { 192 | QSet set; 193 | for (int i = 0; i < size(); ++i) { 194 | set << at(i).expandedMacro; 195 | set += at(i).excludedSymbols; 196 | } 197 | return set; 198 | } 199 | 200 | QT_END_NAMESPACE 201 | 202 | #endif // SYMBOLS_H 203 | -------------------------------------------------------------------------------- /modules/uic/src/utils.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef UTILS_H 43 | #define UTILS_H 44 | 45 | #include "ui4.h" 46 | #include 47 | #include 48 | #include 49 | 50 | QT_BEGIN_NAMESPACE 51 | 52 | inline bool toBool(const QString &str) 53 | { return str.toLower() == QLatin1String("true"); } 54 | 55 | inline QString toString(const DomString *str) 56 | { return str ? str->text() : QString(); } 57 | 58 | enum StringFlags { 59 | Utf8String = 0x1, 60 | MultiLineString = 0x2 61 | }; 62 | 63 | inline QString fixString(const QString &str, const QString &indent, 64 | unsigned *stringFlags = 0) 65 | { 66 | QString cursegment; 67 | QStringList result; 68 | const QByteArray utf8 = str.toUtf8(); 69 | const int utf8Length = utf8.length(); 70 | 71 | unsigned flags = 0; 72 | 73 | for (int i = 0; i < utf8Length; ++i) { 74 | const uchar cbyte = utf8.at(i); 75 | if (cbyte >= 0x80) { 76 | cursegment += QLatin1Char('\\'); 77 | cursegment += QLatin1Char('x'); 78 | cursegment += QString::number(cbyte, 16); 79 | flags |= Utf8String; 80 | } else { 81 | switch(cbyte) { 82 | case '\\': 83 | cursegment += QLatin1String("\\\\"); break; 84 | case '\"': 85 | cursegment += QLatin1String("\\\""); break; 86 | case '\r': 87 | break; 88 | case '\n': 89 | flags |= MultiLineString; 90 | cursegment += QLatin1String("\\n\"..\n\""); break; 91 | default: 92 | cursegment += QLatin1Char(cbyte); 93 | } 94 | } 95 | 96 | if (cursegment.length() > 1024) { 97 | result << cursegment; 98 | cursegment.clear(); 99 | } 100 | } 101 | 102 | if (!cursegment.isEmpty()) 103 | result << cursegment; 104 | 105 | 106 | QString joinstr = QLatin1String("\"\n"); 107 | joinstr += indent; 108 | joinstr += indent; 109 | joinstr += QLatin1Char('"'); 110 | 111 | QString rc(QLatin1Char('"')); 112 | rc += result.join(joinstr); 113 | rc += QLatin1Char('"'); 114 | 115 | if (result.size() > 1) 116 | flags |= MultiLineString; 117 | 118 | if (stringFlags) 119 | *stringFlags = flags; 120 | 121 | return rc; 122 | } 123 | 124 | inline QString fixLuaString(const QString &str, const QString &indent, 125 | unsigned *stringFlags = 0) 126 | { 127 | QString cursegment; 128 | QStringList result; 129 | const QByteArray utf8 = str.toUtf8(); 130 | const int utf8Length = utf8.length(); 131 | 132 | unsigned flags = 0; 133 | 134 | for (int i = 0; i < utf8Length; ++i) { 135 | const uchar cbyte = utf8.at(i); 136 | if (cbyte >= 0x80) { 137 | cursegment += QLatin1Char('\\'); 138 | cursegment += QLatin1Char('x'); 139 | cursegment += QString::number(cbyte, 16); 140 | flags |= Utf8String; 141 | } else { 142 | switch(cbyte) { 143 | case '\\': 144 | cursegment += QLatin1String("\\\\"); break; 145 | case '\"': 146 | cursegment += QLatin1String("\\\""); break; 147 | case '\r': 148 | break; 149 | case '\n': 150 | flags |= MultiLineString; 151 | cursegment += QLatin1String("\\n\"..\n\""); break; 152 | break; 153 | default: 154 | cursegment += QLatin1Char(cbyte); 155 | } 156 | } 157 | 158 | if (cursegment.length() > 1024) { 159 | result << cursegment; 160 | cursegment.clear(); 161 | } 162 | } 163 | 164 | if (!cursegment.isEmpty()) 165 | result << cursegment; 166 | 167 | 168 | QString joinstr = QLatin1String("\"\n"); 169 | joinstr += indent; 170 | joinstr += indent; 171 | joinstr += "+ "; 172 | joinstr += QLatin1Char('"'); 173 | 174 | QString rc(QLatin1Char('"')); 175 | rc += result.join(joinstr); 176 | rc += QLatin1Char('"'); 177 | 178 | if (result.size() > 1) 179 | flags |= MultiLineString; 180 | 181 | if (stringFlags) 182 | *stringFlags = flags; 183 | 184 | return rc; 185 | } 186 | 187 | inline QString writeString(const QString &s, const QString &indent) 188 | { 189 | unsigned flags = 0; 190 | const QString ret = fixString(s, indent, &flags); 191 | if (flags & Utf8String) 192 | return QLatin1String("QString::fromUtf8(") + ret + QLatin1Char(')'); 193 | // MSVC cannot concat L"foo" "bar" (C2308: concatenating mismatched strings), 194 | // use QLatin1String instead (all platforms to avoid cross-compiling issues). 195 | if (flags & MultiLineString) 196 | return QLatin1String("QLatin1String(") + ret + QLatin1Char(')'); 197 | return QLatin1String("QStringLiteral(") + ret + QLatin1Char(')'); 198 | } 199 | 200 | 201 | inline QHash propertyMap(const QList &properties) 202 | { 203 | QHash map; 204 | 205 | for (int i=0; iattributeName(), p); 208 | } 209 | 210 | return map; 211 | } 212 | 213 | inline QStringList unique(const QStringList &lst) 214 | { 215 | QHash h; 216 | for (int i=0; i 0 and outt[j] ~= "..") then 145 | outt[j] = nil 146 | j = j-1 147 | elseif (j == 0 and prefix~= "") then 148 | else 149 | j = j+1 150 | outt[j] = comps[i] 151 | end 152 | else 153 | j = j+1 154 | outt[j] = comps[i] 155 | end 156 | end 157 | if (prefix=='' and j == 0) then 158 | return '.' 159 | end 160 | if (isWindows) then 161 | sep = sep or '\\' 162 | else 163 | sep = sep or '/' 164 | end 165 | return prefix .. table.concat(outt, sep) 166 | end 167 | local normalize = path.normalize 168 | 169 | function path.split(p) 170 | local p1, p2 = p:match("(.+[%/%\\])[%/%\\]*([^%/%\\]+)") 171 | if p1 then 172 | return p1, p2 173 | end 174 | return "", p 175 | end 176 | local split = path.split 177 | 178 | function path.splitext(p) 179 | local p1, p2 = p:match("(.+)(%.[^.]*)") 180 | if (p1) then 181 | if (p2:match("[%/%\\]")) then 182 | return p, '' 183 | end 184 | return p1, p2 185 | end 186 | return p, '' 187 | end 188 | 189 | function path.basename(p) 190 | local b, t = split(p) 191 | return t 192 | end 193 | 194 | function path.dirname(p) 195 | local b, t = split(p) 196 | return b 197 | end 198 | 199 | function path.normjoin(...) 200 | return normalize(join(...)) 201 | end 202 | 203 | function path.abspath(path) 204 | return normalize(join(current(), path)) 205 | end 206 | local abspath = path.abspath 207 | 208 | local function _abspath_split(path) 209 | path = abspath(path) 210 | local prefix, rest = splitdrive(path) 211 | local restsplit = {} 212 | --rest:split("[%/%\\]", false, true) 213 | for k in rest:gmatch("([^%/%\\]+)") do 214 | table.insert(restsplit, k) 215 | end 216 | 217 | return prefix, restsplit 218 | end 219 | 220 | function path.relpath(path, start) 221 | start = start or current() 222 | 223 | local start_prefix, start_list = _abspath_split(start) 224 | local path_prefix, path_list = _abspath_split(path) 225 | 226 | if (start_prefix:lower() ~= path_prefix:lower()) then 227 | return path 228 | end 229 | 230 | local i = 1 231 | while (i<=#start_list and i<=#path_list and start_list[i] == path_list[i]) do 232 | i = i + 1 233 | end 234 | 235 | local rel_list = {} 236 | for j = i, #start_list do 237 | table.insert(rel_list, pardir) 238 | end 239 | for j = i, #path_list do 240 | table.insert(rel_list, path_list[j]) 241 | end 242 | if (#path_list == 0) then 243 | return curdir 244 | end 245 | return table.concat(rel_list, sep) 246 | end 247 | 248 | path.stat = impl.stat 249 | path.isdir = impl.isdir 250 | path.exists = impl.exists 251 | path.listAll = impl.listAll 252 | path.listFiles = impl.listFiles 253 | path.listSubdirs = impl.listSubdirs 254 | 255 | local exists = path.exists 256 | 257 | local function mkdir(path, mode) --mode = 777 258 | mode = mode or 0x1FF 259 | local head, tail = split(path) 260 | if (tail == "") then 261 | head, tail = split(head) 262 | end 263 | if (head~="" and tail~="" and not exists(head)) then 264 | mkdir(head, mode) 265 | end 266 | if (not exists(path)) then 267 | impl.mkdir(path, mode) 268 | end 269 | end 270 | path.mkdir = mkdir 271 | 272 | --[[ 273 | function path.modifiedTime(path) 274 | return fbmakelib.modifiedTime(path) 275 | end 276 | 277 | function createdTime(path) 278 | return fbmakelib.createdTime(path) 279 | end 280 | 281 | function rmdir(path, func) 282 | for i,v in ipairs(listfile(path)) do 283 | local p = normjoin(path, v) 284 | if func then 285 | func(p) 286 | end 287 | os.remove(p) 288 | end 289 | for i,v in ipairs(listsubdir(path)) do 290 | rmdir(join(path, v)) 291 | end 292 | 293 | local p = normpath(path) 294 | if func then 295 | func(p) 296 | end 297 | 298 | if (isWindows) then 299 | os.execute("rmdir ".. p) 300 | else 301 | os.remove(p) 302 | end 303 | end 304 | ]] 305 | 306 | return path -------------------------------------------------------------------------------- /modules/mocreader/src/qmetaobject_moc_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the QtCore module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #if !defined(QMETAOBJECT_P_H) && !defined(UTILS_H) 43 | # error "Include qmetaobject_p.h (or moc's utils.h) before including this file." 44 | #endif 45 | 46 | QT_BEGIN_NAMESPACE 47 | 48 | // This function is shared with moc.cpp. This file should be included where needed. 49 | static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixScope = false, bool adjustConst = true) 50 | { 51 | int len = e - t; 52 | /* 53 | Convert 'char const *' into 'const char *'. Start at index 1, 54 | not 0, because 'const char *' is already OK. 55 | */ 56 | QByteArray constbuf; 57 | for (int i = 1; i < len; i++) { 58 | if ( t[i] == 'c' 59 | && strncmp(t + i + 1, "onst", 4) == 0 60 | && (i + 5 >= len || !is_ident_char(t[i + 5])) 61 | && !is_ident_char(t[i-1]) 62 | ) { 63 | constbuf = QByteArray(t, len); 64 | if (is_space(t[i-1])) 65 | constbuf.remove(i-1, 6); 66 | else 67 | constbuf.remove(i, 5); 68 | constbuf.prepend("const "); 69 | t = constbuf.data(); 70 | e = constbuf.data() + constbuf.length(); 71 | break; 72 | } 73 | /* 74 | We mustn't convert 'char * const *' into 'const char **' 75 | and we must beware of 'Bar'. 76 | */ 77 | if (t[i] == '&' || t[i] == '*' ||t[i] == '<') 78 | break; 79 | } 80 | if (adjustConst && e > t + 6 && strncmp("const ", t, 6) == 0) { 81 | if (*(e-1) == '&') { // treat const reference as value 82 | t += 6; 83 | --e; 84 | } else if (is_ident_char(*(e-1)) || *(e-1) == '>') { // treat const value as value 85 | t += 6; 86 | } 87 | } 88 | QByteArray result; 89 | result.reserve(len); 90 | 91 | #if 1 92 | // consume initial 'const ' 93 | if (strncmp("const ", t, 6) == 0) { 94 | t+= 6; 95 | result += "const "; 96 | } 97 | #endif 98 | 99 | // some type substitutions for 'unsigned x' 100 | if (strncmp("unsigned", t, 8) == 0) { 101 | // make sure "unsigned" is an isolated word before making substitutions 102 | if (!t[8] || !is_ident_char(t[8])) { 103 | if (strncmp(" int", t+8, 4) == 0) { 104 | t += 8+4; 105 | result += "uint"; 106 | } else if (strncmp(" long", t+8, 5) == 0) { 107 | if ((strlen(t + 8 + 5) < 4 || strncmp(t + 8 + 5, " int", 4) != 0) // preserve '[unsigned] long int' 108 | && (strlen(t + 8 + 5) < 5 || strncmp(t + 8 + 5, " long", 5) != 0) // preserve '[unsigned] long long' 109 | ) { 110 | t += 8+5; 111 | result += "ulong"; 112 | } 113 | } else if (strncmp(" short", t+8, 6) != 0 // preserve unsigned short 114 | && strncmp(" char", t+8, 5) != 0) { // preserve unsigned char 115 | // treat rest (unsigned) as uint 116 | t += 8; 117 | result += "uint"; 118 | } 119 | } 120 | } else { 121 | // discard 'struct', 'class', and 'enum'; they are optional 122 | // and we don't want them in the normalized signature 123 | struct { 124 | const char *keyword; 125 | int len; 126 | } optional[] = { 127 | { "struct ", 7 }, 128 | { "class ", 6 }, 129 | { "enum ", 5 }, 130 | { 0, 0 } 131 | }; 132 | int i = 0; 133 | do { 134 | if (strncmp(optional[i].keyword, t, optional[i].len) == 0) { 135 | t += optional[i].len; 136 | break; 137 | } 138 | } while (optional[++i].keyword != 0); 139 | } 140 | 141 | bool star = false; 142 | while (t != e) { 143 | char c = *t++; 144 | if (fixScope && c == ':' && *t == ':' ) { 145 | ++t; 146 | c = *t++; 147 | int i = result.size() - 1; 148 | while (i >= 0 && is_ident_char(result.at(i))) 149 | --i; 150 | result.resize(i + 1); 151 | } 152 | star = star || c == '*'; 153 | result += c; 154 | if (c == '<') { 155 | //template recursion 156 | const char* tt = t; 157 | int templdepth = 1; 158 | int scopeDepth = 0; 159 | while (t != e) { 160 | c = *t++; 161 | if (c == '{' || c == '(' || c == '[') 162 | ++scopeDepth; 163 | if (c == '}' || c == ')' || c == ']') 164 | --scopeDepth; 165 | if (scopeDepth == 0) { 166 | if (c == '<') 167 | ++templdepth; 168 | if (c == '>') 169 | --templdepth; 170 | if (templdepth == 0 || (templdepth == 1 && c == ',')) { 171 | result += normalizeTypeInternal(tt, t-1, fixScope, false); 172 | result += c; 173 | if (templdepth == 0) { 174 | if (*t == '>') 175 | result += ' '; // avoid >> 176 | break; 177 | } 178 | tt = t; 179 | } 180 | } 181 | } 182 | } 183 | 184 | // cv qualifers can appear after the type as well 185 | if (!is_ident_char(c) && t != e && (e - t >= 5 && strncmp("const", t, 5) == 0) 186 | && (e - t == 5 || !is_ident_char(t[5]))) { 187 | t += 5; 188 | while (t != e && is_space(*t)) 189 | ++t; 190 | if (adjustConst && t != e && *t == '&') { 191 | // treat const ref as value 192 | ++t; 193 | } else if (adjustConst && !star) { 194 | // treat const as value 195 | } else if (!star) { 196 | // move const to the front (but not if const comes after a *) 197 | result.prepend("const "); 198 | } else { 199 | // keep const after a * 200 | result += "const"; 201 | } 202 | } 203 | } 204 | 205 | return result; 206 | } 207 | 208 | QT_END_NAMESPACE 209 | --------------------------------------------------------------------------------