CC lets you getmetatable(''), OC doesn't. Removing all metatable usages (mystr:len(), mystr:sub() etc) would make getmetatable('') "safe".
I just wanna be able to do
getmetatable('').__mod = function(s,t)
if type(t) == "table" then
return s:format(table.unpack(t, 1, t.n))
else
return s:format(t)
end
end
print("%s %s %s" % {"this", "is", "fun"})
I prefer to err on the side of caution here. This could also affect native code, in particular the persistence lib. And I expect there are other cases I can't think of off the top of my head. In particular, there'd have to be special code to persist and restore the base types' metatables because the persistence lib doesn't (and shouldn't) do that automatically.
TL;DR: no.
Side note: looking at CC's bios.lua it might actually be a bug that this is possible, because it overrides getmetatable and checks for the string metatable and errors if it sees it. Except that check if wrong, as far as I can tell.
Eh I hate crippled Lua :/ First collectgarbage, now string metatable :/
There's a good reason the string metatable is disabled, and that's because it's not thread/instance safe. If you change the string metatable in the code on one CC computer, it changes it in the code on all CC computers; and probably OC computers as well (I'm not familiar enough with c to tell you for certain from the source)
I'm pretty sure you can't use the string metatable for instant message passing in CC... (correct me if I'm wrong)
EDIT: Oh, you can... Screw wireless! :D
EDIT2: Wtf is wrong with ppl?! you should be making a new state for each PC! Last I checked (with the Lua mailing list that is) Lua supports a different string metatable per state...
Oh right, LuaJ. So yeah. This would also apply to the OC fallback. For "normal" OC (with the native lib) this particular thing wouldn't be an issue, because each computer gets its own state. LuaJ on the other hand has no concept of a "state". Everything's just a Java value. Therefore all strings share a metatable in LuaJ. If this is still the case in the latest CC you might want to report that as a bug, by the way...
Ew, someone should fix LuaJ... (it _is_ supposed to be a pure Java reimplementation of native Lua after all)
EDIT: Also this: https://sourceforge.net/p/luaj/bugs/42/
Most helpful comment
I'm pretty sure you can't use the string metatable for instant message passing in CC... (correct me if I'm wrong)
EDIT: Oh, you can... Screw wireless! :D
EDIT2: Wtf is wrong with ppl?! you should be making a new state for each PC! Last I checked (with the Lua mailing list that is) Lua supports a different string metatable per state...