Example #1
0
int LuaStack::executeScriptFile(const char* filename)
{
    std::string code("require \"");
    code.append(filename);
    code.append("\"");
    return executeString(code.c_str());
}
Example #2
0
bool Console::keyDown(keypress key, keymod mod)
{
	if (!isDown())
		return false;

	// If we intercept a toggleConsole() command, then execute it.
	keypress convertedKey     = Input::convertKeycode(key);
	std::string commandString = bindings.getCommandString(convertedKey);
	if (commandString == "toggleConsole()")
	{
		toggle();
		return true;
	}

	_textInput.keyDown(key, mod);
	TextInput::text_input_status status = _textInput.getStatus();
	if (status == TextInput::text_input_complete)
	{
		// Add the completed string to the history.
		// Front = top    = oldest,
		// Back  = bottom = newest
		std::string finishedText = _textInput.getText();
		write(finishedText);

		if (_history.size() > _historySize)
			_history.pop_front();
		
		executeString(finishedText);
		_textInput.clear();
	}
	else if (status == TextInput::text_input_cancelled)
		_textInput.clear();

	return true;
}
Example #3
0
void startScript(std::string strDebugArg)
{
    // register lua engine
    auto engine = LuaEngine::getInstance();
    if (!strDebugArg.empty())
    {
        // open debugger.lua module
        cocos2d::log("debug args = %s", strDebugArg.c_str());
        luaopen_lua_debugger(engine->getLuaStack()->getLuaState());
        engine->executeString(strDebugArg.c_str());
    }

    std::string code("require \"");
    code.append(ConfigParser::getInstance()->getEntryFile().c_str());
    code.append("\"");
    engine->executeString(code.c_str());
}
Example #4
0
void ScriptCore::setItem(ScriptCoreItemI* item)
{
	if (!item)
		return;

	ScriptCoreItemI* temp = ItemJSBinding::GetItem(m_uiItemId);

	if (temp == item)
		return;

	delItem();

	m_uiItemId = ItemJSBinding::AddItem(item);
	executeString(gcString("item.SetItem({0});", (int32)m_uiItemId).c_str());
}
Example #5
0
void ScriptManager::executeDefaultCode() {
	static const Common::UString fnNewIndexSource =
	    "function mt_new_index(table, key, value)"
	    "    local objClass = getmetatable(table).__objectClass"
	    "    if objClass ~= nil then"
	    "        local cppInstance = rawget(table, \"CPP_instance\")"
	    "        if cppInstance[key] ~= nil then"
	    "            cppInstance[key] = value"
	    "        end"
	    "        return"
	    "    end"
	    "    rawset(table, key, value)"
	    "end";

	executeString(fnNewIndexSource);
}
void LuaStack::connectDebugger(int debuggerType, const char *host, int port, const char *debugKey, const char *workDir)
{
    _debuggerType = debuggerType;
    if (debuggerType == kCCLuaDebuggerLDT)
    {
        lua_pushboolean(_state, 1);
        lua_setglobal(_state, kCCLuaDebuggerGlobalKey);
        
        char buffer[512];
        memset(buffer, 0, sizeof(buffer));
        sprintf(buffer, "require('ldt_debugger')('%s', %d, '%s', nil, nil, '%s')",
                host ? host : "127.0.0.1",
                port > 0 ? port : 10000,
                debugKey ? debugKey : "luaidekey",
                workDir ? workDir : "");
        executeString(buffer);
    }
}
Example #7
0
void PythonContext::executeFile(const QString &filename)
{
  QFile f(filename);

  if(!f.exists())
  {
    emit exception(lit("FileNotFoundError"), tr("No such file or directory: %1").arg(filename), -1,
                   {});
    return;
  }

  if(f.open(QIODevice::ReadOnly | QIODevice::Text))
  {
    QByteArray py = f.readAll();

    executeString(filename, QString::fromUtf8(py));
  }
  else
  {
    emit exception(lit("IOError"), QFormatStr("%1: %2").arg(f.errorString()).arg(filename), -1, {});
  }
}
int CCLuaStack::executeScriptFile(const char* filename)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    std::string code("require \"");
    code.append(filename);
    code.append("\"");
    return executeString(code.c_str());
#else
    ++m_callFromLua;
    int nRet = luaL_dofile(m_state, filename);
    --m_callFromLua;
    CC_ASSERT(m_callFromLua >= 0);
    // lua_gc(m_state, LUA_GCCOLLECT, 0);
    
    if (nRet != 0)
    {
        CCLOG("[LUA ERROR] %s", lua_tostring(m_state, -1));
        lua_pop(m_state, 1);
        return nRet;
    }
    return 0;
#endif
}
Example #9
0
int LuaStack::executeScriptFile(const char* filename)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    std::string code("require \"");
    code.append(filename);
    code.append("\"");
    return executeString(code.c_str());
#else
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
    ++_callFromLua;
    int nRet = luaL_dofile(_state, fullPath.c_str());
    --_callFromLua;
    CC_ASSERT(_callFromLua >= 0);
    // lua_gc(_state, LUA_GCCOLLECT, 0);
    
    if (nRet != 0)
    {
        CCLOG("[LUA ERROR] %s", lua_tostring(_state, -1));
        lua_pop(_state, 1);
        return nRet;
    }
    return 0;
#endif
}
Example #10
0
int LuaStack::reload(const char* moduleFileName)
{
    if (nullptr == moduleFileName || strlen(moduleFileName) == 0)
    {
        CCLOG("moudulFileName is null");
        return 1;
    }

    lua_getglobal(_state, "package");                         /* L: package */
    lua_getfield(_state, -1, "loaded");                       /* L: package loaded */
    lua_pushstring(_state, moduleFileName);
    lua_gettable(_state, -2);                                 /* L:package loaded module */
    if (!lua_isnil(_state, -1))
    {
        lua_pushstring(_state, moduleFileName);               /* L:package loaded module name */
        lua_pushnil(_state);                                  /* L:package loaded module name nil*/
        lua_settable(_state, -4);                             /* L:package loaded module */
    }
    lua_pop(_state, 3);
    
    std::string name = moduleFileName;
    std::string require = "require \'" + name + "\'";
    return executeString(require.c_str());
}
Example #11
0
void ScriptToolKit::clearScriptStack()
{
	mTickStackSize = 0;
	executeString( "Pulsar.TickScripts = {}" );
}
Example #12
0
bool PythonScript::executeImpl()
{
    return executeString();
}
Example #13
0
bool PythonScript::executeImpl() {
  TemporaryValue holder(m_threadID, getThreadID());
  return executeString();
}
void TDLuaMgr::excuteConvertString(std::string pLuaString)
{
	executeString(convertExcuteString(pLuaString));
}
bool TDLuaMgr::executeLua()
{
	std::vector<LUA_ELEM *> tempList;

	m_mutex.lock();
	// 1、从队列中先取出执行的脚本函数
	// 先缓存在临时列表中,然后再执行根据临时列表中的操作,这是因为我们不希望 m_LuaElemList 被锁住太久
	unsigned int size = m_luaElemList.size();
	for (unsigned int i = 0; i < size; i++)
	{
		tempList.push_back(m_luaElemList[i]);
	}
	m_luaElemList.clear();
	m_mutex.unlock();
	if (tempList.size() == 0) {
		return false;
	}
	size = tempList.size();
	if (size > 1000)
		cocos2d::log("Lua queue has too much pending request(%d)\n", size);

	for (unsigned int i = 0; i < size; i++)
	{
		LUA_ELEM* elem = tempList[i];

		// 若该字段不为 NULL,表示为 lua string,直接执行
		if (elem->pLuaString.size() > 0)
		{
			executeString(elem->pLuaString);
		}
		else if (elem->Func != -1)
		{
			// 执行指定定义类型的函数
			switch (elem->Func)
			{
				// 收到的消息
			case FUNC_MESSAGE:

				excuteMessage(elem->fd, elem->stream);
				break;

				// 收到的数据库返回结果
			case FUNC_DB_RESULT:
				excuteDBResult(elem->cookie, elem->ret, elem->errmsg.c_str(), elem->stream);
				break;
				// 收到新连接
			case FUNC_NEW_CONNECTION:
				excuteNewConnect(elem->cookie, elem->fd);
				break;
				// 连接断开
			case FUNC_CONNECTION_LOST:
				excuteConnectLost(elem->fd);
				break;

			default:
				break;
			}
		}
		delete elem;
	}

	tempList.clear();

	return true;
}
Example #16
0
void ofxPython::executeScript(const string& path)
{
	executeString(ofBufferFromFile(path).getText());
	PythonErrorCheck();
}
Example #17
0
void PythonContext::executeString(const QString &source)
{
  executeString(lit("<interactive.py>"), source);
}