User:Lil Toady: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:
===TODO:===
===TODO:===
* OOP tostring
* OOP tostring
* OOP vectors
* Handle vectors in CLuaArgument
* Optimize destroyElement
* Optimize destroyElement
* Release packets queue after function call
* Release packets queue after function call
* Enhance files and timers (gc)


===OOP Metatable Structure:===
===OOP Metatable Structure===
 
<syntaxhighlight lang="lua">
-- Exposed to global environment
Element = {
Element = {
     create = createElement,
     create = createElement,
Line 16: Line 18:


Vehicle = {
Vehicle = {
     create = createElement,
     create = createVehicle,
     setColor = setVehicleColor,
     setColor = setVehicleColor,
     ...
     ...
}
}


-- Hidden in lua registry, applied to userdata
ElementMT = {
ElementMT = {
     __index = CLuaClassDefs::Index,
     __index = CLuaClassDefs::Index,
     __newindex = CLuaClassDefs::NewIndex,
     __newindex = CLuaClassDefs::NewIndex,
     __class = Element,
     __class = Element,
    __call = __class.create,
     __set = {
     __set = {
         type = CLuaClassDefs::ReadOnly,
         type = CLuaClassDefs::ReadOnly,
Line 42: Line 46:
     __class = Vehicle,
     __class = Vehicle,
     __parent = ElementMT,
     __parent = ElementMT,
    __call = __class.create,
     __set = {
     __set = {
         damageProof = setVehicleDamageProof
         damageProof = setVehicleDamageProof
Line 51: Line 56:
     },
     },
}
}
</syntaxhighlight>

Latest revision as of 14:48, 6 June 2014

Coder.gif This user is an MTA developer

TODO:

  • OOP tostring
  • Handle vectors in CLuaArgument
  • Optimize destroyElement
  • Release packets queue after function call
  • Enhance files and timers (gc)

OOP Metatable Structure

-- Exposed to global environment
Element = {
    create = createElement,
    setPosition = setElementPosition,
    ...
}

Vehicle = {
    create = createVehicle,
    setColor = setVehicleColor,
    ...
}

-- Hidden in lua registry, applied to userdata
ElementMT = {
    __index = CLuaClassDefs::Index,
    __newindex = CLuaClassDefs::NewIndex,
    __class = Element,
    __call = __class.create,
    __set = {
        type = CLuaClassDefs::ReadOnly,
        health = setElementHealth,
        ...
    },
    __get = {
        type = getElementType,
        health = getElementHealth,
        ...
    },
}

VehicleMT = {
    __index = CLuaClassDefs::Index,
    __newindex = CLuaClassDefs::NewIndex,
    __class = Vehicle,
    __parent = ElementMT,
    __call = __class.create,
    __set = {
        damageProof = setVehicleDamageProof
        ...
    },
    __get = {
        damageProof = isVehicleDamageProof
        ...
    },
}