Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
--Загрузка библиотек local term = require("term") local gpu = require("component").gpu local component = require("component") local event = require("event") --Локальные функции всех классов local function copyTable(orig) --Копирование таблиц local orig_type = type(orig) local copy if orig_type == 'table' then copy = { } for orig_key, orig_value in next, orig, nil do copy[copyTable(orig_key)] = copyTable(orig_value) end setmetatable(copy, copyTable(getmetatable(orig))) else copy = orig end return copy end local function isConnect(address, kind) --Проверка подключения по адресу local result = false for value in component.list(kind) do if address == value then result = true break end end return result end local function findComp(kind) --Находит любой компонент по типу local result = false for value in component.list(kind) do result = value break end return result end local function toLines(str, w) --Переносит текст на следующую строку, если не хватает места local lines = { } for i=1, math.ceil(#str/w) do lines[i] = string.sub(str, (i-1)*w+1, i*w) end return lines end local function rusType(var) --Руссифицированная функция type var = type(var) if var == "number" then return "число" elseif var == "table" then return "таблица" elseif var == "function" then return "функция" elseif var == "string" then return "строка" elseif var == "boolean" then return "логическое значение" elseif var == "nil" then return "ничего" else return var end end local function button_error(list) --Детектирует ошибки в кнопке if type(list) ~= "table" then error("Задан неверный параметр.") end list.Draw = nil list.Set = nil list.Detect = nil list.Screen = list.Screen or gpu.getScreen() list.Text = tostring(list.Text or "") list.TextColor = list.TextColor or 0xE6E6FA list.BackgroundColor = list.BackgroundColor or 0x085eff list.ActiveColor = list.ActiveColor or 0x13c000 list.InactiveColor = list.InactiveColor or 0x696969 list.Time = list.Time or 0.3 list.Style = list.Style or "round" if list.Visible == nil then list.Visible = true end --Ошибки if type(list.Screen) ~= "string" then error("Адрес монитора должен быть строкой!", 2) end if not isConnect(list.Screen, "screen") then error("Не найдено \"screen\" по адресу: \""..list.Screen.."\".", 2) end if type(list.xPos) ~= "number" then local var = rusType(list.xPos) list.xPos = tonumber(list.xPos) if not list.xPos then error("Параметр xPos должен быть числом, получено "..var..".", 2) end end if type(list.yPos) ~= "number" then local var = rusType(list.yPos) list.yPos = tonumber(list.yPos) if not list.yPos then error("Параметр yPos должен быть числом, получено "..var..".", 2) end end if type(list.Width) ~= "number" then local var = rusType(list.Width) list.Width = tonumber(list.Width) if not list.Width then error("Параметр Width должен быть числом, получено "..var..".", 2) end end if type(list.Height) ~= "number" then local var = rusType(list.Height) list.Height = tonumber(list.Height) if not list.Height then error("Параметр Height должен быть числом, получено "..var..".", 2) end end if type(list.TextColor) ~= "number" then local var = rusType(list.TextColor) list.TextColor = tonumber(list.TextColor) if not list.TextColor then error("Цвет текста должен быть числом, получено "..var..".", 2) end end if type(list.BackgroundColor) ~= "number" then local var = rusType(list.BackgroundColor) list.BackgroundColor = tonumber(list.BackgroundColor) if not list.BackgroundColor then error("Цвет кнопки должен быть числом, получено "..var..".", 2) end end if type(list.ActiveColor) ~= "number" then local var = rusType(list.ActiveColor) list.ActiveColor = tonumber(list.ActiveColor) if not list.ActiveColor then error("Цвет активной кнопки должен быть числом, получено "..var..".", 2) end end if type(list.InactiveColor) ~= "number" then local var = rusType(list.InactiveColor) list.InactiveColor = tonumber(InactiveColor) if not list.InactiveColor then error("Цвет неактивной кнопки должен быть числом, получено "..var..".", 2) end end if type(list.Visible) ~= "boolean" then error("Параметр видимости должен быть логическим значением, получено "..rusType(list.Visible)..".", 2) end if type(list.Time) ~= "number" then local var = rusType(list.Time) list.Time = tonumber(list.Time) if not list.Time then error("Время нажатия должно быть числом, получено "..var..".", 2) end end if list.Style ~= "round" and list.Style ~= "square" then error("Стиль кнопки может быть \"round\" или \"square\", получено \""..list.Style.."\".", 2) end end local function object_set(object, list) --Меняет свойства любого объекта for key, value in pairs(list) do object[key] = value end if object.Object == "button" then button_error(object) end if object.Visible then object.Draw() end end local function object_detect(object, list) --Детектирует взаимодействия со всем if list.Action ~= "touch" and list.Action ~= "drag" and list.Action ~= "drop" and list.Action ~= "scroll" then error("Получено незарегистрированное действие, \""..list.Action.."\".", 2) end list.Button = list.Button or 2 if not list.x then _, list.Screen, list.x, list.y, list.CurrentButton = event.pull(list.Action) end list.Screen = list.Screen or object.Screen if list.x >= object.xPos and list.x <= object.xPos+object.Width-1 and list.y >= object.yPos and list.y <= object.yPos+object.Height-1 and (list.Button == list.CurrentButton or list.Button == 2) and list.Screen == object.Screen then return true, list.CurrentButton else return false end end --[[ Классы ]] local Object = {} Object.New = { } --Таблица с классами do --Класс кнопки local function button_draw(object, state) --Рисует кнопку local screen = gpu.getScreen() local RES1, RES2 = gpu.getResolution() local BG = gpu.getBackground() local FG = gpu.getForeground() if object.Screen ~= screen then gpu.bind(object.Screen) end local backColor if state == "active" then backColor = object.ActiveColor elseif state == "inactive" then backColor = object.InactiveColor else backColor = object.BackgroundColor end gpu.setBackground(backColor) gpu.fill(object.xPos, object.yPos, object.Width, object.Height, " ") if object.Style == "round" then gpu.setBackground(BG) gpu.setForeground(backColor) gpu.set(object.xPos, object.yPos, "▄") gpu.set(object.xPos+object.Width-1, object.yPos, "▄") gpu.set(object.xPos, object.yPos+object.Height-1, "▀") gpu.set(object.xPos+object.Width-1, object.yPos+object.Height-1, "▀") end do gpu.setBackground(backColor) gpu.setForeground(object.TextColor) local text = toLines(object.Text, object.Width) for i=1, #text do gpu.set(math.floor(object.Width/2+object.xPos-#text[i]/2), math.ceil(object.yPos+object.Height/2-#text/2+(i-1)), text[i]) end end if object.Screen ~= screen then gpu.setResolution(RES1, RES2) gpu.bind(screen) end gpu.setForeground(FG) gpu.setBackground(BG) end local function button_detect(object, list) --Детектирование действий с кнопкой local bool, n = object_detect(object, list) if object.Visible and bool then object.Draw("active") os.sleep(object.Time) object.Draw() end print(bool, n) return bool, n end function Object.New.Button(list) --Класс кнопки local object = copyTable(list) button_error(object) object.Object = "button" list = nil local Me = { ["Draw"] = function(state) --Рисует кнопку button_draw(object, state) end; ["Set"] = function(list) --Меняет значения кнопки object_set(object, list) end; ["Detect"] = function(list) --Детектирует взаимодействия с кнопкой local bool, n = button_detect(object, list) return bool, n end; } setmetatable(Me, {__index = object}) setmetatable(object, {__index = Me}) --Cоздание объекта if object.Visible then Me.Draw() end return Me end end return Object
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
15 hours ago | 2.28 KB
GSA NS
19 hours ago | 1.37 KB
WaterFul.m
MatLab | 21 hours ago | 0.42 KB
WaterEmpty.m
MatLab | 21 hours ago | 0.54 KB
Spinning.m
MatLab | 21 hours ago | 0.53 KB
Drying.m
MatLab | 21 hours ago | 0.48 KB
DoorCls.m
MatLab | 21 hours ago | 0.55 KB
Washing.m
MatLab | 21 hours ago | 0.45 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!