So i was experimenting with Lua a bit, and found in some arbitrary code this line:
("").dump(print)
I couldn't find anything about it on the roblox wiki or anywhere else. It does however classify as a keyword in my syntax highlighter, so it's gotta do something.
Indexing a string?
Something else i don't get about it, is it's indexing a string value. Which, i didn't know was possible? If strings can be indexed, what are all their keys? Nothing displays the keys you can index a string with, so it's very confusing to me.
Thanks for reading, hope you can help.
Strings can be indexed. You did this all the time when you use methods like :sub
or :gmatch
.
local text = "hello world" print(text:sub(1, 5)) -- helo
a:b(...)
is just sugar for a.b(a, ...)
. Thus the above is the same as
print( text.sub(text, 1, 5) )
In particular, text.sub == string.sub
.
Strings have a metatable, where their __index
is set to string
. That means anything on the string
table is also on any string.
The above is for methods on strings. string.dump
is not a method on a string -- so you should just use string.dump
, not ("").dump
.
string.dump(fun)
takes a function value and produces a string which can be loadstring
ed back into a function.
The result is executable bytecode, meaning you can somewhat understand how a function was written just by string.dump
ing it, though it would require a lot of work.