Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix the virtuals generation and enable verbose build

  • Loading branch information...
commit 35828c7dad9018f8d9d7225ce2009a0af7bce5eb 1 parent e1f2d33
@mkottman authored
View
10 CMakeLists.txt
@@ -45,6 +45,13 @@ set(QT_USE_QTSQL 1)
set(QT_USE_QTXMLPATTERNS 1)
include(${QT_USE_FILE})
+set(EXTRA_LUA_OPTIONS )
+option(VERBOSE_BUILD "Create a verbose build which logs every binding call" OFF)
+if(VERBOSE_BUILD)
+ add_definitions(-DVERBOSE_BUILD)
+ set(EXTRA_LUA_OPTIONS -v)
+endif()
+
if(noqt)
set(QT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
#set(nomerge TRUE)
@@ -114,7 +121,8 @@ function(build_qt_lib_binding BINDING_HEADER)
add_custom_target(generate_${BINDING_NAME}_cpp
COMMAND ${LUA_CMD}
"${CMAKE_SOURCE_DIR}/generator/generator.lua"
- ${GEN_XML}
+ ${GEN_XML}
+ ${EXTRA_LUA_OPTIONS}
-i ${BINDING_HEADER} -i lqt_qt.hpp
-n ${BINDING_NAME}
-t ${CMAKE_SOURCE_DIR}/generator/qtypes.lua
View
6 common/lqt_qt.cpp
@@ -2,6 +2,7 @@
#include <QThread>
+#ifdef VERBOSE_BUILD
const char * callTypeToString(QMetaObject::Call call)
{
switch(call) {
@@ -18,13 +19,16 @@ case QMetaObject::CreateInstance: return "CreateInstance";
}
return "???";
}
+#endif
int lqtL_qt_metacall (lua_State *L, QObject *self, QObject *acceptor,
QMetaObject::Call call, const char *name,
int index, void **args)
{
+#ifdef VERBOSE_BUILD
printf("[%lx] metacall [%s] %s : %d\n", QThread::currentThreadId(), callTypeToString(call), name, index);
-
+#endif
+
int callindex = 0, oldtop = 0;
oldtop = lua_gettop(L);
lqtL_pushudata(L, self, name); // (1)
View
28 generator/classes.lua
@@ -480,12 +480,6 @@ function fill_wrapper_code(f)
local has_args = true
local wrap, line = ' int oldtop = lua_gettop(L);\n', ''
- wrap = wrap .. ' printf("[%lx] %s :: %s (%d)\\n", ' ..
- 'QThread::currentThreadId(), ' ..
- '"'..(f.xarg.member_of_class or f.xarg.fullname)..'", ' ..
- '"'..f.xarg.name..'", '..
- 'oldtop);\n'
-
if f.xarg.abstract then
ignore(f.xarg.fullname, 'abstract method', f.xarg.member_of_class)
return nil
@@ -511,8 +505,22 @@ function fill_wrapper_code(f)
else
line = 'self->'..f.xarg.fullname..'('
end
+ if VERBOSE_BUILD then
+ wrap = wrap .. ' printf("[%lx; %p] %s :: %s (%d)\\n", ' ..
+ 'QThread::currentThreadId(), self, ' ..
+ '"'..(f.xarg.member_of_class or f.xarg.fullname)..'", ' ..
+ '"'..f.xarg.name..'", '..
+ 'oldtop);\n'
+ end
else
line = f.xarg.fullname..'('
+ if VERBOSE_BUILD then
+ wrap = wrap .. ' printf("[%lx; static] %s :: %s (%d)\\n", ' ..
+ 'QThread::currentThreadId(), ' ..
+ '"'..(f.xarg.member_of_class or f.xarg.fullname)..'", ' ..
+ '"'..f.xarg.name..'", '..
+ 'oldtop);\n'
+ end
end
for i, a in ipairs(f.arguments) do
if not typesystem[a.xarg.type_name] then
@@ -803,12 +811,16 @@ function print_single_class(c)
print_meta('int '..shellname..'::lqtAddOverride(lua_State *L) {')
print_meta(' '..shellname..' *self = static_cast<'..shellname..'*>('..typesystem[c.xarg.fullname..'*'].get(1)..');')
print_meta(' const char *name = luaL_checkstring(L, 2);')
- print_meta(' // printf("Overriding %s in %s\\n", name, "'..shellname..'");')
+ if VERBOSE_BUILD then
+ print_meta(' printf("Overriding \'%s\' in %s [%p]\\n", name, "'..shellname..'", self);')
+ end
local virt = virtuals.sort_by_index(c)
for _, v in pairs(virt) do
print_meta(' if (!strcmp(name, "'..v.xarg.name..'")) {')
print_meta(' self->hasOverride.setBit('..v.virtual_index..');')
- print_meta(' // printf("-> updated %d to %d\\n", '..v.virtual_index..', (bool)self->hasOverride['..v.virtual_index..']);')
+ if VERBOSE_BUILD then
+ print_meta(' printf("-> updated %d to %d\\n", '..v.virtual_index..', (bool)self->hasOverride['..v.virtual_index..']);')
+ end
print_meta(' return 0;')
print_meta(' }')
end
View
2  generator/generator.lua
@@ -66,6 +66,8 @@ do
elseif argi=='-c' then
i = i + 1
template_file = select(i, ...)
+ elseif argi=='-v' then
+ VERBOSE_BUILD = true
else
filename = filename and error'duplicate filename' or argi
end
View
53 generator/virtuals.lua
@@ -8,11 +8,15 @@ function fill_virtuals(classes)
byname[c.xarg.fullname] = c
end
local function get_virtuals(c, includePrivate)
+ local methods = {}
+ for _, f in ipairs(c) do
+ if f.label=='Function' and f.xarg.virtual ~= '1' then
+ methods[f.xarg.name] = f
+ end
+ end
+
local ret = {}
- local virtual_index = 0
local function add_overload(name, func)
- virtual_index = virtual_index + 1
- func.virtual_index = virtual_index
ret[name] = func
end
@@ -32,7 +36,17 @@ function fill_virtuals(classes)
if type(base)=='table' then
local bv = get_virtuals(base, true)
for n, f in pairs(bv) do
- if not ret[n] then add_overload(n, f) end
+ -- print('found', n, 'in', b, 'for', c.xarg.name, 'have', not not ret[n])
+ if not ret[n] then
+ if methods[n] then
+ -- print('has', n, 'which is not marked virtual')
+ methods[n].xarg.virtual = '1'
+ add_overload(n, methods[n])
+ else
+ -- print('does not have', n)
+ add_overload(n, f)
+ end
+ end
end
end
end
@@ -43,11 +57,20 @@ function fill_virtuals(classes)
local n = string.match(f.xarg.name, '~') or f.xarg.name
if f.label=='Function'
and (includePrivate or f.xarg.access~='private')
- and (ret[n])
+ and ret[n]
then
+ -- print('adding', c.xarg.name, n)
f.xarg.virtual = '1'
+ add_overload(n, f)
end
end
+
+ local virtual_index = 0
+ for n, f in pairs(ret) do
+ virtual_index = virtual_index + 1
+ f.virtual_index = virtual_index
+ end
+
return ret, virtual_index
end
for c in pairs(classes) do
@@ -61,13 +84,13 @@ end
-- virtual methods call original virtual method if no corresponding Lua function is
-- found, pure virtual (abstract) methods throw Lua error.
function virtual_overload(v)
- local ret = ''
if v.virtual_overload then return v end
-- make return type
if v.return_type and not typesystem[v.return_type] then
ignore(v.xarg.fullname, 'unknown return type', v.return_type)
return nil, 'return: '..v.return_type
end
+ local ret = ''
local rget, rn, ret_as = '', 0
if v.return_type then rget, rn, ret_as = typesystem[v.return_type].get'oldtop+2' end
local retget = ''
@@ -101,17 +124,19 @@ function virtual_overload(v)
fallback = (v.return_type and 'return this->' or 'this->') .. v.xarg.fullname .. '(' .. fallback .. ');' ..
(v.return_type and '' or ' return;')
if v.xarg.abstract then
- fallback = 'luaL_error(L, "Abstract method %s not implemented! In %s", "' .. v.xarg.name .. '", lqtL_source(L,oldtop+1));'
+ fallback = 'luaL_error(L, "Abstract method %s for %s not implemented! In %s", "' .. v.xarg.name .. '", lqtL_source(L,oldtop+1));'
end
ret = proto .. ' {\n'
ret = ret .. ' int oldtop = lua_gettop(L);\n'
- ret = ret .. ' printf("[%lx] virtual %s :: %s (%d) => %d\\n", ' ..
- 'QThread::currentThreadId(), ' ..
- '"'.. v.xarg.member_of_class.. '", ' ..
- '"'..v.xarg.name..'", '..
- v.virtual_index .. ', '..
- '(int)(bool)hasOverride[' .. v.virtual_index .. ']'..
- ');\n'
+ if VERBOSE_BUILD then
+ ret = ret .. ' printf("[%lx; %p] virtual %s :: %s (%d) => %d\\n", ' ..
+ 'QThread::currentThreadId(), this, ' ..
+ '"'..v.xarg.member_of_class.. '", ' ..
+ '"'..v.xarg.name..'", '..
+ v.virtual_index .. ', '..
+ '(int)(bool)hasOverride[' .. v.virtual_index .. ']'..
+ ');\n'
+ end
ret = ret .. ' if (!hasOverride[' .. v.virtual_index .. ']) { \n'
ret = ret .. ' ' .. fallback .. '\n }\n'
ret = ret .. [[
Please sign in to comment.
Something went wrong with that request. Please try again.