__luaBindIndex
Definition
-- @/lua/common/luaBinding.lua:6
-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt
-- do not change the name of the functions as they are hardcoded in the c++ part
function __luaBindIndex(t, k)
local mt = getmetatable(t)
-- log('E', '', ' __index invoked on ' .. tostring(mt.___type))
local res = rawget(mt, k)
if res ~= nil then return res end
local origgetters = rawget(mt, 1) -- 1 = getters
local getFunc = rawget(origgetters, k)
if getFunc ~= nil then
-- log('E', '', ' getter hit: ' .. tostring(k) .. ' = ' .. tostring(res))
return getFunc(t)
end
local origmt = mt
while true do
mt = rawget(mt, 3) -- 3 = super
if not mt then
--log('E', '', string.format("property '%s.%s' is not found", origmt.___type, k))
return
end
res = rawget(mt, k)
if res ~= nil then
rawset(origmt, k, res)
return res
end
local getters = rawget(mt, 1) -- 1 = getters
if getters then
local getFunc = rawget(getters, k)
if type(getFunc) == 'function' then
-- log('E', '', ' getter hit: ' .. tostring(k) .. ' = ' .. tostring(res))
rawset(origgetters, k, getFunc)
return getFunc(t)
end
end
end
end
Callers