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

How can I modify locked tables?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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})
1
thx m8! LunarCross01 12 — 4y
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. LucarioZombie 291 — 4y
Ad

Answer this question