DGS OOP Class: Difference between revisions
Jump to navigation
Jump to search
(→Start) |
|||
Line 17: | Line 17: | ||
==Get Started== | ==Get Started== | ||
Instead of using | Instead of using | ||
<syntaxhighlight | <syntaxhighlight lang="lua"> | ||
label = exports.dgs:dgsCreateLabel(0, 0, 0.5, 0.1, "text", true) | label = exports.dgs:dgsCreateLabel(0, 0, 0.5, 0.1, "text", true) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight | <syntaxhighlight lang="lua"> | ||
DGS = exports.dgs | DGS = exports.dgs | ||
label = DGS:dgsCreateLabel(0,0,0.5,0.1,"text",true) | label = DGS:dgsCreateLabel(0,0,0.5,0.1,"text",true) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight | <syntaxhighlight lang="lua"> | ||
loadstring(exports.dgs:dgsImportFunction())()-- load functions | loadstring(exports.dgs:dgsImportFunction())()-- load functions | ||
label = dgsCreateLabel(0,0,0.5,0.1,"text",true) --create a label | label = dgsCreateLabel(0,0,0.5,0.1,"text",true) --create a label | ||
Line 30: | Line 30: | ||
We provides Object Oriented Programming | We provides Object Oriented Programming | ||
<syntaxhighlight | <syntaxhighlight lang="lua"> | ||
loadstring(exports.dgs:dgsImportOOPClass())()-- load OOP class | loadstring(exports.dgs:dgsImportOOPClass())()-- load OOP class | ||
window = DGSClass:createWindow(0,0,0.5,0.1,"test",true) --create a window with oop | window = DGSClass:createWindow(0,0,0.5,0.1,"test",true) --create a window with oop |
Revision as of 07:38, 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 )
Get Started
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