Author Topic: This UDT thing really bugs me...  (Read 5040 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: This UDT thing really bugs me...
« Reply #15 on: January 06, 2021, 07:08:19 pm »
And if you want to do something really strange, DECLARE LIBRARY your own sub and pass an offset value of something to it, so it can process it as a UDT...

Code: QB64: [Select]
  1. DECLARE CUSTOMTYPE LIBRARY 'Use Customtype for self-referencing a sub written inside your program
  2.     SUB SUB_EXAMPLE (BYVAL passed AS _OFFSET) 'this points to SUB EXAMPLE below, but uses an OFFSET to point to its parameter.
  3.     'NOTE:  The sub/function name *MUST* be the same as QB64 translates it as, for us.
  4.     'General rule of thumb is to make the subname ALL CAPS, preceeded by SUB_ or FUNCTION_ as dictated.
  5.     SUB SUB_EXAMPLE2 (BYVAL passed AS _OFFSET)
  6.  
  7. TYPE DataType 'A datatype to use as an example
  8.     x AS STRING * 12
  9.     y AS LONG
  10.     z AS LONG
  11.  
  12. TYPE DataType2 'a second datatype
  13.     byte1 AS _UNSIGNED _BYTE
  14.     byte2 AS _UNSIGNED _BYTE
  15.     byte3 AS _UNSIGNED _BYTE
  16.     byte4 AS _UNSIGNED _BYTE
  17.     byte5 AS _UNSIGNED _BYTE
  18.     byte6 AS _UNSIGNED _BYTE
  19.     byte7 AS _UNSIGNED _BYTE
  20.     byte8 AS _UNSIGNED _BYTE
  21.     byte9 AS _UNSIGNED _BYTE
  22.     byte10 AS _UNSIGNED _BYTE
  23.     byte11 AS _UNSIGNED _BYTE
  24.     byte12 AS _UNSIGNED _BYTE
  25.     byte13 AS _UNSIGNED _BYTE
  26.     byte14 AS _UNSIGNED _BYTE
  27.     byte15 AS _UNSIGNED _BYTE
  28.     byte16 AS _UNSIGNED _BYTE
  29.     byte17 AS _UNSIGNED _BYTE
  30.     byte18 AS _UNSIGNED _BYTE
  31.     byte19 AS _UNSIGNED _BYTE
  32.     byte20 AS _UNSIGNED _BYTE
  33.  
  34. a$ = "Hello World " + MKL$(-1) + MKL$(3)
  35.  
  36.  
  37. SUB_EXAMPLE _OFFSET(a$) 'Call the sub with the offset to a string
  38. SUB_EXAMPLE2 _OFFSET(a$) 'Notice, we passed the same string, but are handling it differently here,
  39. '                             according to the paramters set in the second sub
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. SUB Example (t AS DataType) 'And here, we want to set up the actual sub to work with our example datatype.
  47.     PRINT t.x 'print the values of that memblock
  48.     PRINT t.y
  49.     PRINT t.z
  50.  
  51. SUB Example2 (x AS DataType2)
  52.     COLOR 12
  53.     PRINT x.byte1
  54.     PRINT x.byte2
  55.     PRINT x.byte3
  56.     PRINT x.byte4
  57.     PRINT x.byte5
  58.     PRINT x.byte6
  59.     PRINT x.byte7
  60.     PRINT x.byte8
  61.     PRINT x.byte9
  62.     PRINT x.byte10
  63.     PRINT x.byte11
  64.     PRINT x.byte12
  65.     PRINT x.byte13
  66.     PRINT x.byte14
  67.     PRINT x.byte15
  68.     PRINT x.byte16
  69.     PRINT x.byte17
  70.     PRINT x.byte18
  71.     PRINT x.byte19
  72.     PRINT x.byte20
  73.  

Now of this bit of trickery doesn't have you scratching your head and wondering just what the heck is happening here, then you win the Obfuscated Coder Award for 2021!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: This UDT thing really bugs me...
« Reply #16 on: January 06, 2021, 07:30:54 pm »
The man doesn't wanna write an extra AS UDT, Steve.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: This UDT thing really bugs me...
« Reply #17 on: January 06, 2021, 08:28:34 pm »
:D :D :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: This UDT thing really bugs me...
« Reply #18 on: January 06, 2021, 10:01:54 pm »
The man doesn't wanna write an extra AS UDT, Steve.

And he’s not.  He’s writing one string and using it with the UDT above. 

What Pete needs is UDTS (user defined type symbols).  Then he can

TYPE foo(%@)
    X AS INTEGER
    Y AS INTEGER
END TYPE

a%@.x = 12
b%@.y = 11

And PRESTO!!  a and b are automatically recognized as type foos.  Can you imagine the colorful type symbols we'd see someone, like Pete, inserting into his code?
   
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: This UDT thing really bugs me...
« Reply #19 on: January 06, 2021, 10:03:53 pm »
Still missing the point, big guy.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: This UDT thing really bugs me...
« Reply #20 on: January 06, 2021, 10:06:36 pm »
Still missing the point, big guy.

I gets it.  Pete gets it.  You're just missing out on the satirically snarky humor me and Pete exchange.  ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: This UDT thing really bugs me...
« Reply #21 on: January 06, 2021, 10:06:55 pm »
Sure. My bad, sir. Won't happen again.
« Last Edit: January 06, 2021, 10:08:25 pm by FellippeHeitor »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: This UDT thing really bugs me...
« Reply #22 on: January 06, 2021, 10:54:34 pm »
Sure. My bad, sir. Won't happen again.

Having both Steve and I on the same forum might be a bit much for you and luke, at times, but you have to appreciate our co-existence is a great asset to Bill in his quest to prove the existence of a multiverse. Based on the premise both Steve's ego and my ego cannot exist together on the size of this forum, let alone a single universe, Bill is one step closer to understanding unified field theory. Oops, now I've taken us from UDTs to UFTs. Oh well, if you will excuse me, my foo got quantum entangled in my shawl again, and it's time for my hot cocoa.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: This UDT thing really bugs me...
« Reply #23 on: January 06, 2021, 11:25:58 pm »
...one step closer to understanding unified field theory.

Nothing complicated to understand there.  UFT is just the theory that if you keep all your cows in the same field, you don't have to walk as far to milk them.  Any farmer can explain that one for you!

To break down the humor for Fell, it goes like this:

Pete: "Change QB64 so I don't have to type 6 characters.  I'm lazy!"
Me: "You don't have to!  You can work around that limit by typing half a page of obfuscated code."
Fell: "No, Pete just doesn't want to type 'AS UDT'..."
Me:"OH!  Then we should add extra symbols to type every time you reference a variable!"
Fell:"You're missing the point!"
Me: "No...  You're missing the humor of how I was joking with Pete."
Fell:  *Sulks in the corner and edits a post a half dozen times to say, "Fine.  Whatever."*

See, Pete likes to joke around and ask for unreasonable things, that no one else wants or cares about.  The answer is to give him an equally unreasonable workaround to his problem, or an obnoxiously over-engineered implementation to correct his issue.  Pete's not really looking for any change -- he's just having fun griping about an issue that popped up in his code that he failed to catch and recognize.

It's all just playful banter back and forth, but you have to be the right TYPE to appreciate it. ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: This UDT thing really bugs me...
« Reply #24 on: January 06, 2021, 11:26:55 pm »
Of course, sir. I apologize once again.