Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- The script automatically places the variables into your script environment with the use of getfenv.
- Just put this at the top of the script, and you're good to go!
- EXPLANATION
- - dumpFunction
- Dumps constants and upvalues of the function, and prints them.
- Parameters: Function
- - dumpTable
- Dumps the contents of the table, giving all of the information about it.
- If the table has metamethods such as __tostring, this would bypass it.
- Parameters: Table
- - tableToString
- Converts a table into a string.
- Example:
- local myTable = {
- [1] = "Hello, World!";
- [2] = "This is my table.";
- [3] = "I made this myself!";
- };
- print(tableToString(myTable));
- expected output:
- [1] = Hello, World! (type: string)
- [2] = This is my table. (type: string)
- [3] = I made this myself! (type: string)
- Parameters: Table
- - findString
- Dumps all functions' constants within the debug registry, and search for a specific string.
- if the second parameter is set to true, it will find all strings that partially match with the string provided (e.g "hello" would find "hello world", and so on).
- Parameters: String, boolean
- - countLen
- Returns the length of a table, even if it is a dictionary.
- Parameters: Table
- - isArray
- Returns a boolean on whether the table passed is an array.
- Parameters: Table
- - forEach
- Loops through the table passed, running the callback function that was passed.
- The callback function has 2 arguments passed to it: the Key and the Value of the current table index.
- Parameters: Table, Callback function
- The script automatically puts all these functions into your environment by using getfenv.
- ]]--
- local globals = {
- [assert] = true;
- [collectgarbage] = true;
- [error] = true;
- [getfenv] = true;
- [getmetatable] = true;
- [ipairs] = true;
- [loadstring] = true;
- [newproxy] = true;
- [next] = true;
- [pairs] = true;
- [pcall] = true;
- [print] = true;
- [rawequal] = true;
- [rawget] = true;
- [rawset] = true;
- [select] = true;
- [setfenv] = true;
- [setmetatable] = true;
- [tonumber] = true;
- [tostring] = true;
- [type] = true;
- [unpack] = true;
- [xpcall] = true;
- [_G] = true;
- [_VERSION] = true;
- [delay] = true;
- [elapsedTime] = true;
- [LoadLibrary] = true;
- [printidentity] = true;
- [require] = true;
- [settings] = true;
- [spawn] = true;
- [stats] = true;
- [tick] = true;
- [time] = true;
- [typeof] = true;
- [UserSettings] = true;
- [_VERSION] = true;
- [wait] = true;
- [warn] = true;
- [Enum] = true;
- [game] = true;
- [shared] = true;
- [workspace] = true;
- [type] = true;
- };
- setmetatable(globals, {
- __index = function(self, key)
- return tostring(key);
- end;
- });
- local function findString(ToFind, Partly)
- for i,v in next, debug.getregistry() do
- if type(v) == "function" and islclosure(v) then
- for g,b in next, debug.getconstants(v) do
- if type(b) == "string" and (Partly and (b:lower():match(ToFind:lower())) or b == ToFind) then
- return v;
- end;
- end;
- end;
- end;
- end;
- local function forEach(Table, Callback)
- for Key, Value in next, Table do
- Callback(Key, Value);
- end;
- end;
- local function countLen(Table)
- local Count = 0;
- forEach(Table, function(Key, Value) Count = Count + 1; end);
- return Count;
- end;
- local function isArray(Table)
- return not (#Table == 0 and (countLen(Table) > 0));
- end;
- local function tableToString(Table)
- if countLen(Table) == 0 then return "{}"; end;
- local Result = "{"
- local isArray = isArray(Table);
- for i,v in next, Table do
- local BackupMT = {};
- if type(v) == "table" then
- local MT = getrawmetatable(v);
- if MT then
- for g,b in next, MT do
- rawset(BackupMT, g, b);
- rawset(MT, g, nil);
- end;
- end;
- end;
- Result = Result .. "\n [" .. tostring(type(i) == "number" and i or ('"' .. i .. '"')) .. "] = " .. globals[v] .. " (type: " .. typeof(v) .. ")";
- if type(v) == "table" then
- local MT = getrawmetatable(v);
- if MT then
- for g,b in next, BackupMT do
- rawset(MT, g, b);
- end;
- end;
- end;
- end;
- Result = Result .. "\n}";
- return Result;
- end;
- -- You can change this to some custom print function
- printconsole = warn
- local isLuaFunction = islclosure;
- if isLuaFunction == nil then
- isLuaFunction = function(Function)
- local worked, Err = pcall(coroutine.wrap, Function);
- return worked;
- end;
- end;
- local function dumpFunction(Function)
- if type(Function) ~= "function" then return; end;
- local Upvalues = debug.getupvalues(Function);
- printconsole("Function found!\nUpvalues: " .. tableToString(Upvalues));
- if isLuaFunction(Function) then
- local Constants = debug.getconstants(Function);
- printconsole("Constants: " .. tableToString(Constants))
- end;
- end;
- local function dumpTable(Table)
- if type(Table) ~= "table" then return; end;
- printconsole("Table found!\nContents: " .. tableToString(Table));
- end;
- --[[
- getfenv(2).dumpFunction = dumpFunction;
- getfenv(2).dumpTable = dumpTable;
- getfenv(2).tableToString = tableToString;
- getfenv(2).findString = findString;
- getfenv(2).countLen = countLen;
- getfenv(2).isArray = isArray;
- getfenv(2).forEach = forEach;
- ]]--
Add Comment
Please, Sign In to add comment