루아에서는 어떻게 테이블을 읽기 전용으로 만듭니 까? (특히 LuaInterface와 C#은 5.1이지만, 아무 것도 바뀌지 않을 것이라고 생각합니다.) __index
과 __newindex
을 사용하는 방법을 알고 있지만 누군가가 실행되는 것을 막지는 못합니다 : math = nil
잠재적으로 추가 스크립트가 발생할 수 있습니다. 잘못 실행됩니다.루아는 테이블을 읽기 전용으로 만듭니다
내 현재의 "보호"기능 :
function protect(table)
return setmetatable({}, { __index = table,
__newindex = function(table, key, value) error("attempted to modify a read only table")
end, __metatable = false }) end
math = protect(math)
math.sqrt = nil // successfully protected
math = nil // this is bad and can happen!
사용중인 루아 버전을 언급하지 않았습니다. 이 경우에는 관련이 있습니다. – Mud
원래 게시물 – user1840819