Difference between revisions of "String (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(string.gmatch(string, pattern))
Line 13: Line 13:
 
"abc=def":gmatch("%a.*")  -- Works
 
"abc=def":gmatch("%a.*")  -- Works
 
"abc=def":gmatch("[%a.]*")  -- Hang
 
"abc=def":gmatch("[%a.]*")  -- Hang
"abc=def":gmatch("[^=]*")  -- Hang - Alternative: "([^=]*)=?"
+
"abc=def":gmatch("[^=]*")  -- Hang
 +
"abc=def":gmatch("([^=]*)=?") -- Works (Note: This produces the same result as the above pattern should)
 
"abcdef":gmatch("[^=]*")  -- Works
 
"abcdef":gmatch("[^=]*")  -- Works
 
"abc=def":gmatch("[^=]*=")  -- Works
 
"abc=def":gmatch("[^=]*=")  -- Works

Revision as of 15:44, 19 April 2012

The string API is a default Lua 5.1 API as defined here. Please list any non-working functions below.

Non-Working Functions

string.gmatch(string, pattern)

Using any quantifier other than + will cause it to hang if that quantifier applies to the whole pattern and that pattern does not match the whole string.

Examples:

"abcdef":gmatch("%a*")   -- Works
"abc=def":gmatch("%a*")   -- Hang
"abc=def":gmatch("%a.*")  -- Works
"abc=def":gmatch("[%a.]*")  -- Hang
"abc=def":gmatch("[^=]*")  -- Hang
"abc=def":gmatch("([^=]*)=?") -- Works (Note: This produces the same result as the above pattern should)
"abcdef":gmatch("[^=]*")  -- Works
"abc=def":gmatch("[^=]*=")  -- Works