Hey.
So I’ve been somewhat experimenting with the lua language recently and I came across a discovery/issue i’ve wanted to find the answer to if this is right
local object = {} local storedFunct = {} local function removeFunctions(table) table.save = nil table.add = nil end local function addFunctions(table) table.save = storedFunct.save table.add = storedFunct.add end function object:save() removeFunctions(self) --- call a function that saves the self without functions addFunctions(self) end function object:add() removeFunctions(self) -- do something addFunctions(self) end storedFunct.save = object.save storedFunct.add = object.add return object
local myobject = require(“test”)
So say I called myobject:save()
That would remove the colon( : ) and dot( . ) functions from myobject self
Save to the file (do whatever) without the functions the myobject, then reattach the functions
I am still able to use myobject:save() using self even though I’ve reattached the save function using dot( . )
Basically I want to know why this works, and if there would be a cleaner/simpler way (without using metatables)
thanks so much.
brian