Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on November 20, 2018, 01:56:10 PM

Title: Small feature request for TYPE
Post by: Brian Alvarez on November 20, 2018, 01:56:10 PM
 This is not a priority but i would like default values for types to be supported, for example:

Code: [Select]
type rgbacolor
  red   as byte = 35
  green as byte
  blue  as byte
  alpha as byte
end type

rgbacolor r

print str(r.red)

I noticed that this already compiles fine, but the value remains 0. I would also
like a way to reset to default empty values and a way to reset to predefined values.
Title: Re: Small feature request for TYPE
Post by: Charles Pegge on November 20, 2018, 04:20:16 PM
Hi Brian,

o2 uses curly braces to assign default values:

Code: [Select]
'DEFAULT MEMBER VALUES
type color
  byte r=0x10
  byte g=0x20
  'g as byte =0x20
  byte b=0x30
  byte a=0x40
end type

color d    'sets all to null
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)

d={} 'sets all to default values
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)

d={g=0x25,b=0x35} 'default values with overrides
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)

Title: Re: Small feature request for TYPE
Post by: Brian Alvarez on November 22, 2018, 12:11:00 PM
Awesome Charles! Thanks!
Title: Re: Small feature request for TYPE
Post by: Brian Alvarez on August 15, 2019, 09:17:07 PM
 Sorry about reviving an old post... but i was playing with dfault values for TYPE and apparently it doesnt work when
there is a previous CHAR member. Even worse... it crashes after not setting the default values:

Code: [Select]
'DEFAULT MEMBER VALUES
type color
  char cls[200]  ' adding this makes it fail and crash.
  byte r=0x10
  byte g=0x20
  'g as byte =0x20
  byte b=0x30
  byte a=0x40
end type

color d    'sets all to null
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)

d={} 'sets all to default values
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)

d={g=0x25,b=0x35} 'default values with overrides
print hex(d.r) ", " hex(d.g) ", " hex(d.b) ", " hex(d.a)
Title: Re: Small feature request for TYPE
Post by: Charles Pegge on August 16, 2019, 08:21:36 PM

Okay, I'm recoding this feature, including multi-assignments. It has become too complex with low level code, so I'll use recursive decomposition, and hope to save about 400 lines of o2 source code in the process :)
Title: Re: Small feature request for TYPE
Post by: Brian Alvarez on August 16, 2019, 08:57:06 PM
Thanks charles, i also noticed it didnt work for CHAR or WCHAR elements... in fact no string types were working.