diff --git a/README_ru.md b/README_ru.md index ded49d6..ebff3d4 100644 --- a/README_ru.md +++ b/README_ru.md @@ -129,12 +129,13 @@ AIO Launcher включает в себя интерпретатор LuaJ 3.0.1 * `string:split(delimeter)` - разделяет строку с помощью указанного разделителя и возвращает таблицу; * `string:replace(regexp, string)` - заменяет текст, найденный регулярным выражением, на другой текст; * `get_index(table, value)` - возвращает индекс элемента таблицы; +* `get_key(table, value)` - возвращает ключ элемента таблицы; * `round(x, n)` - округляет число; * `md_colors` - таблица цветов Material Design (исходник есть в этом репозитории, [справка](https://materialui.co/colors)); В комплект также входят: -* [Penlight](http://stevedonovan.github.io/Penlight/api/manual/01-introduction.md.html) - набор портированных из Python функций и структур данных; +* url - функции для кодирования/декодирования строки в URL из библиотеки Lua Penlight; * [luaDate](https://github.com/Tieske/date) - функции для работы со временем; * [json.lua](https://github.com/rxi/json.lua) - парзер JSON; * [SLAXDOM](https://github.com/Phrogz/SLAXML) - парзер XML; diff --git a/lib/utils.lua b/lib/utils.lua new file mode 100644 index 0000000..fdafb21 --- /dev/null +++ b/lib/utils.lua @@ -0,0 +1,46 @@ +-- Standard AIO Launcher library + +function string:split(sep) + if sep == nil then + sep = "%s" + end + + local t={} + + for str in string.gmatch(self, "([^"..sep.."]+)") do + table.insert(t, str) + end + + return t +end + +function string:replace(from, to) + return self:gsub(from, to) +end + +function get_index(tab, val) + for index, value in ipairs(tab) do + if value == val then + return index + end + end + + return 0 +end + +function get_key(tab, val) + for index, value in pairs(tab) do + if value == val then + return index + end + end + + return 0 +end + +function round(x, n) + local n = math.pow(10, n or 0) + local x = x * n + if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end + return x / n +end diff --git a/main/wikipedia-widget.lua b/main/wikipedia-widget.lua index 5e15978..500cdb1 100644 --- a/main/wikipedia-widget.lua +++ b/main/wikipedia-widget.lua @@ -6,7 +6,7 @@ -- version = "1.0" json = require "json" -url = require "pl.url" +url = require "url" -- constants local lang = system:get_lang() diff --git a/ru/widgets-on-off.lua b/ru/widgets-on-off.lua index 88134cc..44929ac 100644 --- a/ru/widgets-on-off.lua +++ b/ru/widgets-on-off.lua @@ -6,8 +6,6 @@ -- arguments_help = "Введите список виджетов и кнопок в формате bitcoin:Биткойн timer:Таймер" -- arguments_default = "bitcoin:Битк. timer:Тайм. stopwatch:Секунд. recorder:Дикт. calculator:Кальк." -sx = require 'pl.stringx' - function on_resume() local args = get_args_kv() @@ -46,7 +44,7 @@ function get_args_kv() local args = aio:get_args() for idx = 1, #args, 1 do - local arg = sx.split(args[idx], ":") + local arg = args[idx]:split(":") keys[idx] = arg[1] values[idx] = arg[2] end diff --git a/samples/pl-tests.lua b/samples/pl-tests.lua deleted file mode 100644 index 6f59ed6..0000000 --- a/samples/pl-tests.lua +++ /dev/null @@ -1,7 +0,0 @@ -sx = require 'pl.stringx' - -function on_resume() - local string = "String with spaces" - local s_list = sx.split(string, " ") - ui:show_text(s_list[3]) -end