Lua keyword 'end' interferes with QPainter:end()
RhettTR opened this issue · comments
RhettTR commented
I may have come across a small problem. It seems that Lua keywords can not in any way be like Qt property, member or function names. Look at this example (test.lua):
package.cpath = "/home/test/projects/alben/build-lqt/lib/?.so"
local QtCore = require 'qtcore'
local QtGui = require 'qtgui'
local QtWidgets = require 'qtwidgets'
local app = QtWidgets.QApplication.new(0, {})
local frame = QtWidgets.QFrame.new()
frame:setFrameRect(QtCore.QRect(0, 0, 640, 400))
function frame:paintEvent(event)
local painter = QtGui.QPainter(frame)
painter:begin(frame)
painter:drawLine(10, 10, 234, 34)
-- painter:end()
end
frame:show()
app.exec()
As the script stands, it works. But change
-- painter:end()
to
painter:end()
and the script reports
/home/test/projects/alben/scripts/test.lua:19: '<name>' expected near 'end
In the Qt doc it says that one does not normally need to call end(). I am not an expert in qtLua so this may not be an issue, but it can not be good practice to have a Begin hang in the air. Besides, the debug reports a call to end() as missing.
Saniko commented
Now you can try use:
painter['end'](painter)
RhettTR commented
It works. Thank you.