sorcery  Diff

Differences From Artifact [64ce434f04]:

  • File lib/str.lua — part of check-in [3f6a913e4e] at 2020-09-29 12:40:28 on branch trunk — * remove former hacky registration system, replace with consistent and flexible API; rewrite metal/gem generation to take advantage of this new API; tweaks to init system to enable world-local tweaks to lore and sorcery behavior * initial documentation commit * initial steps towards calendar - add default date format, astrolabe; prepare infra for division/melding/transmutation spells, various tweaks and fixes (user: lexi, size: 2303) [annotate] [blame] [check-ins using]

To Artifact [345c990ba7]:

  • File lib/str.lua — part of check-in [ea6e475e44] at 2020-10-19 09:52:11 on branch trunk — continue dev on celestial mechanics, add melding+division spells (resonance), refine itemclasses, add keypunch and punchcards, add paper pulp, add a shitload of visuals, add convenience scripts for working with the wiki, make the flamebolt spell actually useful instead of just a pretty lightshow, add essences, inferno crystal, and other goodies; iterate on wands, lots of shit i can't remember, various bugfixes (user: lexi, size: 2983) [annotate] [blame] [check-ins using]

    10     10   	['\xf3'] = '\3';
    11     11   }
    12     12   return {
    13     13   	capitalize = function(str)
    14     14   		return string.upper(string.sub(str, 1,1)) .. string.sub(str, 2)
    15     15   	end;
    16     16   
    17         -	explode = function(str,delim)
           17  +	beginswith = function(str,pfx)
           18  +		if #str < #pfx then return false end
           19  +		return string.sub(str,1,#pfx) == pfx
           20  +	end;
           21  +
           22  +	endswith = function(str,sfx)
           23  +		if #str < #sfx then return false end
           24  +		return string.sub(str,#sfx) == sfx
           25  +	end;
           26  +
           27  +	explode = function(str,delim,pat) -- this is messy as fuck but it works so im keeping it
    18     28   		local i = 1
    19     29   		local tbl = {}
           30  +		if pat == nil then pat = false end
    20     31   		repeat
    21     32   			local ss = string.sub(str, i)
    22         -			local d = string.find(ss, delim, 1, true) or string.len(ss)+1
    23         -			tbl[#tbl+1] = string.sub(ss,1,d-1)
    24         -			i = i + d 
           33  +			local d
           34  +			if pat then
           35  +				local matches = {string.match(ss, '()' .. delim .. '()')}
           36  +				if #matches > 0 then
           37  +					local start,stop = matches[1], matches[#matches]
           38  +					d = start
           39  +					i = i + stop - 1
           40  +				end
           41  +			else
           42  +				local dl = string.len(delim)
           43  +				d = string.find(ss, delim, 1, not pat)
           44  +				if d then i = i + d + dl - 1 end
           45  +			end
           46  +			if not d then
           47  +				tbl[#tbl+1] = string.sub(ss,1,string.len(ss))
           48  +				break
           49  +			else
           50  +				tbl[#tbl+1] = string.sub(ss,1,d-1)
           51  +			end
    25     52   		until i > string.len(str)
    26     53   		return tbl
    27     54   	end;
    28     55   
    29     56   	rand = function(min,max)
    30     57   		if not min then min = 16  end
    31     58   		if not max then max = min end