Ejemplo n.º 1
0
int syscmd(lua_State *L)
{
    if (luaT_check(L, 1, LUA_TTABLE))
    {
        lua_pushinteger(L, 1);
        lua_gettable(L, -2);
        std::wstring cmd(luaT_towstring(L, -1));
        lua_pop(L, 1);
        if (cmd == L"tray")
        {
            int n = luaL_len(L, -1);
            std::deque<std::wstring> text;
            for (int i=2; i<=n; ++i)
            {
                lua_pushinteger(L, i);
                lua_gettable(L, -2);
                if (lua_isstring(L, -1))
                {
                    std::wstring tmp(luaT_towstring(L, -1));
                    text.push_back(tmp);
                }
                lua_pop(L, 1);
            }
            lua_pop(L, 1);
            if (!text.empty())
            {
                Msg m;
                COLORREF text_color = 0; COLORREF bgnd_color = 0;
                if (base::translateColors(L, text[0].c_str(), &text_color, &bgnd_color))
                {
                    m.textcolor = text_color;
                    m.bkgndcolor = bgnd_color;
                    text.pop_front();
                }
                else
                {
                    m.textcolor =  g_tray.traySettings().text;
                    m.bkgndcolor = g_tray.traySettings().background;
                }
                for (int i=0,e=text.size();i<e;++i) {
                   if (i != 0) m.text.append(L" ");
                   m.text.append(text[i]);
                }
                g_tray.addMessage(m);
            }
            lua_pushnil(L);
            return 1;
        }
    }
    return 1;
}
Ejemplo n.º 2
0
void pluginFormatByType(lua_State* L, int index, tstring *buf)
{
    int i = index;
    int type = lua_type(L, i);
    tchar dbuf[32];
    buf->clear();

    switch (type)
    {
    case LUA_TNIL:
        buf->append(L"[nil]");
        break;
    case LUA_TNUMBER:
        swprintf(dbuf, L"%d", lua_tointeger(L, i));
        buf->append(dbuf);
        break;
    case LUA_TBOOLEAN:
        buf->append( (lua_toboolean(L, i) == 0) ? L"[false]" : L"[true]" );
        break;
    case LUA_TSTRING:
        buf->append(luaT_towstring(L, i));
        break;
    /*case LUA_TUSERDATA:
    case LUA_TLIGHTUSERDATA:
    case LUA_TFUNCTION:
    case LUA_TTHREAD:
    case LUA_TTABLE:*/
    default:
        buf->append(L"[?]");
        break;
    }
}
Ejemplo n.º 3
0
int syscmd(lua_State *L)
{
    if (luaT_check(L, 1, LUA_TTABLE))
    {
        lua_pushinteger(L, 1);
        lua_gettable(L, -2);
        std::wstring cmd(luaT_towstring(L, -1));
        lua_pop(L, 1);
        if (cmd == L"sound" || cmd == L"play")
        {
            std::vector<std::wstring> params;
            int n = luaL_len(L, -1);
            std::wstring text;
            for (int i=2; i<=n; ++i)
            {
                lua_pushinteger(L, i);
                lua_gettable(L, -2);
                if (!lua_isstring(L, -1))
                {
                    luaT_pushwstring(L, L"Неверные параметры");
                    return 1;
                }
                else
                {
                    std::wstring p(luaT_towstring(L, -1));
                    params.push_back(p);
                }
                lua_pop(L, 1);
            }
            lua_pop(L, 1);
            
            std::wstring error;
            if (cmd == L"play")
                player->runPlayCommand(params, &error);
            else
                player->runCommand(params, &error);
            if (!error.empty())
                luaT_pushwstring(L, error.c_str() );
            else
                lua_pushnil(L);
            return 1;
        }
    }
    return 1;
}
Ejemplo n.º 4
0
bool loadModules()
{
    loadEmbeddedModules(L);

    ChangeDir cd;
    if (!cd.changeDir(L"modules"))
    {
        lua_register(L, "require", require_stub);
        return false;
    }

    tstring path(cd.getCurrentDir());
    path.append(L"\\modules\\?.dll");
    luaopen_package(L);
    lua_pushstring(L, "path");
    lua_pushstring(L, "");
    lua_settable(L, -3);
    lua_pushstring(L, "cpath");
    lua_pushstring(L, TW2A(path.c_str()));
    lua_settable(L, -3);
    lua_setglobal(L, "package");
    lua_pop(L, 1);

    std::vector<tstring> files;
    {
        WIN32_FIND_DATA fd;
        memset(&fd, 0, sizeof(WIN32_FIND_DATA));
        HANDLE file = FindFirstFile(L"*.*", &fd);
        if (file != INVALID_HANDLE_VALUE)
        {
            do
            {
                if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
                {
                    if (Module::isModule(fd.cFileName))
                        files.push_back(fd.cFileName);
                }
            } while (::FindNextFile(file, &fd));
            ::FindClose(file);
        }
    }

    for (int j = 0, je = files.size(); j < je; ++j)
    {
        TW2A w2a(files[j].c_str());
        if (luaL_dofile(L, w2a))
        {
            tstring error(L"Ошибка при загрузке модуля: '");
            error.append(files[j]);
            error.append(L"' - ");
            error.append(luaT_towstring(L, -1));
            pluginOut(error.c_str());
        }
    }
    return true;
}