Posted 25 May 2016 - 02:02 PM
Hey guys,
Environments are not my strong point, so I was wondering if I have a table like so:
So when I run: object:say("hey")
It could maybe (AN EXAMPLE) run the init function inside of the object? So say maybe when I run count
it will run object:init() then start count, with it all being internal, so all I have to do is call the function
and it is all done for me?
Thanks in advance,
Danny
Environments are not my strong point, so I was wondering if I have a table like so:
local object = {
say = function( self, text )
print(text)
return true
end;
count = function( self, limit )
for i=1, limit do
print(i)
end
return true
end;
init = function( self )
-- This will do something
end;
}
This is a basic example, but is there a way so every time a function is run in that table, I can run something just before it is called, example:So when I run: object:say("hey")
It could maybe (AN EXAMPLE) run the init function inside of the object? So say maybe when I run count
it will run object:init() then start count, with it all being internal, so all I have to do is call the function
and it is all done for me?
Thanks in advance,
Danny
Edited on 25 May 2016 - 12:03 PM