PDA

View Full Version : TypeOf and secret Static UDT-members...



ReneMiner
25-09-2016, 08:37
Lets have a look at this code:



Uses "console"

Type tVec2S
x As Single
y As Single
End Type

Type tVec3S Extends tVec2S
z As Single
End Type

Dim a As Long
Dim b As tVec2S
Dim c As tVec3S

PrintL TypeOf(a)
PrintL TypeOf(b)
PrintL TypeOf(c)

WaitKey


It runs without any error, but it does not print anything.
So TypeOf still is a dead keyword without any functionality.

:( :unguee::cray:

Lets think about


Dim a As Long


built-in primitive type information as Byte, Long, String, Variant etc. are stored internally as some numeral that i can retrieve when i abuse
thinBasic_VariableGetInfoEx - but thinCore.dll its not intended to be used from within thinBasic-scripts this way.
And i have to translate the number in retrieved MainType into its String-expression before when i want to

Dim foo Like TypeOf(a)

Should not be so difficult to make the already existing keyword TypeOf functional for primitive types ;)

But what if MainType holds 24? ( = %MainType_UDT )

So i think an UDT could have some built-in secret static udt-subelement that holds the name of the udt, automatic assigned when the type gets defined.


In case of the example above it would work like



Type tVec2S
Secret Static TypeOf As String = "TVEC2S" ' automatic done by thinCore
x As Single
y As Single
End Type

Type tVec3S Extends tVec2S
Secret Static TypeOf As String = "TVEC3S" ' thinCore should have a separate static for each udt-extension ;)
z As Single
End Type

Dim b As tVec2S
Dim c As tVec3S

PrintL TypeOf(b)
PrintL TypeOf(c)

' equals then:

PrintL b.TypeOf
PrintL c.TypeOf


Assume "Secret" something be done by thinCore in background when keyword "Type" encountered...

Currently an issue is that static subelement TypeOf-information of Vec3S overwrites the content of same named static subelement of Vec2S when assigning TypeOf.

Maybe an idea.

primo
26-09-2016, 09:21
It runs without any error, but it does not print anything.
no i get error with PrintL TypeOf(a) in windows xp and in windows 7. not only display nothing. it is may be windows 10 are more forgiving.
but TypeOf$ works, it gives OutPut: Numeric.Long for
Dim a As Long
PrintL TypeOf$(a)

i found it in thinBasic_Keywords.ini, the only other places for TypeOf keyword is in Oxygen.

ReneMiner
26-09-2016, 15:20
Yeah, TypeOf$ works!

But in case example above the output is incorrect for the tVec2S:
seems the extending type tVec3s overwrites the correct information of the extended type tVec2S
Guess Eros already used a secret static udt-element :)

ReneMiner
01-10-2016, 11:09
and i got another problem here. If dimensioning another variable after udt within same function-level it seems the UDTs loose theirs information.



Uses "console"

Type tVec2S
x As Single
y As Single
End Type

Type tVec3S Extends tVec2S
z As Single
End Type

Dim a As Long
Dim b As tVec2S
Dim c As tVec3S

PrintL TypeOf$(a)
PrintL TypeOf$(b)
PrintL TypeOf$(c)

PrintL
PrintL "now dim another variable d:"

Dim d As String

PrintL TypeOf$(a)
PrintL TypeOf$(b)
PrintL TypeOf$(c)
PrintL TypeOf$(d)

WaitKey

ErosOlmi
06-10-2016, 18:11
Thanks for reporting.
I think I've solved all those bugs.

ATTENTION: only for testing purposes, attached a thinCore.dll you can put into your \thinBasic\ directory replacing your current one.
I'm undergoing a lot of changes for next thinBasic version.

ReneMiner
07-10-2016, 05:26
I'll try it after work when the weekend Starts.
Thanks already, got something in mind😂

ReneMiner
08-10-2016, 07:41
First test, seems now TypeOf and TypeOf$ are the same output.

For real-life use i need only type-name but not type of type ("Numeric.", "UDT.")
perhaps you can make TypeOf to return just name and TypeOf$ to give full description? As


Uses "console"

Dim a As Long
Dim b As String

PrintL Get_TypeOf(TypeOf(a)) ' TypeOf only return this
PrintL Get_TypeOf(TypeOf(b))

PrintL TypeOf$(a) ' TypeOf$ as currently
PrintL TypeOf$(b)
WaitKey

Function Get_TypeOf(ByVal sTypeOf As String) As String

Dim sResult() As String
If Split(sTypeOf, ".", sResult) = 2 Then
Function = sResult(2)
Else
' default "variant" if something invalid occurs
' to avoid run-time-error when Dim ... Like [some stored TypeOf]
Function = "Variant"
EndIf

End Function


Could as well introduce a new Keyword as TypeName but currently we have 2 doing the same...

ErosOlmi
10-10-2016, 17:29
I'm thinking ... also to future when I will be able to give type/subtype of an UDT element or sub-elements.


TypeOf$ will return a concatenation of information.
MainTypeOf$ will return the main type: UDT, Numeric, String ...
SubTypeOf$ will return the subtype: Long, Single, Ext, String, ...


Than I think something like NameOf$ ...


Thinking ...
Thinking ...
:)