FANDOM


--<nowiki>
--| Basic utility functions.
--by Pedro Miller Rabinovitch
--$Id: util.lua,v 1.3 2003/10/03 15:53:26 miller Exp $
--http://lua-users.org/wiki/ExpLua
--http://lua-users.org/files/wiki_insecure/users/miller/explua.tar.gz
local util = {}
--% Current system verbosity level (the more the most)
VERB_LEVEL = 2
--% Current system prefix
VERB_NAME = ''
 
--% Emit a log message
--  Sends out (or not) a line of logging information, depending on the current
--  verbosity level.
--@ level (number) Specifies this message's verbosity level
--@ ... (tostringable) Message arguments (must be |tostring|able)
function util.verb( level, ... )
    if level <= VERB_LEVEL then
        return print( os.date()..VERB_NAME, unpack( arg ))
    end
end 
 
--% Assert parameter types are correct
--@ type_name (string) expected type name
--@ ... (any) values to be checked
function util.check_types( type_name, ... )
   for i, v in ipairs( arg ) do
      assert( type(v) == type_name )
   end               
end                     
 
--% Adds an optional punctuation mark to a string, if there's none.
--@ text (string) text to be adjusted
--@ char (string) character (or sequence thereof) to be added. '.' (period)
-- is used by default.
--@ mask (string) mask representing punctuation characters. '[.;!?]' by default.
--: (string) adjusted text
function util.add_punctuation( text, char, mask )
	util.check_types( 'string', text )
	char = char or '.'
	mask = mask or '[.;!?]'
	util.check_types( 'string', text, char )
	if text and string.len( text ) > 1 then
		if not string.find( text, mask..'%s*$') then
			 text = string.gsub( text,
			  '%s*$', char )
		end
	end
 
	return text
end
 
return util

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.