Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Carn/TextSnippets
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
--[[ easy text joining TODO: remake from step-by-step conversion to text in conversion to text only at the end of operations (string creation isn't cheap for lua) object types, conditions and order pattern string formatting (easier for users) --]] local snippet = {["__index"] = {["text"] = "", ["a"] = 1.5, ["z"] = 1.5}} --[["a" + "z" = is there space or not 0 1 2 3 0 - - - + 1 - - + + 2 - + + + 3 + + + + ]]-- function snippet:dress (var) if not self or type(self) ~= "table" then return end -- todo: обработка ошибки -- в случае если на входе уже объект нужного класса, возвращаем его же if type(var) == "table" and getmetatable(var) == self then return var end var = var or {} if type(var) ~= "table" and (type(var) == "string" or type(var) == "number") then local text = var var = {["text"]=text} elseif type(var) ~= "table" then return end -- обработчик ошибок без входящего параметра status и без создания замыканий сюда бы setmetatable(var,self) return var end function snippet.__eq (pre, aft) return pre.text == aft.value and pre.a == aft.a and pre.z == aft.z end function snippet.__add (pre,aft) pre=snippet:dress(pre) aft=snippet:dress(aft) if pre == empty or pre.text == "" then return aft end if aft == empty or aft.text == "" then return pre end local sill = pre.z + aft.a local output = { ["text"] = pre.text .. ((sill > 2) and " " or "") .. aft.text, ["a"] = pre.a, ["z"] = aft.z } return snippet:dress(output) end function snippet.__tostring (table) if type(table) == "table" then return table.text end end return snippet
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Carn/TextSnippets/doc
(
edit
)