Перейти к содержимому

1kovand1

Пользователи
  • Публикации

    18
  • Зарегистрирован

  • Посещение

Все публикации пользователя 1kovand1

  1. Я на днях решил написать небольшой прототип проги для удаленного доступа, которая слушает события modem_message, и исполняет их содержимое, перенаправляя выход в ту же сетевую карту. У меня получился такой код(Полностью рабочий) local s = require"shell" local e = require"event" local m = require("component").modem m.open(512) env = _G function env.io.stdout:write(...) m.broadcast(512, ...) end while true do args = {e.pull("modem_message")} s.execute(args[6], env) end Потом, недолго думая, я решил вынести это добро в отдельный поток, который создается в дефолтном шелле bin/sh.lua Вот такое дело у меня получилось Мой говнокод с 474 по 497 строку НО! Теперь перенаправляется вывод не только программ, запущенных через удаленный доступ, но так же и программ, запущенных через сам комп P.S Убедительная просьба по поводу отступов тапками не кидаться
  2. Такой всё равно не обрабатывается (заменил на event.pull) local com = require"component" local uc = require"unicode" local e = require"event" local term = require"term" local gpu = com.gpu ---------------- buttons = {} function drawButton(name,x,y, w, h, bg, fg, text, onBClick) buttons.name = {} buttons.name[1] = x buttons.name[2] = y buttons.name[3] = w buttons.name[4] = h buttons.name[5] = onBCLick oldbg = gpu.getBackground() oldfg = gpu.getForeground() gpu.setBackground(bg) gpu.setForeground(fg) gpu.fill(x, y, w, h, " ") gpu.set(math.max(x, w)/2 - math.min(x, w)/2 - uc.len(text)/2,math.max(y,h)/2 - math.min(y, h)/2, text) gpu.setBackground(oldbg) gpu.setForeground(oldfg) end local function onClick(_,_, x, y, ...) for name in buttons do print(x.." "..name[1].." "..name[3].." ".. y.." "..name[2].." ".. name[4]) if x >= name[1] and x <= name[3] and y >= name[2] and y <= name[4] then name[5]() end end end local function lol() require"computer".shutdown(false) end e.listen("touch", onClick) local w, h = gpu.getResolution() drawButton("lol", 1, 1, w/2, h/2, 0x00FF00, 0x000000, "lol", lol) while true do e.pull() end
  3. Я пишу прогу, которая рисует кнопку, а потом обрабатывает на неё нажатие. Рисовать, то она рисует правильно, но почему-то функция onClick, которая вызывается по ивенту touch не запускается. Вот код: local com = require"component" local uc = require"unicode" local e = require"event" local term = require"term" local gpu = com.gpu ---------------- buttons = {} function drawButton(name,x,y, w, h, bg, fg, text, onBClick) buttons.name = {} buttons.name[1] = x buttons.name[2] = y buttons.name[3] = w buttons.name[4] = h buttons.name[5] = onBCLick oldbg = gpu.getBackground() oldfg = gpu.getForeground() gpu.setBackground(bg) gpu.setForeground(fg) gpu.fill(x, y, w, h, " ") gpu.set(x,math.max(y,h)/2 - math.min(y, h)/2, text) gpu.setBackground(oldbg) gpu.setForeground(oldfg) end local function onClick(_,_, x, y, ...) for name in buttons do print(x.." "..name[1].." "..name[3].." ".. y.." "..name[2].." ".. name[4]) if x >= name[1] and x <= name[3] and y >= name[2] and y <= name[4] then name[5]() end end end local function lol() require"computer".shutdown(false) end e.listen("touch", onClick) local w, h = gpu.getResolution() drawButton("lol", 1, 1, w/2, h/2, 0x00FF00, 0x000000, "lol", lol) while true do io.read() end
  4. А если какой-нибудь аргумент будет nil
  5. Раз уж на то пошло, что такое ipairs
  6. event = require("event") com = require("component") while true do local f,s,t, fo, fi, si = event.pull(60) event = require("event") com = require("component") while true do local f,s,t, fo, fi, si = event.pull("touch") if si == nil then si = "nil" end if fi == nil then fi = "nil" end if fo == nil then fo = "nil" end if t == nil then t = "nil" end if s == nil then s = "nil" end if f == nil then f = "nil" end if f ~= "nil" then print(f.."\n"..s.."\n"..t.."\n"..fo.."\n"..fi.."\n"..si.."\n") end end si = "nil" end if fi == nil then fi = "nil" end if fo == nil then fo = "nil" end if t == nil then t = "nil" end if s == nil then s = "nil" end if f == nil then f = "nil" end if f ~= "nil" then print(f.."\n"..s.."\n"..t.."\n"..fo.."\n"..fi.."\n"..si.."\n") end end
  7. Почему не работает фильтрация , например event.pull("chat_message") все равно пропускает все эвенты.
  8. А то в официальной документации ничего не понятно
  9. Просто надо для системки безопасности дома
  10. Спасибо большое! Я знал про функцию shouldInterrupt(), Просто не зналл куда именно ее писать
  11. И еще вопросик, можно ли из значения переменной взять первые несколько символов, а остальные отбросить, например: input = "ABCDEFGH" через некий код превращается в output = "ABC"
  12. Значит мне надо чтобы если в переменной обнаружен(ы) пробел(ы), то она разбивалась на две и более частей (в зависимости от кол-ва пробелов) Например есть переменная input = "abc def ghi", она через некий код должна превратиться в переменные output1 = "abc" output2 = "def" output3 = "ghi" P.S нужно для программки на OpenComputers
×
×
  • Создать...