Is it possible to code a script in an OO (Object Oriented) manner.
If this is possible, how to do it?
Can someone give an example, please :)
sure.. object is really just a table of functions (lua even understands "self")
you can set-up simple inheritance with tag methods >> (http://lua-users.org/lists/lua-l/2002-08/msg00157.html)
check out what they did in stdlua project >> (http://sourceforge.net/projects/lua-users/)
Thanks for the links, tezlo.
Lack of experience from C or C++,
I'm trying to get a grip on this things, but its hard. :)
Btw, "self" is it a function calling itself?
self is pointing too the object of the class, like this in java
thanx for the info ;)
I'm totally "fumble in the dark" here.
Is this nearby a start to an Object Oriented script?
Or am I all lost in the blue? :Dfunction delegate(tab, item)
local base = rawget(tab, "inherits")
if type(base) == "table" then
return base[item]
else
return nil
end
end
settagmethod(tag{}, "index", delegate)
HubObject =
{
UserCount = frmHub:GetUsersCount(),
HubName = frmHub:GetHubName(),
MaxUsers = frmHub:GetMaxUsers(),
MinShare = frmHub:GetMinShare(),
}
function HubObject:Command()
HubInfo(self.UserCount, self.HubName, self.MaxUsers, self.MinShare)
end
OpCommand =
{
inherits = HubObject,
SetMaxUser = frmHub:SetMaxUsers(),
SetMinShare = frmHub:SetMinShare()
}
function OpCommand:Command()
HubInfo(self.UserCount, self.HubName, self.MaxUsers, self.MinShare, self.SetMaxUser, self.SetMinShare)
end
thats a nice thing :))
and I think you are doing it right.
the only thing is inherits, but I haven't check will it build that other table with all values of the other or will it only use the other table. so no new memory is used.
and I can use it :)
now I need a way to serialize it. :(.