PtokaX forum

Development Section => Your Developing Problems => Topic started by: VidFamne on 03 February, 2004, 04:45:30

Title: OO-script
Post by: VidFamne on 03 February, 2004, 04:45:30
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 :)
Title:
Post by: tezlo on 03 February, 2004, 05:33:10
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/)
Title:
Post by: VidFamne on 03 February, 2004, 22:50:49
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?
Title:
Post by: [NL]Pur on 03 February, 2004, 23:22:04
self is pointing too the object of the class, like this in java
Title:
Post by: VidFamne on 06 February, 2004, 03:40:43
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
Title:
Post by: c h i l l a on 07 February, 2004, 12:15:41
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. :(.