Exemple #1
0
/** \brief Ausführen von Lua code aus einen String.

    Diese Funktion wird für die Konsolenanwendung benötigt.
*/
void LuaWorker::on_doString(const QString &sCmd)
{
    if (m_pConsole==NULL)
        return;

    qDebug("on_doString(\"%s\"); thread id: %d",
           sCmd.toStdString().c_str(),
           reinterpret_cast<int>(QThread::currentThreadId()));

    try
    {
        doString(sCmd, "command_line_chunk");
        emit finished();
    }
    catch(Exception &exc)
    {
        emit error(exc.getMessage());
    }
    catch(std::exception &exc)
    {
        emit error(exc.what());
    }
    catch(...)
    {
        emit error("Internal error: FrmConsole::executeCommand");
    }
}
Exemple #2
0
void Core::onMessageQueueEmpty(double elapsedSeconds)
{
    if (!run)
    {
        return;
    }

    if (luaChunk != NULL)
    {
        doString(luaChunk);
        luaChunk = NULL;
    }

    static double previousElapsedSeconds = 0;
    static double dt = 0;

    dt += elapsedSeconds - previousElapsedSeconds;
    previousElapsedSeconds = elapsedSeconds;

    if (dt < minDt)
    {
        return;
    }

    if (dt > maxDt)
    {
        dt = maxDt;
    }

    // \todo Update all entities with dt.

    // dt is an accumulator; it has just been
    // consumed, so now it should be cleared.
    dt = 0;
}
Exemple #3
0
//this function maps the path to a string to the string contained in path, if the string has been loaded 
//before then the strings path is just the key to the string at the path else
//the path is used to return the string
std::string StringLoader::doString( std::string _path){

	for( auto s: strings){

		if(s.first == _path){

            std::cout<< "string at " << _path << " found."<< std::endl;
            return s.second;
        }
    }

    //temporary string container
    std::string temp, input;

    std::ifstream textFile( _path.c_str());

    if( textFile){

        while(getline( textFile, input)){ 

            temp += input + '\n';
        }

        //setting key value pair
        strings[ _path] = temp;

        //recursivley call function again, this way string will have been initialised
        return doString( _path);
    }else{

        std::cout <<"File at " << _path << " not found."<< std::endl;
        return "File does not exist";
    }
}
void fsScriptLua::runTest( )
{
    std::cout << "fsScriptLua::runTest";

    std::cout << "//-testing a file\n";
	doFile("scripts/hello.lua");
    
    std::cout << "//-testing a string\n";
    doString("io.write ('hello again\\n')");
    
    std::cout << "//-putting some vars\n";
    doString("someInt = 5");
    doString("someFloat = 8.1234123");
    doString("someString = 'ffffffffffffffffff'");
    
    std::cout << "//-getting some vars\n";
    std::cout << "someInt:" << getInt("someInt") << std::endl;
    std::cout << "someFloat:" << getFloat("someFloat") << std::endl;
    std::cout << "someString:" << getString("someString") << std::endl;
    
    
}
Exemple #5
0
void LuaWrapper::setup(){
  //grab a new instance of script
  script = new SLB::Script();
  script->setPrintCallback(&printCallback_stderr);

  exportApi(SLB::Manager::defaultManager());

  doString("SLB.using(SLB.Barrel)");
  doString(" \
    function evaluate(x) \
      return load(x)() \
    end \
  ");
}
Exemple #6
0
    virtual void SetUp()
    {
        LuaTest::SetUp();

        cpathAppend("../ironbee/util/.libs/?.so");

        pathAppend("../?.lua");
        pathAppend(TOP_SRCDIR_STR "/lua/?.lua");

        doString("ibcutil = require('ibcutil')");

        // Clear stack.
        lua_settop(L, 0);
    }
Exemple #7
0
	bool doFile(lua_State* L, std::string fileName)
	{
		
		std::ifstream file(fileName);
		if(!file)
		{
			throw std::invalid_argument( "Invalid file input in doFile()" );
		}
		else
		{
			std::stringstream ss;
			ss << file.rdbuf();
			return doString(L,ss.str());
		}
	}
Exemple #8
0
bool Core::init()
{
    lua = luaL_newstate();
    assert(lua != 0);
    luaL_checkversion(lua);

    // Stop garbage collector.
    lua_gc(lua, LUA_GCSTOP, 0); 

    // Load Lua core libraries.
    // \todo maybe don't load lua libraries to save memory (and omit from build).
    luaL_openlibs(lua);

    // Register core function with Lua.
    lua_register(lua, "quit", Script::quit);
    lua_register(lua, "backgroundColor", Script::backgroundColor);
    lua_register(lua, "create", Script::create);
    lua_register(lua, "pos", Script::pos);
    lua_register(lua, "move", Script::move);
    lua_register(lua, "destroy", Script::destroy);
    lua_register(lua, "pc", Script::pc);
    lua_register(lua, "tone", Script::tone);

    // Restart garbage collector.
    lua_gc(lua, LUA_GCRESTART, 0);

    if (!Graphics::init())
    {
        return false;
    }

    if (!assetContainer.setContainerFilename("content.seng"))
    {
		Platform::error << "Failed to load content file: content.seng" << std::endl << std::endl;
		Platform::error << "AssetContainer error: " << assetContainer.getLastError() << std::endl << std::endl;
        return false;
    }
    char initScript[1024];
    if (!assetContainer.getString("scripts/init.lua", initScript, 1024))
    {
		Platform::error << "AssetContainer error: " << assetContainer.getLastError();
        return false;
    }
    doString(initScript);
    return true;
}
Exemple #9
0
//-------------------------------------------------------------------------------------------------
void LuaWorker::on_doFile(IFile *pFile)
{
    if (m_pConsole==NULL || pFile==NULL)
        return;

    qDebug("on_doFile(%s); thread id: %d",
           pFile->getName().toStdString().c_str(),
           reinterpret_cast<int>(QThread::currentThreadId()));

    try
    {
        QVector<QString> vLines = pFile->getLines();
        QString sScript;
        for (int i=0; i<vLines.size(); ++i)
        {
            sScript += vLines[i];
        }

        if (m_luaState==NULL)
            throw LuaException(QString("Can't execute Lua code fragment \"%1\": Lua state is not initialized").arg(sScript));

        doString(sScript, pFile->getName());
        emit finished();
    }
    catch(LuaException &exc)
    {
        exc.setFile(pFile);

        QString sMsg = QString("%1 in Line %2").arg(exc.getMessage())
                                               .arg(exc.getLine());
        emit error(sMsg);
    }
    catch(Exception &exc)
    {
        emit error(exc.getMessage());
    }
    catch(std::exception &exc)
    {
        emit error(exc.what());
    }
    catch(...)
    {
        emit error("Internal error: FrmConsole::executeCommand");
    }
}
Exemple #10
0
 void pathAppend(std::string path) {
     doString("package.path = package.path .. \";" + path + "\"");
 }
Exemple #11
0
void CLua::doString(const std::string str)
{
	doString(str.c_str());
}
Exemple #12
0
void CLua::doFile(const char* fn)
{
	//luaL_dofile(L, fn);
	doString(pfGetString(fn));
}
Exemple #13
0
void
LuaManager::parseScript(DataStreamPtr& stream, const String&)
{
  currentFileName = stream->getName();
  doString(stream->getAsString());
}
Exemple #14
0
 int cpathAppend(std::string cpath) {
     return doString("package.cpath = package.cpath .. \";" + cpath + "\"");
 }
Exemple #15
0
 int pathAppend(std::string path) {
     return doString("package.path = package.path .. \";" + path + "\"");
 }
Exemple #16
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;
}
Exemple #17
0
 void cpathAppend(std::string cpath) {
     doString("package.cpath = package.cpath .. \";" + cpath + "\"");
 }