mirror of
https://github.com/don-philipe/knorke.git
synced 2025-11-08 14:57:02 +01:00
changed widget lib handling, pyload widget now ready to use
This commit is contained in:
23
helpers.lua
23
helpers.lua
@@ -1,25 +1,10 @@
|
||||
-- some things copied from vicious' helper
|
||||
-- helper functions
|
||||
|
||||
local rawget = rawget
|
||||
local helpers = {}
|
||||
|
||||
-- {{{ Loader for knorke modules
|
||||
function helpers.wrequire(table, key)
|
||||
local module = rawget(table, key)
|
||||
return module or require(table._NAME .. "." .. key)
|
||||
-- substitutes parts from format_string of the form ${var} with the value from sub_table with the key "var"
|
||||
function helpers.sub_format_string(format_string, sub_table)
|
||||
return string.gsub(format_string, "%${(%w+)}", sub_table)
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{ Format a string with args
|
||||
function helpers.format(format, args)
|
||||
for var, val in pairs(args) do
|
||||
format = format:gsub("$" .. (tonumber(var) and var or
|
||||
var:gsub("[-+?*]", function(i) return "%"..i end)),
|
||||
val)
|
||||
end
|
||||
|
||||
return format
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return helpers
|
||||
|
||||
Reference in New Issue
Block a user