Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is dump()?

Asked by
LuaQuest 450 Moderation Voter
9 years ago

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.

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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 loadstringed back into a function.

The result is executable bytecode, meaning you can somewhat understand how a function was written just by string.dumping it, though it would require a lot of work.

See here for more information on string.dump

Ad

Answer this question