I'm running this function a lot which shortens the name of a string:
function shorten(st) return string.sub(st,6) end function test(input) local h = shorten(input) print(""..h) end test("helloworld") I want to write it with a colon like the other functions in this context, which all go like world():context():manager(), not manager(context(world())). I read that using the syntax with the colon passes the first as an argument into the latter, but this does not work:
function shorten(st) return string.sub(st,6) end function test(input) local h = input:shorten() print(""..h) end test("helloworld") Is there a way to do this?
:shorten()can be used on every string in your program that's probably fine. just add it to the string library as shown in the answer below. I personally would simply use:sub(6)so I don't have to think about what:shorten()actually does. but if shortenning to 6 characters is what you always do, go ahead.