OO-script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

OO-script

Started by VidFamne, 03 February, 2004, 04:45:30

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

VidFamne

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 :)

tezlo

sure.. object is really just a table of functions (lua even understands "self")
you can set-up simple inheritance with tag methods >>

check out what they did in stdlua project >>

VidFamne

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?

[NL]Pur

self is pointing too the object of the class, like this in java

VidFamne

#4
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? :D
function 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

c h i l l a

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. :(.

SMF spam blocked by CleanTalk