QVariant DataSource::headerData(int section, Qt::Orientation orientation, int role) const { lua_State *L = const_cast<lua_State*>(dub_L); if (role == Qt::DisplayRole) { if (!dub_pushcallback("header")) return QVariant(); lua_pushnumber(L, section + 1); lua_pushnumber(L, orientation); // <func> <self> <section> <orientation> if (!dub_call(3, 1)) { return QVariant(); } QVariant res = variantFromLua(L, -1); lua_pop(L, 1); return res; } else if (role == Qt::BackgroundRole || role == Qt::ForegroundRole) { if (!dub_pushcallback( role == Qt::BackgroundRole ? "background" : "foreground" )) return QVariant(); lua_pushnumber(L, section + 1); // <func> <self> <section> if (!dub_call(2, 1)) { return QVariant(); } if (!lua_isnil(L, -1)) { try { Color *color = *((Color **)dub_checksdata_n(L, -1, "mimas.Color")); QVariant res = *color; lua_pop(L, 1); return res; } catch(dub::Exception) { return QVariant(); } } } return QVariant(); }
//-------------------------------------------------------------- void ofLuaApp::keyPressed(int key) { if (!dub_pushcallback("keyPressed")) return; lua_pushnumber(dub_L, key); dub_call(2, 0); }
//-------------------------------------------------------------- void ofLuaApp::windowResized(int w, int h) { if (!dub_pushcallback("windowResized")) return; lua_pushnumber(dub_L, w); lua_pushnumber(dub_L, h); dub_call(3, 0); }
//-------------------------------------------------------------- void ofLuaApp::mouseMoved(int x, int y) { if (!dub_pushcallback("mouseMoved")) return; lua_pushnumber(dub_L, x); lua_pushnumber(dub_L, y); dub_call(3, 0); }
//-------------------------------------------------------------- void ofLuaApp::mouseReleased(int x, int y, int button) { if (!dub_pushcallback("mouseReleased")) return; lua_pushnumber(dub_L, x); lua_pushnumber(dub_L, y); lua_pushnumber(dub_L, button); dub_call(4, 0); }
QVariant DataSource::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { if (!dub_pushcallback("data")) return QVariant(); } else if (role == Qt::EditRole) { if (!dub_pushcallback("editData") && !dub_pushcallback("data")) return QVariant(); } else if (role == Qt::ToolTipRole) { if (!dub_pushcallback("tooltip")) return QVariant(); } else if (role == Qt::BackgroundRole) { if (!dub_pushcallback("background")) return QVariant(); } else if (role == Qt::ForegroundRole) { if (!dub_pushcallback("foreground")) return QVariant(); } else { return QVariant(); } lua_State *L = const_cast<lua_State*>(dub_L); lua_pushnumber(L, index.row() + 1); lua_pushnumber(L, index.column() + 1); // <func> <self> <row> <column> if (!dub_call(3, 1)) { // failed return QVariant(); } QVariant res; if (role == Qt::BackgroundRole || role == Qt::ForegroundRole) { if (!lua_isnil(L, -1)) { try { Color *color = *((Color **)dub_checksdata_n(L, -1, "mimas.Color")); res = *color; } catch (dub::Exception) { // ignore } } } else { res = variantFromLua(L, -1); } lua_pop(L, 1); return res; }
//-------------------------------------------------------------- void ofLuaApp::exit() { if (!dub_pushcallback("exit")) return; dub_call(1, 0); }
//-------------------------------------------------------------- void ofLuaApp::draw() { if (!dub_pushcallback("draw")) return; dub_call(1, 0); }
//-------------------------------------------------------------- void ofLuaApp::update() { if (!dub_pushcallback("update")) return; dub_call(1, 0); }
//-------------------------------------------------------------- void ofLuaApp::setup() { if (!dub_pushcallback("setup")) return; dub_call(1, 0); }