Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I modify locked tables?

I'm trying to add a function to the table string.

function string.bytes(s_str) -- errors
    assert(type("") == type(s_str), "bad argument #1 to 'string.bytes' (string expected, got " .. type(s_str) .. ")")
    return tostring(s:gsub(".", function(c)
        return ("\\" .. c:byte()) or c or ""
    end))
end

How can I unlock string table?

1 answer

✓ Accepted answer

The solution is a one liner. I believe that metatables are the quickest way of doing this. Place this line at the top of script (or above function)

local string = setmetatable({}, {__index = string})

2 comments

1

thx m8!

0

You're very welcome. Also note that you're not limited to using string. You can replace it with table and add functions to table.

This discussion is preserved as it was. New answers, comments, and votes are closed.