DGS OOP Class: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(→Start) |
||
Line 16: | Line 16: | ||
==Start== | ==Start== | ||
Instead of using | Instead of using | ||
<syntaxhighlight language="lua"> | |||
label = exports.dgs:dgsCreateLabel(0, 0, 0.5, 0.1, "text", true) | |||
</syntaxhighlight> | |||
<syntaxhighlight language="lua"> | |||
DGS = exports.dgs | |||
label = DGS:dgsCreateLabel(0,0,0.5,0.1,"text",true) | |||
</syntaxhighlight> | |||
<syntaxhighlight language="lua"> | |||
loadstring(exports.dgs:dgsImportFunction())()-- load functions | |||
label = dgsCreateLabel(0,0,0.5,0.1,"text",true) --create a label | |||
</syntaxhighlight> | |||
We provides Object Oriented Programming | |||
<syntaxhighlight language="lua"> | |||
loadstring(exports.dgs:dgsImportOOPClass())()-- load OOP class | |||
window = DGSClass:createWindow(0,0,0.5,0.1,"test",true) --create a window with oop | |||
label = window:createLabel(0,0,1,1,"label",true) --create a label inside the window | |||
label.text = "DGS OOP Test" --set text | |||
</syntaxhighlight> |
Revision as of 07:37, 15 November 2018
DGS provides not only POP ( Procedure Oriented Programming ) but also OOP ( Object Oriented Programming ). This page introduces OOP of dgs.
Structure
When using DGS OOP, DGS objects being operated are no longer elements, instead, they will be tables ( table is the only type whose call methods can be defined in lua ) . Here is the structure of DGS OOP Object:
DGSDxObject = { DGSElement = DGSElement -- The actual dgs element function1, function2, ... }
- The built-in functions are non-modifiable
- Any variable of the table are get/set via dgsSetProperty/dgsGetProperty ( Exclude DGSElement )
Start
Instead of using
label = exports.dgs:dgsCreateLabel(0, 0, 0.5, 0.1, "text", true)
DGS = exports.dgs label = DGS:dgsCreateLabel(0,0,0.5,0.1,"text",true)
loadstring(exports.dgs:dgsImportFunction())()-- load functions label = dgsCreateLabel(0,0,0.5,0.1,"text",true) --create a label
We provides Object Oriented Programming
loadstring(exports.dgs:dgsImportOOPClass())()-- load OOP class window = DGSClass:createWindow(0,0,0.5,0.1,"test",true) --create a window with oop label = window:createLabel(0,0,1,1,"label",true) --create a label inside the window label.text = "DGS OOP Test" --set text