Esempio n. 1
0
LUA_EXTERNC
#endif
QTIDE_API int luaopen_libqtide(lua_State *L)
{ 
  // load module 'qt'
  if (luaL_dostring(L, "require 'qt'"))
    lua_error(L);
  if (QApplication::type() == QApplication::Tty)
    luaL_error(L, "Graphics have been disabled (running with -nographics)");
  // register metatypes
  qRegisterMetaType<QPrinter*>("QPrinter*");
  // register classes
  QtLuaEngine::registerMetaObject(&QLuaBrowser::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QLuaTextEdit::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QLuaTextEditMode::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QLuaConsoleWidget::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QLuaEditor::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QLuaSdiMain::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QLuaMdiMain::staticMetaObject);
#if HAVE_QTWEBKIT
  QtLuaEngine::registerMetaObject(&QWebFrame::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QWebPage::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QWebView::staticMetaObject);
  QtLuaEngine::registerMetaObject(&QLuaBrowser::staticMetaObject);
#endif
  // class 'qluaide'
  lua_pushcfunction(L, qluaide_hook);
  luaQ_pushmeta(L, &QLuaIde::staticMetaObject);
  lua_call(L, 1, 0);
  // return
  return 1;
}
Esempio n. 2
0
LUA_EXTERNC QTUILOADER_API int
luaopen_libqtuiloader(lua_State *L)
{
  // load module 'qt'
  if (luaL_dostring(L, "require 'qt'"))
    lua_error(L);
  // enrichs class QUiLoader.
  luaQ_pushmeta(L, &QUiLoader::staticMetaObject);
  luaQ_getfield(L, -1, "__metatable");
  luaQ_register(L, qtuiloader_lib, QCoreApplication::instance());
  return 0;
}
Esempio n. 3
0
static void
hide_deletelater(lua_State *L, const QMetaObject *mo)
{
  luaQ_pushmeta(L, mo);
  lua_getfield(L, -1, "__metatable");
  // ..stack: metaclass
  lua_pushcfunction(L, no_methodcall);
  lua_setfield(L, -2, "deleteLater");
  lua_pushcfunction(L, no_methodcall);
  lua_setfield(L, -2, "deleteLater(QObject*)");
  // restore
  lua_pop(L, 1);
}
Esempio n. 4
0
int 
luaopen_libqttorch(lua_State *L)
{
  // load module 'qt'
  if (luaL_dostring(L, "require 'qt'"))
    lua_error(L);
  // load modules 'torch'
  if (luaL_dostring(L, "require 'torch'"))
    lua_error(L);
  torch_Tensor_id = luaT_checktypename2id(L, "torch.Tensor");

  // enrichs QImage
  luaQ_pushmeta(L, QMetaType::QImage);
  luaQ_getfield(L, -1, "__metatable");
  luaL_register(L, 0, qttorch_qimage_lib);

  
  return 0;
}
Esempio n. 5
0
int
QLuaApplication::Private::processArguments(int argc, char **argv)
{
  bool has_e = false;
  bool has_v = false;
  bool stdinmode = false;

  // Obtain and lock lua
  QtLuaLocker lua(theEngine);
  globalL = lua;
  
  // Good time to limit access to QtLuaConsole
  lua_pushcfunction(lua, hook_qluaconsole);
  luaQ_pushmeta(lua, &QLuaConsole::staticMetaObject);
  lua_call(lua, 1, 0);

  // parse lua argument 
  int argn = 1;
  int status;
  while (argn < argc)
    {
      const char *a;
      const char *s = argv[argn];
      if (s[0] != '-')
        break;
      if (s[1] == 0)
        break;
      argn += 1;
      if (s[1] == '-' && s[2] == 0)
        break;
      switch(s[1])
        {
        case '-':
          if (s[2]) 
            return printBadOption(s);
          break;
        case 'i':
          if (!strcmp(s, "-ide") || !strncmp(s, "-ide=", 5))
            break;
          else if (s[2]) 
            return printBadOption(s);
          interactive = ttyConsole = true;
          theConsole->setCtrlCHandler(QLuaConsole::ctrlCBreak);
          theConsole->setPrintCapturedOutput(true);
          break;
        case 'v':
          if (s[2]) 
            return printBadOption(s);
          has_v = true;
          break;
        case 'e':
          has_e = true;
          a = s + 2;
          if (a[0]==0 && argn < argc)
            a = argv[argn++];
          lua.setRunning();
          if (a && a[0])
            if ((status = doString(lua, a)))
              return status;
          break;
        case 'l':
          a = s + 2;
          if (a[0]==0 && argn < argc)
            a = argv[argn++];
          lua.setRunning();
          if (a && a[0])
            if ((status = doLibrary(lua, a)))
              return status;
          break;
        case 'h':
          if (s[2])
            return printBadOption(s);
          return printUsage();
          break;
        case 'n':
        case 'o':
        default:
          if (strcmp(s, "-nographics") &&
              strcmp(s, "-onethread") )
            return printBadOption(s);
          break;
        }
    }
  // script mode?
  if (argn>=argc && !has_e && !has_v)
    {
      int c = EOF;
#if HAVE_ISATTY
      bool stdin_is_tty = isatty(0);
#elif defined(WIN32)
      bool stdin_is_tty = _isatty(_fileno(stdin));
#else
      bool stdin_is_tty = true;
#endif
      if (stdin_is_tty)
        interactive = ttyConsole = true;
      else if ((c = fgetc(stdin)) != EOF)
        stdinmode = true;
      if (stdinmode)
        ungetc(c, stdin);
    }
  // handle script
  if (argn < argc)
    if ((status = doScript(lua, argc, argv, argn)))
      return status;
  // handle stdin
  if (stdinmode)
    if ((status = doScript(lua, argc, argv, argc)))
      return status;
  // run interactive if there are toplevel windows
  foreach(QWidget *w, QApplication::topLevelWidgets())
    if (w && w->isVisible() && w->windowType() != Qt::Desktop)
      interactive = true;
  // do we need to print the version?
  forceVersion = has_v;
  if (has_v && !interactive)
    printLuaVersion();
  return 0;
}