Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/qtlua.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2015-08-06 22:10:00 +0300
committerSam Gross <colesbury@gmail.com>2015-08-17 23:30:54 +0300
commit575f723265cf99e178b9f11bfd97f85755af07d5 (patch)
treeda5ee49fba0816663c262aa41d3ec346a0c2ecc3
parentc4fc6f5c8d8c93ed9fe531a584420a6baf2249a0 (diff)
Lua 5.2 support
-rw-r--r--packages/qtcore/qtcore.cpp14
-rw-r--r--packages/qtgui/qtgui.cpp6
-rw-r--r--packages/qtide/init.lua22
-rw-r--r--packages/qtide/prefs.lua10
-rw-r--r--packages/qtsvg/init.lua7
-rw-r--r--packages/qtuiloader/init.lua11
-rw-r--r--packages/qtwidget/init.lua24
-rw-r--r--packages/qtwidget/qtwidget.cpp6
-rw-r--r--qlua/qluaapplication.cpp4
-rw-r--r--qlua/qluaconsole_unix.cpp2
-rw-r--r--qtlua/qtluaconf.h.in26
-rw-r--r--qtlua/qtluaengine.cpp14
-rw-r--r--qtlua/qtluaengine.h4
-rw-r--r--qtlua/qtluautils.cpp12
14 files changed, 96 insertions, 66 deletions
diff --git a/packages/qtcore/qtcore.cpp b/packages/qtcore/qtcore.cpp
index 073d545..e85318c 100644
--- a/packages/qtcore/qtcore.cpp
+++ b/packages/qtcore/qtcore.cpp
@@ -148,7 +148,7 @@ static struct luaL_Reg t ## _lib[] = {\
static int t ## _hook(lua_State *L) \
{ \
lua_getfield(L, -1, "__metatable"); \
- luaL_register(L, 0, t ## _lib); \
+ luaL_setfuncs(L, t ## _lib, 0); \
return 0; \
}
@@ -220,7 +220,7 @@ static int
qbytearray_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qbytearray_lib);
+ luaL_setfuncs(L, qbytearray_lib, 0);
return 0;
}
@@ -440,7 +440,7 @@ static int
qstring_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qstring_lib);
+ luaL_setfuncs(L, qstring_lib, 0);
return 0;
}
@@ -498,7 +498,7 @@ static int
qstringlist_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qstringlist_lib);
+ luaL_setfuncs(L, qstringlist_lib, 0);
return 0;
}
@@ -578,7 +578,7 @@ static int
qurl_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qurl_lib);
+ luaL_setfuncs(L, qurl_lib, 0);
return 0;
}
@@ -632,7 +632,7 @@ static int
qvariantlist_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qvariantlist_lib);
+ luaL_setfuncs(L, qvariantlist_lib, 0);
return 0;
}
@@ -690,7 +690,7 @@ static int
qvariantmap_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qvariantmap_lib);
+ luaL_setfuncs(L, qvariantmap_lib, 0);
return 0;
}
diff --git a/packages/qtgui/qtgui.cpp b/packages/qtgui/qtgui.cpp
index 720ae5c..327e6f6 100644
--- a/packages/qtgui/qtgui.cpp
+++ b/packages/qtgui/qtgui.cpp
@@ -276,7 +276,7 @@ static struct luaL_Reg t ## _lib[] = {\
static int t ## _hook(lua_State *L) \
{ \
lua_getfield(L, -1, "__metatable"); \
- luaL_register(L, 0, t ## _lib); \
+ luaL_setfuncs(L, t ## _lib, 0); \
return 0; \
}
@@ -1336,7 +1336,7 @@ static int
qimage_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qimage_lib);
+ luaL_setfuncs(L, qimage_lib, 0);
luaQ_register(L, qimage_guilib, QCoreApplication::instance());
return 0;
}
@@ -1937,7 +1937,7 @@ qtransform_map(lua_State *L)
DO(QRectF,mapRect);
#undef DO
else
- luaL_typerror(L, 2, "point, polygon, region, or path");
+ luaQ_typerror(L, 2, "point, polygon, region, or path");
return 1;
}
diff --git a/packages/qtide/init.lua b/packages/qtide/init.lua
index dc5b2e0..d293eb8 100644
--- a/packages/qtide/init.lua
+++ b/packages/qtide/init.lua
@@ -23,7 +23,7 @@ local type = type
local paths = paths
local pcall = pcall
-module('qtide')
+qtide = qtide or {}
-- Startup --
@@ -35,7 +35,7 @@ local function realmode(mode)
return mode or qt.qApp:readSettings("ide/mode") or defaultmode
end
-function setup(mode)
+function qtide.setup(mode)
mode = realmode(mode)
if mode == "mdi" then -- subwindows within a big window
local mdi = qluaide:createMdiMain()
@@ -69,7 +69,7 @@ function setup(mode)
qt.qApp:writeSettings("ide/mode", mode)
end
-function start(mode)
+function qtide.start(mode)
setup(mode)
if not qt.qLuaSdiMain then
qluaide:createSdiMain()
@@ -81,7 +81,7 @@ end
-- Editor --
-function editor(s)
+function qtide.editor(s)
local e = qluaide:editor(s or "")
if e == nil and type(s) == "string" then
error(string.format("Unable to read file '%s'", s))
@@ -90,7 +90,7 @@ function editor(s)
end
-function doeditor(e)
+function qtide.doeditor(e)
-- validate parameter
if not qt.isa(e, 'QLuaEditor*') then
error(string.format("QLuaEditor expected, got %s.", s));
@@ -124,7 +124,7 @@ end
-- Inspector --
-function inspector(...)
+function qtide.inspector(...)
error("Function qtide.inspector is not yet working")
end
@@ -134,7 +134,7 @@ end
-- Browser --
-function browser(url)
+function qtide.browser(url)
return qluaide:browser(url or "about:/")
end
@@ -159,7 +159,7 @@ end
helpbrowser = nil
helpurl = locate_help_files()
-function help()
+function qtide.help()
local appname = qt.qApp.applicationName:tostring()
if not helpurl then
error("The html help files are not installed.")
@@ -187,7 +187,7 @@ qt.connect(qluaide,'helpRequested(QWidget*)',
-- Preferences --
-function preferences()
+function qtide.preferences()
G.require 'qtide.prefs'
local d = prefs.createPreferencesDialog()
if d and d.dialog:exec() > 0 then
@@ -204,6 +204,4 @@ qt.connect(qluaide,'prefsRequested(QWidget*)',
end
end)
-
-
-
+return qtide
diff --git a/packages/qtide/prefs.lua b/packages/qtide/prefs.lua
index 6f35c0c..72e34bf 100644
--- a/packages/qtide/prefs.lua
+++ b/packages/qtide/prefs.lua
@@ -16,8 +16,8 @@ local tonumber = tonumber
local tostring = tostring
local type = type
-module('qtide.prefs')
-
+qtide.prefs = qtide.prefs or {}
+local M = qtide.prefs
local uiPreferences = paths.thisfile("prefs.ui")
@@ -42,7 +42,7 @@ local function readSettingsBoolean(a,k)
return nil
end
-function createPreferencesDialog()
+function M.createPreferencesDialog()
if not paths.filep(uiPreferences) then
error("Unable to locate file 'prefs.ui'")
end
@@ -155,7 +155,7 @@ function createPreferencesDialog()
end
-function savePreferences(d)
+function M.savePreferences(d)
local a = qt.qApp
local f,w,h,ts,te,cl,hs
local ide = qt.QLuaIde()
@@ -226,4 +226,4 @@ function savePreferences(d)
end
-
+return M
diff --git a/packages/qtsvg/init.lua b/packages/qtsvg/init.lua
index 59cf77f..dec516c 100644
--- a/packages/qtsvg/init.lua
+++ b/packages/qtsvg/init.lua
@@ -5,13 +5,13 @@ qt.require 'libqtsvg'
local qt = qt
local type = type
-module 'qtsvg'
+qtsvg = qtsvg or {}
-function loadsvg(filename)
+function qtsvg.loadsvg(filename)
return qt.QSvgRenderer(filename)
end
-function paintsvg(port,svg,...)
+function qtsvg.paintsvg(port,svg,...)
if type(port) == "table" then
port = port.port
end
@@ -29,3 +29,4 @@ function paintsvg(port,svg,...)
port:gend(true)
end
+return qtsvg
diff --git a/packages/qtuiloader/init.lua b/packages/qtuiloader/init.lua
index 01c79b8..2a57c11 100644
--- a/packages/qtuiloader/init.lua
+++ b/packages/qtuiloader/init.lua
@@ -10,11 +10,12 @@ qt.require 'libqtuiloader'
local qt = qt
-module('qtuiloader')
+qtuiloader = qtuiloader or {}
+local M = qtuiloader
local theloader = nil
-function loader()
+function M.loader()
if (not theloader or not theloader:tobool()) then
theloader = qt.QUiLoader()
end
@@ -27,8 +28,10 @@ local loaderFunctions = {
for i = 1,#loaderFunctions do
local f = loaderFunctions[i]
- _M[f] = function(...)
- local uiloader = loader()
+ M[f] = function(...)
+ local uiloader = M.loader()
return uiloader[f](uiloader,...)
end
end
+
+return M
diff --git a/packages/qtwidget/init.lua b/packages/qtwidget/init.lua
index dcfa7c6..27f6b15 100644
--- a/packages/qtwidget/init.lua
+++ b/packages/qtwidget/init.lua
@@ -142,7 +142,7 @@ local type = type
local pcall = pcall
local setmetatable = setmetatable
-module('qtwidget')
+qtwidget = qtwidget or {}
local painterFunctions = {
-- c functions
@@ -177,7 +177,8 @@ end
-- windows
-windowClass = {}
+local windowClass = {}
+qtwidget.windowClass = windowClass
windowClass.__index = windowClass
declareRelayFunctions(windowClass)
@@ -209,7 +210,7 @@ function windowClass:close()
pcall(function() self.widget:deleteLater() end)
end
-function newwindow(w,h,title)
+function qtwidget.newwindow(w,h,title)
local self = {}
setmetatable(self, windowClass)
self.widget = qt.QWidget()
@@ -242,7 +243,8 @@ end
-- images
-imageClass = {}
+local imageClass = {}
+qtwidget.imageClass = imageClass
imageClass.__index = imageClass
declareRelayFunctions(imageClass)
@@ -250,7 +252,7 @@ function imageClass:valid()
return true;
end
-function newimage(...)
+function qtwidget.newimage(...)
local self = {}
setmetatable(self, imageClass)
local firstarg = ...
@@ -268,7 +270,8 @@ end
-- printer
-printerClass = {}
+local printerClass = {}
+qtwidget.printerClass = printerClass
printerClass.__index = printerClass
declareRelayFunctions(printerClass)
@@ -276,7 +279,7 @@ function printerClass:valid()
return true;
end
-function newprint(w,h,printername)
+function qtwidget.newprint(w,h,printername)
local self = {}
setmetatable(self, printerClass)
self.printer = qt.QtLuaPrinter()
@@ -292,7 +295,7 @@ function newprint(w,h,printername)
end
end
-function newpdf(w,h,filename)
+function qtwidget.newpdf(w,h,filename)
local self = {}
setmetatable(self, printerClass)
self.printer = qt.QtLuaPrinter()
@@ -307,7 +310,7 @@ function newpdf(w,h,filename)
return self
end
-function newps(w,h,filename)
+function qtwidget.newps(w,h,filename)
local self = {}
setmetatable(self, printerClass)
self.printer = qt.QtLuaPrinter()
@@ -321,7 +324,7 @@ function newps(w,h,filename)
return self
end
-function newsvg(w,h,filename)
+function qtwidget.newsvg(w,h,filename)
local self = {}
setmetatable(self, printerClass)
self.svg = qt.QtLuaSvgGenerator(filename)
@@ -333,3 +336,4 @@ function newsvg(w,h,filename)
return self
end
+return qtwidget
diff --git a/packages/qtwidget/qtwidget.cpp b/packages/qtwidget/qtwidget.cpp
index c5c1823..8567c69 100644
--- a/packages/qtwidget/qtwidget.cpp
+++ b/packages/qtwidget/qtwidget.cpp
@@ -172,7 +172,7 @@ luaQE_checkqvariant(lua_State *L, int index, T* = 0)
lua_pop(L, 1);
}
if (v.userType() != type)
- luaL_typerror(L, index, QMetaType::typeName(type));
+ luaQ_typerror(L, index, QMetaType::typeName(type));
return qVariantValue<T>(v);
}
@@ -569,7 +569,7 @@ static int qtluapainter_image(lua_State *L)
sw = o->width();
sh = o->height();
} else
- luaL_typerror(L, k, "QPixmap or QImage");
+ luaQ_typerror(L, k, "QPixmap or QImage");
k += 1;
if (lua_isnumber(L, k)) {
sx = luaL_checknumber(L, k++);
@@ -672,7 +672,7 @@ struct luaL_Reg qtluapainter_guilib[] = {
static int qtluapainter_hook(lua_State *L)
{
lua_getfield(L, -1, "__metatable");
- luaL_register(L, 0, qtluapainter_lib);
+ luaL_setfuncs(L, qtluapainter_lib, 0);
// luaQ_register(L, qtluapainter_lib, QCoreApplication::instance());
luaQ_register(L, qtluapainter_guilib, QCoreApplication::instance());
return 0;
diff --git a/qlua/qluaapplication.cpp b/qlua/qluaapplication.cpp
index 8b25422..fc13f94 100644
--- a/qlua/qluaapplication.cpp
+++ b/qlua/qluaapplication.cpp
@@ -709,8 +709,8 @@ QLuaApplication::Private::acceptInput(bool clear)
if (L)
{
struct lua_State *L = lua;
- lua_getfield(L, LUA_GLOBALSINDEX, "_PROMPT");
- lua_getfield(L, LUA_GLOBALSINDEX, "_PROMPT2");
+ lua_getglobal(L, "_PROMPT");
+ lua_getglobal(L, "_PROMPT2");
luaPrompt = lua_isstring(L,-2) ? lua_tostring(L, -2) : "> ";
luaPrompt2 = lua_isstring(L,-1) ? lua_tostring(L, -1) : ">> ";
lua_pop(L, 2);
diff --git a/qlua/qluaconsole_unix.cpp b/qlua/qluaconsole_unix.cpp
index e68b830..9cf1e25 100644
--- a/qlua/qluaconsole_unix.cpp
+++ b/qlua/qluaconsole_unix.cpp
@@ -476,7 +476,7 @@ rtty_complete(const char *text, int start, int end)
QtLuaLocker lua(console->lua, 250);
struct lua_State *L = lua;
if (lua) {
- lua_getfield(L, LUA_GLOBALSINDEX, "help");
+ lua_getglobal(L, "help");
if (lua_gettop(L)) {
printf("\n");
lua_pushstring(L, keyword);
diff --git a/qtlua/qtluaconf.h.in b/qtlua/qtluaconf.h.in
index 9884f4c..8669110 100644
--- a/qtlua/qtluaconf.h.in
+++ b/qtlua/qtluaconf.h.in
@@ -19,9 +19,33 @@
# define QTLUA_EXTERNC extern
#endif
+#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
+# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
+# define lua_setuservalue lua_setfenv
+# define lua_getuservalue lua_getfenv
+# define luaQ_typerror luaL_typerror
+static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
+ luaL_checkstack(L, nup+1, "too many upvalues");
+ for (; l->name != NULL; l++) { /* fill the table with given functions */
+ int i;
+ lua_pushstring(L, l->name);
+ for (i = 0; i < nup; i++) /* copy upvalues to the top */
+ lua_pushvalue(L, -(nup+1));
+ lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
+ lua_settable(L, -(nup + 3));
+ }
+ lua_pop(L, nup); /* remove upvalues */
+}
+#else
+# define lua_objlen lua_rawlen
+# define LUA_PATHSEP ";"
+static int luaQ_typerror(lua_State *L, int narg, const char *tname)
+{
+ return luaL_error(L, "%s expected, got %s", tname, luaL_typename(L, narg));
+}
#endif
-
+#endif
/* -------------------------------------------------------------
diff --git a/qtlua/qtluaengine.cpp b/qtlua/qtluaengine.cpp
index 535ad22..6423fec 100644
--- a/qtlua/qtluaengine.cpp
+++ b/qtlua/qtluaengine.cpp
@@ -127,7 +127,7 @@ luaQ_setup(lua_State *L, QtLuaEngine::Private *d)
lua_createtable(L, 0, 0);
lua_rawset(L, LUA_REGISTRYINDEX);
// package.preload["qt"]
- lua_getfield(L, LUA_GLOBALSINDEX, "package");
+ lua_getglobal(L, "package");
if (lua_istable(L, -1))
{
lua_getfield(L, -1, "preload");
@@ -1462,7 +1462,7 @@ call_in_arg_thread(lua_State *L)
// object
QObject *obj = luaQ_toqobject(L, 1);
if (! obj)
- luaL_typerror(L, 1, "qobject");
+ luaQ_typerror(L, 1, "qobject");
// function
lua_pushvalue(L, lua_upvalueindex(1));
Q_ASSERT(lua_isfunction(L, -1));
@@ -1871,7 +1871,7 @@ luaQ_m__getsetproperty(lua_State *L)
const QMetaProperty &mp = info->metaProperty;
QObject *obj = luaQ_toqobject(L, 1, info->metaObject);
if (! obj)
- luaL_typerror(L, 0, info->metaObject->className());
+ luaQ_typerror(L, 0, info->metaObject->className());
if (! mp.isScriptable(obj))
luaL_error(L, "property " LUA_QS " is not scriptable", mp.name());
if (lua_gettop(L) == 1)
@@ -2333,7 +2333,7 @@ luaQ_buildmetaclass(lua_State *L, int type)
else
{
// Standard methods
- luaL_register(L, 0, qtval_lib);
+ luaL_setfuncs(L, qtval_lib, 0);
}
// Insert class into qt package
lua_pushlightuserdata(L, (void*)qtKey);
@@ -2385,7 +2385,7 @@ luaQ_buildmetaclass(lua_State *L, const QMetaObject *mo)
else
{
// Standard methods
- luaL_register(L, 0, qtval_lib);
+ luaL_setfuncs(L, qtval_lib, 0);
}
// Slots and invokable method
QMap<QByteArray,QtLuaMethodInfo> overloads;
@@ -2470,7 +2470,7 @@ void
luaQ_fillmetatable(lua_State *L, int type, const QMetaObject *mo)
{
// Fill common entries
- luaL_register(L, 0, qtmeta_lib);
+ luaL_setfuncs(L, qtmeta_lib, 0);
// Fill distinct entries
if (mo)
{
@@ -3117,7 +3117,7 @@ luaQ_disconnect(lua_State *L, QObject *obj, const char *sig, int findex)
lua_pushlightuserdata(L, (void*)r);
lua_rawget(L, -3);
// ..stack: sigfunc function sigtable
- bool eq = lua_equal(L, -1, -2);
+ bool eq = lua_rawequal(L, -1, -2);
lua_pop(L, 1);
if (! eq)
continue;
diff --git a/qtlua/qtluaengine.h b/qtlua/qtluaengine.h
index 7d6da02..891eeb2 100644
--- a/qtlua/qtluaengine.h
+++ b/qtlua/qtluaengine.h
@@ -145,7 +145,7 @@ luaQ_checkqobject(lua_State *L, int index, T* = 0)
{
T *obj = qobject_cast<T*>(luaQ_toqobject(L, index));
if (! obj)
- luaL_typerror(L, index, T::staticMetaObject.className());
+ luaQ_typerror(L, index, T::staticMetaObject.className());
return obj;
}
@@ -155,7 +155,7 @@ luaQ_checkqvariant(lua_State *L, int index, T* = 0)
int type = qMetaTypeId<T>();
QVariant v = luaQ_toqvariant(L, index, type);
if (v.userType() != type)
- luaL_typerror(L, index, QMetaType::typeName(type));
+ luaQ_typerror(L, index, QMetaType::typeName(type));
return qVariantValue<T>(v);
}
diff --git a/qtlua/qtluautils.cpp b/qtlua/qtluautils.cpp
index f19f206..764911a 100644
--- a/qtlua/qtluautils.cpp
+++ b/qtlua/qtluautils.cpp
@@ -89,7 +89,7 @@ int
luaQ_tracebackskip(struct lua_State *L, int skip)
{
// stack: msg
- luaQ_getfield(L, LUA_GLOBALSINDEX, "debug");
+ lua_getglobal(L, "debug");
luaQ_getfield(L, -1, "traceback");
// stack: traceback debug msg
lua_remove(L, -2);
@@ -155,7 +155,7 @@ luaQ_complete(struct lua_State *L)
int k = 0;
int loop = 0;
const char *stem = luaL_checkstring(L, 1);
- lua_pushvalue(L, LUA_GLOBALSINDEX);
+ lua_pushglobaltable(L);
for(;;)
{
const char *s = stem;
@@ -438,7 +438,7 @@ qt_disconnect(lua_State *L)
if (lua_isnoneornil(L, 3))
findex = 0;
else if (! lua_isfunction(L, 3))
- luaL_typerror(L, 3, "function");
+ luaQ_typerror(L, 3, "function");
ok = luaQ_disconnect(L, obj, sig, findex);
}
lua_pushboolean(L, ok);
@@ -554,7 +554,7 @@ static const char *pushfilename (lua_State *L, const char *name)
{
const char *path;
const char *filename;
- luaQ_getfield(L, LUA_GLOBALSINDEX, "package");
+ lua_getglobal(L, "package");
luaQ_getfield(L, -1, "cpath");
lua_remove(L, -2);
if (! (path = lua_tostring(L, -1)))
@@ -689,8 +689,8 @@ luaopen_qt(lua_State *L)
const char *qt = luaL_optstring(L, 1, "qt");
luaQ_pushqt(L);
lua_pushvalue(L, -1);
- lua_setfield(L, LUA_GLOBALSINDEX, qt);
- luaL_register(L, qt, qt_lib);
+ lua_setglobal(L, qt);
+ luaL_setfuncs(L, qt_lib, 0);
// Add qt_m_index in a metatable
lua_createtable(L, 0, 1);