GE Lua Documentation

Press F to search!

__index

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

@/lua/common/libs/LuLPeg/lulpeg.lua
    local struct, boolset_constructor = {v={}}
    function byteset_mt.__index(s,i)
        if i == nil or i > s.upper then return nil end
    Builder.proxymt = pattmt
    function pattmt:__index(k)
        return proxycache[self][k]
@/lua/ge/ge_utils.lua
scenetree.__index = function(class_table, memberName)
  --log('E', logTag,'scenetree.__index('..tostring(class_table) .. ', ' .. tostring(memberName)..')')
  --dump(class_table)
@/lua/common/libs/LuaIRC/init.lua
local meta_preconnect = {}
function meta_preconnect.__index(o, k)
    local v = rawget(meta_preconnect, k)