Module:Explode: Difference between revisions
From StrategyWiki, the video game walkthrough and strategy guide wiki
removed broken/unused functions
Notmyhandle (talk | contribs) (added local p) |
Notmyhandle (talk | contribs) (removed broken/unused functions) |
||
(26 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
]]-- | ]]-- | ||
local p = {} | local p = {} | ||
function explode( | |||
if ( | function p.explode(frame) | ||
local | --[[ | ||
-- | By Notmyhandle, working August 9th, 2014, compatibility is Lua 5.1 or 5.2, not sure | ||
args: | |||
1:string | |||
2:delimiter character (divider character) | |||
]]-- | |||
--If no string is present, don't waste any more time. | |||
if (frame.args[1]=='') then return false end | |||
local finalstring,rindex,s,e = 0 | |||
local rindexdebug,rindexnegativedebug,capturedstring,capturedstringdebug = "string" | |||
--capture the starting index | |||
s = string.find(frame.args[1],frame.args[2]) | |||
if (frame.args[3]=='left') then | |||
--capture the index of the left side of the first delimiter character | |||
rindex = (s-1) | |||
capturedstring = string.sub(frame.args[1], 1, rindex) | |||
if (frame.args[4]=='debug') then | |||
rindexdebug = string.format("%s %d %s", "rindex = ", rindex, "<br>") | |||
rindexnegative = rindex * -1 | |||
rindexnegativedebug = string.format("%s %d %s", "rindexnegative = ", rindexnegative, "<br>") | |||
capturedstringdebug = string.format("%s %s", "capturedstring = ", capturedstring) | |||
finalstring = string.format("%s %s %s", rindexdebug, rindexnegativedebug, capturedstringdebug) | |||
else | |||
finalstring = capturedstring | |||
end | |||
else | |||
--capture the index of the right side of the first delimiter character | |||
rindex = (s+1) | |||
finalstring = string.sub(frame.args[1], rindex) | |||
end | end | ||
return | return finalstring | ||
end | |||
function p.find(frame) | |||
--[[ | |||
args: | |||
1:string | |||
2:delimiter character (divider character) | |||
3:starting position (far left if not set) | |||
4:set to 'true' if you want plain matching enabled. | |||
See http://lua-users.org/wiki/StringLibraryTutorial | |||
]]-- | |||
return string.find(frame.args[1],frame.args[2],frame.args[3],frame.args[4]) | |||
end | end | ||
return p | return p |