Skip to content

Instantly share code, notes, and snippets.

@xordspar0
Forked from randomguyeatspotato/GameState.lua
Last active April 3, 2018 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xordspar0/92a8618751becec4bc14ea220eb9f250 to your computer and use it in GitHub Desktop.
Save xordspar0/92a8618751becec4bc14ea220eb9f250 to your computer and use it in GitHub Desktop.
Separate __parent from the metatable
local enabledFunctions = require("gamestates/enabledFunctions")
local function emptyFunction() end
local function index(t, key) return t.__parent[key] end
local function indexMeta(t, k) return enabledFunctions[key] and emptyFunction end
local function call(self) return setmetatable({__parent = self}, {__index = index}) end
local GameState = setmetatable({}, {__index = indexMeta, __call = call})
return GameState
@randomguyeatspotato
Copy link

{__index = index} Does this creates a new metatable each time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment