예제 #1
0
int LuaStack::executeScriptFile(const char* filename)
{
    CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");

    std::string buf(filename);
    //
    // remove .lua or .luac
    //
    size_t pos = buf.rfind(BYTECODE_FILE_EXT);
    if (pos != std::string::npos)
    {
        buf = buf.substr(0, pos);
    }
    else
    {
        pos = buf.rfind(NOT_BYTECODE_FILE_EXT);
        if (pos == buf.length() - NOT_BYTECODE_FILE_EXT.length())
        {
            buf = buf.substr(0, pos);
        }
    }

    FileUtils *utils = FileUtils::getInstance();
    //
    // 1. check .lua suffix
    // 2. check .luac suffix
    //
    std::string tmpfilename = buf + NOT_BYTECODE_FILE_EXT;
    if (utils->isFileExist(tmpfilename))
    {
        buf = tmpfilename;
    }
    else
    {
        tmpfilename = buf + BYTECODE_FILE_EXT;
        if (utils->isFileExist(tmpfilename))
        {
            buf = tmpfilename;
        }
    }

    std::string fullPath = utils->fullPathForFilename(buf);
    Data data = utils->getDataFromFile(fullPath);
    int rn = 0;
    if (!data.isNull())
    {
        if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0)
        {
            rn = executeFunction(0);
        }
    }
    return rn;
}
예제 #2
0
void CCLuaStack::executeObjectDestructor(CCObject* obj) {
    pushCCObject(obj, getLuaTypeNameByTypeId(typeid(*obj).name())); // obj
    lua_pushstring(m_state, "dtor"); // obj "dtor"
    lua_gettable(m_state, -2); // obj dtor
    if(lua_isnil(m_state, -1) || !lua_isfunction(m_state, -1)) {
        lua_pop(m_state, 2);
    } else {
        // push obj
        lua_pushvalue(m_state, -2); // obj dtor obj
        lua_remove(m_state, -3); // dtor obj
        executeFunction(1);
    }
}
예제 #3
0
int LuaStack::executeFunctionByHandler(int nHandler, int numArgs)
{
    int ret = 0;
    if (pushFunctionByHandler(nHandler))                                /* L: ... arg1 arg2 ... func */
    {
        if (numArgs > 0)
        {
            lua_insert(_state, -(numArgs + 1));                        /* L: ... func arg1 arg2 ... */
        }
        ret = executeFunction(numArgs);
    }
    lua_settop(_state, 0);
    return ret;
}
예제 #4
0
int CCLuaStack::executeFunctionByHandler(int nHandler, int numArgs)
{
    if (pushFunctionByHandler(nHandler))                                /* L: ... arg1 arg2 ... func */
    {
        if (numArgs > 0)
        {
            lua_insert(m_state, -(numArgs + 1));                        /* L: ... func arg1 arg2 ... */
        }
        return executeFunction(numArgs);
    }

    lua_pop(m_state, numArgs); // remove args from stack
    return 0;
}
예제 #5
0
int CCLuaStack::executeFunctionByHandler(int nHandler, int numArgs, CCObject* collector, SEL_ScriptReturnedValueCollector sel)
{
    int ret = 0;
    if (pushFunctionByHandler(nHandler))                                /* L: ... arg1 arg2 ... func */
    {
        if (numArgs > 0)
        {
            lua_insert(m_state, -(numArgs + 1));                        /* L: ... func arg1 arg2 ... */
        }
        ret = executeFunction(numArgs, collector, sel);
    }
    lua_settop(m_state, 0);
    return ret;
}
예제 #6
0
int LuaStack::executeScriptFile(const char* filename)
{
    CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");

    FileUtils *utils = FileUtils::getInstance();
    std::string fullPath = utils->fullPathForFilename(filename);
    Data data = utils->getDataFromFile(fullPath);
    int rn = 0;
    if (!data.isNull()) {
        if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0) {
            rn = executeFunction(0);
        }
    }
    return rn;
}
예제 #7
0
int LuaStack::executeGlobalFunction(const char* functionName, int argsNum)
{  

  lua_getglobal(_state, functionName);       /* query function by name, stack: function */
  if (!lua_isfunction(_state, -1))
  {
    CCLOG("[LUA ERROR] name '%s' does not represent a Lua function", functionName);
    lua_pop(_state, 1);
    return 0;
  }
  if (argsNum > 0)
  {
    lua_insert(_state, -(argsNum + 1));                        /* L: ... func arg1 arg2 ... */
  }
  return executeFunction(argsNum);
}
예제 #8
0
int LuaStack::executeScriptFile(const char* filename)
{
    CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");

    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
    ssize_t chunkSize = 0;
    unsigned char *chunk = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &chunkSize);
    int rn = 0;
    if (chunk) {
        if (luaLoadBuffer(_state, (const char*)chunk, (int)chunkSize, fullPath.c_str()) == 0) {
            rn = executeFunction(0);
        }
        delete chunk;
    }
    return rn;
}
예제 #9
0
		void CRpcExecutor::run()
		{
			San2::Utils::bytes b;
			unsigned int functionId;
			
			// needs some kind of return value
			while(!isTerminated())
			{
				if (!(m_channel.recvData(functionId, b, m_timRX)))
				{
					 //printf("FAIL: CRpcExecutor::run()::recvData()\n");
					 break;
				}
				
				if (executeFunction(functionId, b) != RpcError::SUCCESS)
				{
					FILE_LOG(logDEBUG3) << "FAIL:CRpcExecutor::run()::executeFunction()";	
				}
			}
		}
