213 posts
Posted 23 February 2016 - 03:59 PM
So as far as I was aware this is all of the regular expression type patterns lua accepts in functions like gmatch and gsub
Patterns in Lua Manualhowever while just randomly browsing through the Lua mail lists I discovered quite a few official/semi-official programs use
%z in gsub… As far as I am aware this shouldn't do anything special should it? or are there some codes that the manual doesn't properly document? Or is this not being used as a pattern in gsub and instead I'm just extremely confused about what it is? Below is one example of it I found in which it is being used to handle bytecode.
string.gsub(foobar,"\20(\1%z%z%z)","\2%1")
Edited on 23 February 2016 - 03:01 PM
3057 posts
Location
United States of America
Posted 23 February 2016 - 04:03 PM
Edited on 23 February 2016 - 03:03 PM
213 posts
Posted 23 February 2016 - 04:07 PM
so basically %z is "\0"?
3057 posts
Location
United States of America
Posted 23 February 2016 - 04:09 PM
That's what I understand, yes.
213 posts
Posted 23 February 2016 - 04:13 PM
Just did a quick test and as far as I can tell that does seem to be the case :D/> thank you very much yami. Still don't understand the point instead of just using \0 but I guess some people just have weird preferences
2217 posts
Location
3232235883
Posted 23 February 2016 - 07:12 PM
Just did a quick test and as far as I can tell that does seem to be the case :D/> thank you very much yami. Still don't understand the point instead of just using \0 but I guess some people just have weird preferences
you
cannot have a \0 in a lua pattern (in vanilla lua atleast)
the reason is performance, Lua is written in C where standard strings are zero terminated, ie you cannot have a "\0" in a string without using your own string type that holds its own length
to make lua patterns faster and easier to implement, the creators of lua decided to use the standard C string functions on patterns instead of their own functions that would handle any \0s in patterns
1426 posts
Location
Does anyone put something serious here?
Posted 23 February 2016 - 09:01 PM
you cannot have a \0 in a lua pattern (in vanilla lua atleast)
the reason is performance, Lua is written in C where standard strings are zero terminated, ie you cannot have a "\0" in a string without using your own string type that holds its own length
to make lua patterns faster and easier to implement, the creators of lua decided to use the standard C string functions on patterns instead of their own functions that would handle any \0s in patterns
Interestingly this limitation
was removed in Lua 5.2. Looks like they manually tracked start and end positions of strings instead.