Skip to content

Commit

Permalink
Merge pull request #13 from colesbury/lua52
Browse files Browse the repository at this point in the history
Lua 5.2 support
  • Loading branch information
soumith committed Dec 19, 2015
2 parents 6bffd31 + 575f723 commit 9184d51
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 66 deletions.
14 changes: 7 additions & 7 deletions packages/qtcore/qtcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/qtgui/qtgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
}

Expand Down Expand Up @@ -1337,7 +1337,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;
}
Expand Down Expand Up @@ -1938,7 +1938,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;
}

Expand Down
22 changes: 10 additions & 12 deletions packages/qtide/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local type = type
local paths = paths
local pcall = pcall

module('qtide')
qtide = qtide or {}

-- Startup --

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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))
Expand All @@ -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));
Expand Down Expand Up @@ -124,7 +124,7 @@ end

-- Inspector --

function inspector(...)
function qtide.inspector(...)
error("Function qtide.inspector is not yet working")
end

Expand All @@ -134,7 +134,7 @@ end

-- Browser --

function browser(url)
function qtide.browser(url)
return qluaide:browser(url or "about:/")
end

Expand All @@ -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.")
Expand Down Expand Up @@ -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
Expand All @@ -204,6 +204,4 @@ qt.connect(qluaide,'prefsRequested(QWidget*)',
end
end)




return qtide
10 changes: 5 additions & 5 deletions packages/qtide/prefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -226,4 +226,4 @@ function savePreferences(d)

end


return M
7 changes: 4 additions & 3 deletions packages/qtsvg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,3 +29,4 @@ function paintsvg(port,svg,...)
port:gend(true)
end

return qtsvg
11 changes: 7 additions & 4 deletions packages/qtuiloader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
24 changes: 14 additions & 10 deletions packages/qtwidget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ local type = type
local pcall = pcall
local setmetatable = setmetatable

module('qtwidget')
qtwidget = qtwidget or {}

local painterFunctions = {
-- c functions
Expand Down Expand Up @@ -177,7 +177,8 @@ end

-- windows

windowClass = {}
local windowClass = {}
qtwidget.windowClass = windowClass
windowClass.__index = windowClass
declareRelayFunctions(windowClass)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -242,15 +243,16 @@ end

-- images

imageClass = {}
local imageClass = {}
qtwidget.imageClass = imageClass
imageClass.__index = imageClass
declareRelayFunctions(imageClass)

function imageClass:valid()
return true;
end

function newimage(...)
function qtwidget.newimage(...)
local self = {}
setmetatable(self, imageClass)
local firstarg = ...
Expand All @@ -268,15 +270,16 @@ end

-- printer

printerClass = {}
local printerClass = {}
qtwidget.printerClass = printerClass
printerClass.__index = printerClass
declareRelayFunctions(printerClass)

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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -333,3 +336,4 @@ function newsvg(w,h,filename)
return self
end

return qtwidget
6 changes: 3 additions & 3 deletions packages/qtwidget/qtwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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++);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions qlua/qluaapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 9184d51

Please sign in to comment.