int msdp_multi_command(lua_State *L, const char* cmd, const char* cmdname) { if (msdp_isoff()) return msdpOffError(L, cmdname); if (luaT_check(L, 1, LUA_TSTRING) || luaT_check(L, 1, LUA_TTABLE)) { std::vector<std::string> vals; if (lua_isstring(L, 1)) vals.push_back(lua_tostring(L, 1)); else { lua_pushnil(L); // first key while (lua_next(L, -2) != 0) // key index = -2, value index = -1 { if (!lua_isstring(L, -1)) pluginInvArgs(L, TA2W(cmdname)); vals.push_back(lua_tostring(L, -1)); lua_pop(L, 1); } } if (!strcmp(cmd,"REPORT")) getMsdp()->report(_cp, &vals); else if (!strcmp(cmd,"UNREPORT")) getMsdp()->unreport(_cp, &vals); if (!vals.empty()) getMsdp()->send_varvals(cmd, vals); return 0; } return pluginInvArgs(L, TA2W(cmdname)); }
bool Plugin::runMethod(const char* method, int args, int results, bool *not_supported) { lua_getglobal(L, module.c_str()); if (!lua_istable(L, -1)) { lua_pop(L, 1); return false; } lua_pushstring(L, method); lua_gettable(L, -2); if (!lua_isfunction(L, -1)) // not supported function in plugin { lua_pop(L, 2); if (not_supported) *not_supported = true; return true; } lua_insert(L, -(args + 2)); lua_pop(L, 1); Plugin *old = _cp; _cp = this; if (lua_pcall(L, args, results, 0)) { // error in call TA2W m(method); if (luaT_check(L, 1, LUA_TSTRING)) pluginMethodError(m, lua_toerror(L)); else pluginMethodError(m, L"неизвестная ошибка"); _cp = old; lua_settop(L, 0); return false; } _cp = old; return true; }
int netserver_check(lua_State *L) { if (!luaT_check(L, 1, LUA_TNUMBER)) return luaT_error(L, "netserver: check [incorrect parameter]"); int mseconds = lua_tointeger(L, -1); selector.Check(mseconds); return 0; }
int luaimage_width(lua_State *L) { if (luaT_check(L, 1, LUAT_IMAGE)) { Image *p = (Image *)luaT_toobject(L, 1); lua_pushinteger(L, p->width()); return 1; } return pluginInvArgs(L, L"image:width"); }
int luaimage_towatch(lua_State *L) { if (luaT_check(L, 1, LUAT_IMAGE)) { Image *img = (Image *)luaT_toobject(L, 1); wchar_t buffer[40]; swprintf(buffer, L"width=%d,height=%d", img->width(), img->height()); luaT_pushwstring(L, buffer); return 1; } return 0; }
int msdp_list(lua_State *L) { if (msdp_isoff()) return msdpOffError(L, "msdp.list"); if (luaT_check(L, 1, LUA_TSTRING)) { getMsdp()->send_varval("LIST", lua_tostring(L, 1)); return 0; } return pluginInvArgs(L, L"msdp.list"); }
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; }
int menucmd(lua_State *L) { if (!luaT_check(L, 1, LUA_TNUMBER)) return 0; int menuid = lua_tointeger(L, 1); lua_pop(L, 1); if (menuid == 1) { HWND parent = base::getParent(L); SaveSoundDlg dlg(player); dlg.DoModal(parent); } return 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; }
//------------------------------------------------------------------------------ int netserver_open(lua_State *L) { if (!luaT_check(L, 2, LUA_TNUMBER, LUA_TTABLE)) return luaT_error(L, "netserver: listen [incorrect parameters]"); if (!_network.init()) return luaT_error(L, "netserver: listen [network not initialized]"); int port = lua_tointeger(L, 1); if (port < 0 || port > 65535) return luaT_errorf(L, "netserver: listen [incorrect (%d) port number]", port); for (int i=0,e=listen_sockets.size(); i<e; ++i) { ListenSocket *s = listen_sockets[i]; if (s->port == port) return luaT_errorf(L, "netserver: listen [port (%d) busy]", port); } ListenSocket *new_socket = NULL; Socket s; if (s.create()) { if (s.setreuseopt() && s.bind(port) && s.setnonblockopt() && s.listen(10)) { new_socket = new (std::nothrow) ListenSocket(); if (new_socket) { new_socket->socket = s; new_socket->port = port; listen_sockets.push_back(new_socket); selector.AddSocket(s); } } if (!new_socket) s.close(); } if (!new_socket) return luaT_errorf(L, "netserver: listen [port (%d) does't opened]", port); lua_pushboolean(L, 1); return 1; }
int luaimage_cut(lua_State *L) { if (luaT_check(L, 2, LUAT_IMAGE, LUA_TTABLE)) { ParametersReader pr(L); RECT rc; if (pr.getrect(&rc)) { Image *img = (Image *)luaT_toobject(L, 1); Image *new_img = new Image(); if (new_img->cut(*img, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top)) { luaT_pushobject(L, new_img, LUAT_IMAGE); return 1; } delete new_img; lua_pushnil(L); return 1; } } return pluginInvArgs(L, L"image:cut"); }
int netserver_close(lua_State *L) { if (!luaT_check(L, 1, LUA_TNUMBER)) return luaT_error(L, "netserver: close [incorrect parameter]"); int index = -1; int port = lua_tointeger(L, -1); for (int i=0,e=listen_sockets.size(); i<e; ++i) { ListenSocket *s = listen_sockets[i]; if (s->port == port && !s->closing) { index = i; break; } } if (index == -1) return luaT_errorf(L, "netserver: close [incorrect (%d) port number]", port); ListenSocket *s = listen_sockets[index]; s->socket.shutdown(HOWTO_RECEIVE); s->closing = true; return 0; }