Generally sandboxes block setmetatable like shown here:
local function memoize(f)
local mt = {}
local t = setmetatable({}, mt)
function mt:__index(k)
local v = f(k)
t[k] = v
return v
end
return t
end
The question is, I want to not use setmetatable. What is it exactly and how would I get around it? Is it simply a global variable that is a copied 'mt' variable in the above case? Is there something specific I should be doing?
Thanks.
Sandboxes written by competent developers don't block the regular
setmetatablefunction. For example, Wikipedia uses the Scribunto extension, which allows anyone to write and run Lua on the site, and it allows unrestricted use ofsetmetatable. (It does, however, blockdebug.setmetatable, along with most of the rest ofdebug.) In general, when a sandbox does blocksetmetatable, it's because its developers either don't understand how userdata works, don't understand thatdebug.setmetatableandsetmetatableare different, and/or don't understand what__metatabledoes. There's no need for you to restrict it.