Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blog/oop-in-lua #4

Open
utterances-bot opened this issue Mar 29, 2022 · 1 comment
Open

blog/oop-in-lua #4

utterances-bot opened this issue Mar 29, 2022 · 1 comment

Comments

@utterances-bot
Copy link

wiki: blog/oop-in-lua

https://fideo.info/wiki.lua/blog/oop-in-lua

Copy link
Owner

fcr-- commented Mar 29, 2022

Correction, the pseudocode for index resolution is closer to:

  function gettable_event(t, k)
    local value = rawget(t, k)
    if value ~= nil then
      return value
    end

    local mt = getmetatable(t)
    if mt == nil then return nil end
    local index == mt.__index

    if type(index) == 'function' then
      return index(t, k)
    elseif type(index) == 'table' then
      return index[k]  -- note that this is a recursion!
    end
    return nil
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants