PDA

View Full Version : User Defined Types



Charles Pegge
18-03-2009, 00:45
UDTs support dynamic strings :)






'USER DEFINED TYPES


uses "oxygen","file"
dim src as string


src = "

type color32

r as byte
g as byte
b as byte
a as byte
lbl as string

end type

dim c as color32

c.r=16
c.b=16
c.g=16
c.a=32
c.lbl=`Dark: `

print c.lbl hex c.a

terminate
"
o2_basic src

'msgbox 0, o2_view "o2h "+src

if len(o2_error) then
msgbox 0, o2_error : stop
end if

o2_exec

Charles Pegge
18-03-2009, 00:54
The equals sign in a UDT causes the element offset counter to be reset. This allows any number of unions to be defined within a type.






'USER DEFINED TYPES
'UNION

uses "oxygen","file"
dim src as string


src = "

type color32

r as byte
g as byte
b as byte
a as byte
=
rgba as long 'UNION

end type

dim c as color32

c.r=16
c.b=16
c.g=16
c.a=32

print hex c.rgba
print hex c.a

terminate
"
o2_basic src

'msgbox 0, o2_view "o2h "+src

if len(o2_error) then
msgbox 0, o2_error : stop
end if

o2_exec

Charles Pegge
18-03-2009, 01:17
'USER DEFINED TYPES
'DERIVED TYPES

uses "oxygen","file"
dim src as string


src = "

type color32

r as byte
g as byte
b as byte
a as byte
=
rgba as long 'UNION

end type

'-------------
'DERIVED TYPE:
'=============

type colortext

c as color32
txt as string

end type


dim t as colortext

t.c.r=16
t.c.b=16
t.c.g=16
t.c.a=32
t.txt=`Color code `

print t.txt hex t.c.rgba

terminate
"
o2_basic src

'msgbox 0, o2_view "o2h "+src

if len(o2_error) then
msgbox 0, o2_error : stop
end if

o2_exec

Charles Pegge
18-03-2009, 01:28
'USER DEFINED TYPES
'INHERITED

uses "oxygen","file"
dim src as string


src = "

type color32

r as byte
g as byte
b as byte
a as byte
=
rgba as long 'UNION

end type


'------------
'DERIVED TYPE
'============

type colortext
color32,
txt as string
end type


dim t as colortext

t.r=16
t.b=16
t.g=16
t.a=32
t.txt=`Color code `

print t.txt hex t.rgba
print hex t.c.a

terminate
"
o2_basic src

'msgbox 0, o2_view "o2h "+src

if len(o2_error) then
msgbox 0, o2_error : stop
end if

o2_exec