int lqtL_qt_metacall (lua_State *L, QObject *self, QObject *acceptor, QMetaObject::Call call, const char *name, int index, void **args) { int callindex = 0, oldtop = 0; oldtop = lua_gettop(L); lqtL_pushudata(L, self, name); // (1) lua_getfield(L, -1, LQT_OBJSIGS); // (2) if (lua_isnil(L, -1)) { // TODO: determine what is wrong lua_settop(L, oldtop); QMetaObject::activate(self, self->metaObject(), index, args); } else { //qDebug() << lua_gettop(L) << luaL_typename(L, -1); lua_rawgeti(L, -1, index + 1); // (3) if (!lua_isstring(L, -1)) { lua_settop(L, oldtop); QMetaObject::activate(self, self->metaObject(), index, args); } else { callindex = acceptor->metaObject()->indexOfSlot(lua_tostring(L, -1)); // qDebug() << "Found slot" << name << lua_tostring(L,-1) << "on" << acceptor->objectName() << "with index" << callindex; lua_pop(L, 2); // (1) lua_getfield(L, -1, LQT_OBJSLOTS); // (2) lua_rawgeti(L, -1, index+1); // (3) lua_remove(L, -2); // (2) index = acceptor->qt_metacall(call, callindex, args); lua_settop(L, oldtop); } } return -1; }
void lqtL_passudata (lua_State *L, const void *p, const char *name) { lqtL_pushudata(L, p, name); // used only when passing temporaries - should be deleted afterwards lua_getfield(L, -1, "delete"); lua_setfield(L, -2, "__gc"); return; }
void lqtL_passudata (lua_State *L, const void *p, const char *name) { lqtL_pushudata(L, p, name); // FIXME: these should be added, but it is not safe for now //lua_getfield(L, -1, "delete"); //lua_setfield(L, -2, "__gc"); return; }
static int lqtL_pushqobject(lua_State *L, QObject * object) { const QMetaObject * meta = object->metaObject(); while (meta) { QString className = meta->className(); className += "*"; char * cname = strdup(qPrintable(className)); lua_getfield(L, LUA_REGISTRYINDEX, cname); int isnil = lua_isnil(L, -1); lua_pop(L, 1); if (!isnil) { lqtL_pushudata(L, object, cname); free(cname); return 1; } else { free(cname); meta = meta->superClass(); } } return 0; }
void lqtL_copyudata (lua_State *L, const void *p, const char *name) { luaL_newmetatable(L, name); lua_pushstring(L, "new"); lua_rawget(L, -2); if (lua_isnil(L, -1)) { std::cerr << "cannot copy " << name << std::endl; lua_pop(L, 2); lua_pushnil(L); } else { lua_remove(L, -2); lqtL_pushudata(L, p, name); if (lqtL_pcall(L, 1, 1, 0)) { std::cerr << "error copying " << name << std::endl; lua_pop(L, 1); lua_pushnil(L); } // Enable autodeletion for copied stuff lua_getfield(L, -1, "delete"); lua_setfield(L, -2, "__gc"); } return; }