From e2938bf17edf1601efce6d0bb2fe2fdd4e835c54 Mon Sep 17 00:00:00 2001 From: adrido Date: Fri, 3 Apr 2015 10:32:57 +0200 Subject: [PATCH] improved linebreak. removes now whitespaces before and after a linebreak. --- init.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index e273d66..7f41c65 100644 --- a/init.lua +++ b/init.lua @@ -115,14 +115,10 @@ arrow_signs.savetext = function(pos, formname, fields, sender) minetest.log("action", (sender:get_player_name() or "").." wrote \""..fields.text.. "\" to sign at "..minetest.pos_to_string(pos)); meta:set_string("text", fields.text) - local text = arrow_signs.create_lines(fields.text) + local text,lines = arrow_signs.create_lines(fields.text) meta:set_string("infotext", '"'..text..'"') - local i=0 - for wort in text:gfind("\n") do - i=i+1 - end - if i > 4 then - minetest.chat_send_player(sender:get_player_name(),"\tInformation: \nYou've written more than 5 lines. \n it may be that not all lines are displayed. \n Please remove the last entry") + if lines > 4 then + minetest.chat_send_player(sender:get_player_name(),"\tInformation: \nYou've written more than 5 lines. \n it may be that not all lines are displayed. \n Please remove the last entry") end return true end @@ -130,9 +126,9 @@ end --this function creates the linebreaks arrow_signs.create_lines = function(text) - text = text:gsub("/", "\"\n\"") - text = text:gsub("|", "\"\n\"") - return text + local text, n = text:gsub("[ ]*(%|)[ ]*", '"\n"')--search for | + local text, m = text:gsub("[ ]*(%/)[ ]*", '"\n"')--search for / + return text, n+m end minetest.override_item("default:sign_wall", {