예제 #10
0
파일: message.c 프로젝트: dewey/layman
/**
 * Creates a Message instance with default values.
 * To modify those values, use the corresponding functions.
 *
 * \param module the module to debug. If you don't know, set "layman"
 * \param out where to write info
 * \param err where to write errors
 * \param dbg where to write debug information
 *
 * \return a new instance of a Message object. It must be freed with messageFree()
 */
Message *messageCreate(const char* module,
			FILE* out,
			FILE* err,
			FILE* dbg)
{
	PyObject *pyout, *pyerr, *pydbg;

	if (!out || fileno(out) <= 0)
		out = stdout;
	if (!err || fileno(err) <= 0)
		err = stderr;
	if (!dbg || fileno(dbg) <= 0)
		dbg = stderr;

	pyout = PyFile_FromFile(out, "", "w", 0);
	pyerr = PyFile_FromFile(err, "", "w", 0);
	pydbg = PyFile_FromFile(dbg, "", "w", 0);

	PyObject *object = executeFunction("layman.debug", "Message",
					"(sOOO)",
					module,
					pyout,
					pyerr,
					pydbg);

	Py_DECREF(pyout);
	Py_DECREF(pyerr);
	Py_DECREF(pydbg);

	if (!object)
		return NULL;

	Message *ret = malloc(sizeof(Message));
	ret->object = object;

	return ret;
}
예제 #11
0
int LuaStack::executeString(const char *codes)
{
    luaL_loadstring(_state, codes);
    return executeFunction(0);
}
예제 #12
0
Variable Module::executeFunction(const std::string &name, const Variable &params) const
{
    return executeFunction(name, params, *this);
}
예제 #13
0
void PgxEditor::createActions()
{
    newpgxeditor_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/editor.png")), tr("New"), this);
    newpgxeditor_action->setShortcuts(QKeySequence::New);
    newpgxeditor_action->setStatusTip(tr("New editor"));
    connect(newpgxeditor_action, SIGNAL(triggered()), this, SIGNAL(newPgxeditor()));

    cut_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/cut.png")), tr("Cut"), this);
    cut_action->setShortcuts(QKeySequence::Cut);
    cut_action->setStatusTip(tr("Cut selected text and copy to clipboard"));
    connect(cut_action, SIGNAL(triggered()), this, SLOT(cut()));

    copy_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/copy.png")), tr("Copy"), this);
    copy_action->setShortcuts(QKeySequence::Copy);
    copy_action->setStatusTip(tr("Copy selected text to clipboard"));
    connect(copy_action, SIGNAL(triggered()), this, SLOT(copy()));

    paste_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/paste.png")), tr("Paste"), this);
    paste_action->setShortcuts(QKeySequence::Paste);
    paste_action->setStatusTip(tr("Paste text from clipboard"));
    connect(paste_action, SIGNAL(triggered()), this, SLOT(paste()));

    if(!editor_name.isEmpty()) {
        save_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/save.png")), tr("&Save"), this);
        save_action->setShortcuts(QKeySequence::Save);
        save_action->setStatusTip(tr("Save function"));
        save_action->setEnabled(false);
        connect(save_action, SIGNAL(triggered()), this, SLOT(saveFunction()));

        execute_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/execute.png")), tr("&Execute"), this);
        execute_action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
        execute_action->setStatusTip(tr("Execute function"));
        connect(execute_action, SIGNAL(triggered()), this, SLOT(executeFunction()));
    }

    selected_execute_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/selected_execute.png")), tr("&Run"), this);
    selected_execute_action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E));
    selected_execute_action->setStatusTip(tr("Execute selected text"));
    if(!editor_name.isEmpty())
        selected_execute_action->setEnabled(false);
    connect(selected_execute_action, SIGNAL(triggered()), this, SLOT(executeText()));

    wrap_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/wrap.png")), tr("Wrap/Un-wrap lines"),this);
    wrap_action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W));
    wrap_action->setStatusTip(tr("Toggle line wrapping"));
    wrap_action->setCheckable(true);
    wrap_action->setChecked(true);
    connect(wrap_action, SIGNAL(triggered()), this, SLOT(toggleWrap()));

    find_action = new QAction(QIcon(qApp->applicationDirPath().append("/icons/find.png")), tr("Find"), this);
    find_action->setShortcuts(QKeySequence::Find);
    find_action->setStatusTip(tr("Find/replace text"));
    connect(find_action, SIGNAL(triggered()), this, SLOT(toggleFindBar()));

    casesensitivity_action = new QAction(tr("Cs"), this);
    casesensitivity_action->setToolTip(tr("Case sensitive"));
    casesensitivity_action->setCheckable(true);
    casesensitivity_button = new QToolButton;
    casesensitivity_button->setDefaultAction(casesensitivity_action);
    casesensitivity_button->setVisible(false);

    wholeword_action = new QAction(tr("W"), this);
    wholeword_action->setToolTip(tr("Whole word"));
    wholeword_action->setCheckable(true);
    wholeword_button = new QToolButton;
    wholeword_button->setDefaultAction(wholeword_action);
    wholeword_button->setVisible(false);

    backwards_action = new QAction(tr("B"), this);
    backwards_action->setToolTip(tr("Backwards"));
    backwards_action->setCheckable(true);
    backwards_button = new QToolButton;
    backwards_button->setDefaultAction(backwards_action);
    backwards_button->setVisible(false);
}