Set of TYPE related functionalities
issueid=279 12-05-2011 09:55
Super Moderator
Number of reported issues by Petr Schreiber: 126
Set of TYPE related functionalities
Adding more functions getting run time info on TYPEs could allow new code stunts

Hi,

I think it could be nice to take more advantage of fact ThinBASIC is interpreted, and bring in some special functionalities regarding TYPEs. I am sure it won't be that easy to implement, but would be definitely something useful to have.

typeHandle = TYPE_FromString( sTypeName )
Example of use (classic variable declaration - built in and UDTs)
sType = IIF$(%DEBUG = 1, "tEntityDataDebug", "tEntityDataDefault")

DIM data AS TYPE_FromString( sType )

DIM index AS TYPE_FromString( "LONG" )
typeHandle = TYPE_FromVariable( variable )
Example of use:
hCarData = TYPE_FromString("tCarData")

DIM data AS tCarData

IF TYPE_FromVariable(data) = hCarData THEN
  ...
END IF
sType = TYPE_ToString( typeHandle )
Example of use:
DIM data AS tCarData

MSGBOX 0, TYPE_ToString(TYPE_FromVariable(data)) ' -- Shows "tCarData"
TYPE_GetMemberInfo( variable, resultArray )
resultArray would be of type TYPE_MemberInfo:
 TYPE TYPE_MemberInfo
  isStatic  AS LONG   ' true/false
  name      AS STRING ' name of member
  type      AS DWORD  ' value which can be converted using TYPE_ToString to human readable
END TYPE
Example of use#1 (UDT):
TYPE tCar
  topSpeed   AS LONG
  length     AS SINGLE
  width      AS SINGLE
  height     AS SINGLE
  isHybrid   AS BYTE
END TYPE

DIM car AS tCar
DIM mInfo() AS TYPE_MemberInfo

TYPE_GetMemberInfo(car, mInfo)
' -- mInfo is dimensioned to as many elements, as UDT has members.
' -- it contains:
mInfo(1).isStatic = false
mInfo(1).name = "TOPSPEED"
mInfo(1).type = some odd value -> TYPE_ToString(mInfo(1).type) = "LONG"
' -- and so on
Example of use#1 (normal type):
DIM carSpeed AS LONG
DIM mInfo() AS TYPE_MemberInfo

TYPE_GetMemberInfo(car, mInfo)
' -- mInfo is dimensioned to single element
' -- it contains:
mInfo(1).isStatic = false
mInfo(1).name = "value" ' -- always
mInfo(1).type = some odd value -> TYPE_ToString(mInfo(1).type) = "LONG"
' -- and so on
Of course, I leave it open to discussion :)


Petr
Issue Details
Issue Number 279
Issue Type Task
Project thinBasic
Category Core engine (thinCore.dll)
Status Requested
Priority 5 - Medium
Target Version 1.9.1
Completed Version (none)
Milestone (none)
Votes to perform 0
Votes not to perform 0
Assigned Users (none)
Tags (none)




+ Reply