Jump to content

Object-oriented LUA


Orange

Recommended Posts

Well, I always wanted to ask this question. Does ANYONE use the object-oriented LUA? Maybe "halfly object-oriented", because there's a lot of work to create a class of every element, and people are too lazy :F I hope that someone does, I don't want to be the only one person in MTA scripting scene, who uses OOP lua :F

Link to comment

Well, I do.

My whole Item-System is OO.

But its a bit chaotic to be OOP only, so I had an Idea called "pl-ObjectOriented" for a test.

Its not EXACTLY what Lua wants to be object oriented, but that had a reason.

function f1() 
    outputChatBox("Funktion 1"); 
end 
  
function f2() 
    outputChatBox("Funktion 2"); 
end 
  
function startup() 
    local sName = "test1"; 
    local aFunctionArray = { FirstFunction = f1 , SecondFunction = f2 }; 
    local aVariableArray = { FirstVariable = "trala" , SecondVariable = "tralala"}; 
    cClass1 = addClass(sName,aFunctionArray,aVariableArray); 
    sName = "test2"; 
    aFunctionArray = { FirstFunction = f2 , SecondFunction = f1 }; 
    aVariableArray = { FirstVariable = "trili" , SecondVariable = "trilili"}; 
    cClass2 = addClass(sName,aFunctionArray,aVariableArray); 
end 
  
function OOtryout() 
    startup(); 
    local oObject1 = createObject("test1"); 
    local oObject2 = createObject("test2"); 
    local oObject3 = createObject("test1"); 
    local oObject4 = createObject("test2"); 
    local oObject5 = createObject("test1"); 
    local oObject6 = createObject("test2"); 
    local oObject7 = createObject("test1"); 
    local oObject8 = createObject("test2"); 
    local oObject9 = createObject("test1"); 
    local oObject0 = createObject("test2"); 
    oObject0.fFirstFunction(); 
    oObject0.fSecondFunction(); 
    oObject1.fFirstFunction(); 
    oObject1.fSecondFunction(); 
    outputChatBox(oObject1.vFirstVariable); 
    outputChatBox(oObject0.vFirstVariable); 
end 
  
addCommandHandler ( "tryout", OOtryout )  
  
  
function OOtryout2() 
    startup(); 
    oObject0 = getObjectNr(0); 
    oObject1 = getObjectNr(1); 
    oObject2 = getObjectNr(2); 
    oObject3 = getObjectNr(3); 
    oObject4 = getObjectNr(4); 
    oObject5 = getObjectNr(5); 
    oObject6 = getObjectNr(6); 
    oObject7 = getObjectNr(7); 
    oObject8 = getObjectNr(; 
    oObject9 = getObjectNr(9); 
     
    if oObject0 then 
        oObject0.fFirstFunction(); 
        oObject0.fSecondFunction(); 
        oObject9.fFirstFunction(); 
        oObject9.fSecondFunction(); 
        outputChatBox(oObject9.vFirstVariable); 
        outputChatBox(oObject0.vFirstVariable); 
        destroyObject(oObject0); 
        destroyObject(oObject1); 
        destroyObject(oObject2); 
        destroyObject(oObject3); 
        destroyObject(oObject4); 
        destroyObject(oObject5); 
        destroyObject(oObject6); 
        destroyObject(oObject7); 
        destroyObject(oObject8); 
        destroyObject(oObject9); 
    end 
    destroyClass("test1"); 
    destroyClass("test2"); 
end 
  
addCommandHandler ( "tryout2", OOtryout2 )  
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...