• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Help with this function (1 Viewer)

sun

Newcomer
Joined
Mar 29, 2022
Messages
1
Reaction score
0
I don't know how does this function work, can anyone help?

s : sub(x, x+y)

how does sub work?
what does s : mean?

Thanks in advance!
 

GavinW

Newcomer
Creator of RiscLua
Joined
Oct 21, 2020
Messages
54
Reaction score
20
Age
83
Location
UK
Website
www.wra1th.plus.com
By definition of the colon operator, s:sub(x,x+y) is s.sub(s,x,x+y), which by definition of the dot operator is s["sub"](s, x,x+y). But if s is a string we have to look up the value of s["sub"] in the __index field of s's metatable. This is the same as the metatable of the table called "string". In other words s:sub(x,x+y) is identical to string.sub(s,x,x+y).
 
  • Like
Reactions: mje
Top