As you know, with the help of setmetatable you can set a metatable only for tables. And what about other types of data, such as strings? Judging by the documentation of lua - not at all, only through C. Well, what about ffi ? But there is a problem - you can not get Lua_state . And ffi.metatype works only with cdata .

In general: how to set a metatable for something other than tables (without using C except ffi )?

    1 answer 1

     getmetatable"".__call = print local str = "abc" str() debug.setmetatable(nil, {__index = function() end}) local t = nil print(t[1]) 
    • Hm Only with debug? - val